13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 8 ■ USING THE COMMAND LINE BETTERfind . -maxdepth 1 -name '*.tex' | xargs echo > list-of-filesMoving FilesYou can use xargs if you need to rename lots of files (such as with datestamping). This command linewill rename each file in the current directory from filename.txt to 20080815-filename.txt:ls | xargs -I {} mv {} 20080815-{}This works because {} is a placeholder meaning “the current argument.” (You can use xxx or yyy orany other string instead of {} if you want, as well, and it’ll do exactly the same thing.) -I implies -n1,because you want to act on each file individually.Or you might want to move all the files in directory 1 into directory 2:ls dir1 | xargs -I {} -t mv dir1/{} dir2/{}It’s an incredibly powerful tool.■ Note You can also use these tricks for other commands. For example, if you have a file containing a list of IPaddresses, then this command would run nmap on each IP address at a time:cat iplist | xargs -n1 nmap -sV183Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!