//View Tip #189
» Grepping for processes
» Grep for word in directory
» Find occurrences of a string in a large code base without firing
» Get your machines IP adress
Similar Tips
» Find words in garbled text» Grepping for processes
» Grep for word in directory
» Find occurrences of a string in a large code base without firing
» Get your machines IP adress

Latest tips by RSS
Click here to subscribe

Follow Shell-Fu on Twitter
Click here to follow

Follow Shell-Fu on identi.ca
Click here to follow
It's easy to remove (or copy, move etc.) all files that match a given criteria, but harder to move all but ones excluded by a criteria.
To do this we can combine grep's -v option with Unix command substitution:
To do this we can combine grep's -v option with Unix command substitution:
$ ls 1.txt 2.txt 3.txt 4.txt $ rm `ls | grep -v 4\.txt` $ ls 4.txt
Comments
Add your comment
Comments are currently disabled
$ ls
1.txt 2.txt 3.txt 4.txt
$ shopt -s extglob
$ rm !(4.txt)
$ ls
4.txt