For sometime now i have been trying to use the xargs command but it sometimes proves somewhat hard for me to understand but now i think i have got the hang of it. Here is a sample code to demonstrate how easy it really is.
% find . -maxdepth 1 -name ‘filesys*’ -print0 | xargs -0 -Ifil mv fil “thefile”
The various parts of the command are :
- . : Represents the current directory.
- -maxdepth : Tells the find command to which depth should it recursively look for the search term. In this case its 1.
- -name : The name of the search term or item.
- -print0 : Note its “Zero” not O. This prints out the file matching the name. The 0 handles file names that have whitespaces in them. I think its always good to have them on.
- -0 : It also handles white space characters for you.
- -I : Temporarily store the currently matched file in the variable “fil”.
- mv : Rename the file represented by fil to ;
- the file. You can do without the double quotes.
Hope that helped.