Can anyone explain why the command below produces the following error:
cannot open `{}' (No such file or directory)
Command
$ ls -al|grep -v '^d\|^$'|awk '{print $10}'|xargs file '{}'
I get the results I expected but with an error
{}: cannot open `{}' (No such file or directory)
cpuinfo: empty
cygdrive: symbolic link to /cygdrive
devices: empty
filesystems: empty
loadavg: empty
meminfo: empty
misc: empty
mounts: symbolic link to self/mounts
partitions: empty
self: symbolic link to 19812
stat: empty
swaps: empty
uptime: empty
version: empty
xargs
to use{}
as thereplace-str
?xargs -I {} ...
. BTW what are you trying to do, exactly? Parsing the output ofls -al
isn't very robust – steeldriver Jul 08 '16 at 14:01{}
construct is unnecessary. If you drop it, your command might work, if the rest of it is sound.find ./ -type f | xargs file
is a better suited command to what I think it is that you are trying to do, in my opinion – MelBurslan Jul 08 '16 at 14:01ls -al
output, unless hisls
command is aliased to something that inserts an additional field – MelBurslan Jul 08 '16 at 14:04ls
when using linux but this is on cygwin (possible reason for difference). basically i would like to pass a list of filenames to file command ie.file filename1 filename2 filename2
– jes516 Jul 08 '16 at 14:37find . -maxdepth 1 -type f -exec file {} +
seems to work for me in Cygwin64 – steeldriver Jul 08 '16 at 14:40ls -al
as the first line from that command istotal 4
when that line with total is being passed to awk, it prints an empty line since there is no field 10. sorry, im still not as fluid with bash/linux as i would like to be and i can overthink things – jes516 Jul 08 '16 at 14:45find
method is much better, starting with the fact that it actually works. BTW,$10
fromls -al
isn't guaranteed to contain even part of the filename, let alone all of it. – cas Jul 09 '16 at 13:32ls
will output the full filename. The tenth field of its output won't necessarily have any or ALL of the filename due to spaces,tabs, control-chars incl. newlines and other annoying but perfectly valid characters. also because the number of fields inls
output can vary depending on the file's timestamp and the version ofls
. Just Don't Parse ls. It's completely unreliable and there are far better, easier, and actually reliable ways. – cas Jul 09 '16 at 15:48