I have a directory that has 108k files in it.
I am using the KSH shell on RHEL5
ls *
-dash_bin_ksh: ls: /bin/ls: cannot execute [Argument list too long]
Only command that seems to work is the find command.
find .
file 1
file 2
file n
I tried using find with then exec option to run the file command but I am not getting anywhere.
find . -exec file {}
find: missing argument to `-exec'
What am I missing? I just want to run the file command on every file in this directory and output to a file_output.txt
For find’s exec, you have to end the argument with with
\;You can also try:
xargs works by taking its STDIN and adding each element (line or delimited string) as an argument to the given executable to be executed as few times as possible. The argument list is split by –max-chars (Platform dependent upto 128Kib) into groups for execution.
-print0adds null chars instead of new lines which makes it safe for file names with spaces.-0onxargsis used to recognise null chars.-print0and-0are GNU extensions and can be dropped for non GNU environments at the cost of versatility.xargs also has the
-Ioption which makes it work more likefind -execwhere the executable is run for each element.Thanks to @glennjackman for his in-depth knowledge on this subject.