Recursively list the names and attributes of files in a directory ending in an 'e' character, sort the list in ascending order of hard links, do not suppress access errors or redirect. Made such a command "ls -lR | sort -n -k 2 | grep 'e $'" and everything worked, but if the file or directory name contains a newline character and some more characters after the "e" character, the command displays only a piece name and without attributes, since it processes the string and not the name. How to change the command so that extra lines are not displayed? List of files in the directory:
As seen on the second screen, only part of the name is displayed.
1 answer
Many command line utilities support zero (or an arbitrary character) sort as a string delimiter. sort is no exception.
In addition, using ls -R in scripts is a bad practice. Usually, the find utility is used instead.
Alternatively, without sorting:
find -name '*e' -exec ls -l '{}' \+ If sorting by the number of hardlinks is critical, then you can do something wisely:
find -name '*e' -exec stat --printf '%h\t%n\0' '{}' \+ | sort -z -n | cut -z -f 2- | xargs -0 ls -Uld PS: Usually, in their scripts “for themselves” (and why should it be concealed - not only for themselves), few people podkazlavaetsya for the presence of files with the translation of lines - this is very often a chore. And to those strange people, who nevertheless deliberately create such files, the majority treats as lovers to flaunt on the street in a raincoat on a naked body or to those who wind up from cyclical hardlinks.
Disclaimer : The examples were checked in a bent environment, I did not do a check with POSIX for the presence of all the above keys.
