Find And Xargs Command


Table of Contents

cmd:xargs 
Usage 
Help 
Test 
Trying History 
xargs, rm and files with whitespaces, quotes and backslashs 
cmd:find 
Usage 
find files newer than 
find files for size 
find files in multi-dirs 
find with prune 
Try to quote the -exec param: 
find -exec support ` 
Delete 
Deal with file names that have ' in it 
Symptom 
Solution 
get mod 
Find man page for strings, iosteam 
find new 
find new 
find read-only files 
find read-only files 
How to search for a file from is size? 
How to search for a file from is size? 
How to check hard links 
Copy and preserve hard links 
Finding hard links 
Finding hard links 
Finding hard links 
Finding hard links 
safe rm, how? 
safe rm, how? 
Find empty dirs 
Find empty dirs 
Find empty dirs 
Find empty dirs 
Rename file names to lower case, but not dirs 
Rename file names to lower case, but not dirs 
Solution: Rename file names to lower case, but not dirs 
Solution: Rename file names to lower case, but not dirs 
Solution: Rename file names to lower case, but not dirs 
find: missing argument to `-exec' 
find: missing argument to `-exec' 
find: missing argument to `-exec' 
find: missing argument to `-exec' 

cmd:xargs 

reads arguments from the standard input, delimited by blanks (which can be protected with double or single quotes or a backslash) or newlines, and executes the command (default is /bin/echo) one or more times with any initial-arguments fol- lowed by arguments read from standard input. Blank lines on the standard input are ignored.

Usage 

>echo * | xargs echo
asciiart.tar.gz assn.tar.gz bin.tgz doc.tar.gz
>echo * | xargs -n 1 echo
asciiart.tar.gz
assn.tar.gz
bin.tgz
doc.tar.gz

Help 

--replace[=replace-str], -i[replace-str]
       Replace  occurences  of  replace-str  in the initial arguments
       with names read from standard input.  Also, unquoted blanks do
       not  terminate  arguments.   If  replace-str  is  omitted,  it
       defaults to "{}" (like for `find -exec').  Implies -x  and  -l
       1.
--max-lines[=max-lines], -l[max-lines]
       Use  at  most max-lines nonblank input lines per command line;
       max-lines defaults to 1 if omitted.  Trailing blanks cause  an
       input  line  to be logically continued on the next input line.
       Implies -x.
--max-args=max-args, -n max-args
       Use at most max-args arguments per command line.   Fewer  than
       max-args  arguments  will  be  used  if  the  size (see the -s
       option) is exceeded, unless the -x option is given,  in  which
       case xargs will exit.
-t             Enable trace mode.   Each  generated  command
               line  will  be written to standard error just
               prior to invocation.

Test 

$ echo `jot 3` | xargs -n 1 -i echo {} {}
1 2 3 1 2 3
$ jot 3 | xargs -i -n 1 echo {} {}
{} {} 1
{} {} 2
{} {} 3
$ jot 3 | xargs -i echo {} {}
1 1
2 2
3 3

— Use above, 'ls -1 | xargs -i' !!,

$ ls ind* | xargs -i echo mv {} _{}
mv index.html _index.html
mv index001.html _index001.html

— no -1 will also do!!! <<:Thu 06-24-99:>>

*N*: If you have to use echo, use this (Sun 03-14-99) echo * | xargs -n 1 | xargs -i echo {} {}

Trying History 

alias xargsi="tr '\n' '\0' | xargs -0 -i"

— the same as alias xargsi="xargs -i"

alias xargs1="tr '\n' '\0' | xargs -0 -n 1"

— the same as alias xargsi="xargs -l 1"

xargs, rm and files with whitespaces, quotes and backslashs 

$ ls
I mean "no"
a b'c d
$ find . -print0 | xargs -0 -l1 rm
rm: cannot remove `.' or `..'
$ dir
total 0

documented on: 02-20-99