Web design service - Sams Teach Yourself Shell Programming in 24 Hours
Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 18: Miscellaneous Tools Previous Chapter Next Chapter Sections in this Chapter: The eval Command The expr Command The : Command The bc Command The type Command remsh/rsh/rcmd/remote (Remote Shell) The sleep Command Summary The find Command Questions xargs Terms Previous Section Next Section xargs xargs is a command that accepts a list of words from standard input and provides those words as arguments to a given command: cat filelist | xargs rm You cannot pipe the output of cat directly to rm because rm does not look for filenames on standard input. xargs reads the files being passed by cat and builds up a command line beginning with rm and ending with the filenames. If there are a large number of files, xargs runs the rm command multiple times, deleting some of the files each time. You can specify how many arguments from standard input to build up on the command line with the -n option: cat filelist | xargs -n 20 rm -n 20 says to put only 20 arguments on each command line, so you delete only 20 files at a time. Here is a different example to give you more insight into how xargs works: $ ls acme report16 report3 report34 report527 $ ls | xargs -n 2 echo === === acme report16 === report3 report34 === report527 $ The first ls command shows us that there are only five files in the current directory. (These five can be regular files or directories; it does not matter for this example.) Next you pipe the output of ls to xargs, which composes and executes this command (the first of several): echo === acme report16 The command begins with echo === because these are the arguments given to the xargs command. The command then contains two filenames read from standard input. -n 2 tells xargs to add only two words from standard input to each echo command. I added === as the first echo argument so you can visually find the output from each separate echo command. You can see that xargs called echo three
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.