I can use ls -ld */ to list all the directory entries in the current directory. Tell me the easiest way to list a file just in the current directory? I know I can use find

find . -maxdepth 1 -type f

or stat

stat -c "%F %n" * | grep "regular file" | cut -d' ' -f 3-

but these do not strike me as being overly elegant. Is there a nice short way to list only the regular files (I don't care about devices, pipes, etc.) but not the sub-directories of the current directory? Listing symbols as well would be a plus but not a necessity

Best Answer

ls -p | grep -v /

This command lists all non-hidden files that aren't directories (regular files, links, device files , etc.). To also include hidden files, add the -A option to ls

It assumes that none of the files have newline characters in their names Adding a -q option to ls would transform all non-printable characters including newline to ? , guaranteeing they're on one line and so suitable for feeding to a line-based utility like grep and for printing on a terminal.