...
Code Block |
---|
|
find . -print0 | xargs -0 -I{} echo {} |
Using xarg's -0 does not work with large data sets. Keep in mind that This is because "ls" produces slightly different output from "find .". Here is an example,
Code Block |
---|
|
# Data I am working with
ls
11 My Baby's Got To Pay the Rent 1.m4a 6 Habits (Stay High) [Hippie Sabotage Remix] 1.txt
11 My Baby's Got To Pay the Rent 1.txt Tin's file.txt
11 Summertime Sadness 1.m4a hello
11 The Troubles 1.m4a pwd
12 Canoeing (Katie and Alex's Theme) 1.m4a test123
# Apostrophe kills xargs here
xargs: unterminated quote
# -0 by itself does not solve the problem
ls | xargs -0 -I{} echo {}
{}
# Now it works.
find . -print0 | xargs -0 -I{} echo {}
.
./11 My Baby's Got To Pay the Rent 1.m4a
./11 My Baby's Got To Pay the Rent 1.txt
./11 Summertime Sadness 1.m4a
./11 The Troubles 1.m4a
./12 Canoeing (Katie and Alex's Theme) 1.m4a
./6 Habits (Stay High) [Hippie Sabotage Remix] 1.txt
./hello
./pwd
./test123
./Tin's file.txt
# Remove a file to show -0 works with smaller data set,
rm test123
# -0 by itself now workworks, but making any file names longer or adding back test123 breaks it
ls | xargs -0 -I{} echo {}
{}
Kitchen-iMac:tmp tin.pham$ ls | xargs -0 -I{} echo {}
11 My Baby's Got To Pay the Rent 1.m4a
11 My Baby's Got To Pay the Rent 1.txt
11 Summertime Sadness 1.m4a
11 The Troubles 1.m4a
12 Canoeing (Katie and Alex's Theme) 1.m4a
6 Habits (Stay High) [Hippie Sabotage Remix] 1.txt
Tin's file.txt
hello
pwd
# Show's that find looks different than ls and you want to keep that in mind,
find . -print0 | xargs -0 -I{} echo {}
.
./11 My Baby's Got To Pay the Rent 1.m4a
./11 My Baby's Got To Pay the Rent 1.txt
./11 Summertime Sadness 1.m4a
./11 The Troubles 1.m4a
./12 Canoeing (Katie and Alex's Theme) 1.m4a
./6 Habits (Stay High) [Hippie Sabotage Remix] 1.txt
./hello
./pwd
./Tin's file.txt |
...