Quantcast
Channel: Removing certain file types that do not contain the hostname in the file name - Ask Ubuntu
Viewing all articles
Browse latest Browse all 2

Answer by Ravexina for Removing certain file types that do not contain the hostname in the file name

$
0
0

Your command does not work as expected because of rm *PC-*-*.json! it would expands by shell and includes all PC-x-x.json files.

Actually you're using xargs in a wrong way.


Something like this should do the job:

ls -Q1 | grep -v $hostname | grep -E "PC-1-[0-9]+\.json" | xargs echo

change echo with rm when you where sure that it works.

A better solution would be using find:

find -type f -name "PC-*-*.json" -not -name "*$hostname*" -exec rm -i {} +
  • remove -i from rm after you were sure that command is working correctly.

Viewing all articles
Browse latest Browse all 2