When I use the ls
command with the option -l
, the first string of letters gives the info about each file, and the first letter in this string gives the file's type. (d
= directory, -
= standard file, l
= link, etc.)
How can I filter the files according to that first letter?
Best Answer
You can filter out everything but directories using
grep
this way:the
^
indicates that the pattern is at the beginning of the line. Replaced
with-
,l
, etc., as applicable.You can of course use other commands to directly search for specific types (e.g.
find . -maxdepth 1 -type d
) or usels -l | sort
to group similar types together based on this first character, but if you want to filter you should usegrep
to only select the appropriate lines from the output.