The Joys of xargs - page 3
xargs and find
You can use xargs if you need to rename lots of files (e.g. datestamping). This command will 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 or any 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/{} dir1/{}
Conclusion
I've concentrated here on using xargs to manipulate files in various ways, but you can use the same tricks for other commands. For example, if you have a file containing a list of IP addresses,
cat iplist | xargs -n1 nmap -sVwould run nmap on each IP address at a time. Play around with it a bit and see what you can do!
- Skip Ahead
- 1. xargs and find
- 2. xargs and find
- 3. xargs and find
Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.