simple examples of how to

Sunday, November 6, 2011

[Linux] How to delete selected files in all subdirectory

Let's assume you want to delete the files with the name 'deleteme.dat' that reside several parts in the subdirectory.
Then, what you should do is the following

$ find . name deleteme.dat | xargs rm

where xargs changes the standard out as the argument of the command rm.
By default, the argument is placed as the last argument of the command.
In order to change the position of the argument, you can do the following.

$ find . name moveme.dat | xargs -I '{}' mv '{}' /tmp

The above command moves the found moveme.dat to /tmp folder. the -I '{}' means the indicator of the argument and you can place it the position you want.



No comments:

Post a Comment