4

I desire to list all inodes in current directory that are regular files (i.e. not directories, links, or special files), with ls -la (ll).

I went to the man ls searching for type and found only this which I didn't quite understand in that regard:

--indicator-style=WORD

append indicator with style WORD to entry names: none (default), slash (-p), file-type (--file-type), classify (-F)

How could I list only regular files with ls -la (ll as my shortcut in Ubuntu 18.04)?

Stephen Kitt
  • 434,908

3 Answers3

9
find . -maxdepth 1 -type f -ls

This would give you the regular files in the current directory in a format similar to what you would get with ls -lisa (but only showing regular files, thanks to -type -f on the command line).

Note that -ls (introduced by BSDs) and -maxdepth (introduced by GNU find) are non-standard (though now common) extensions. POSIXly, you can write it:

find . ! -name . -prune -type f -exec ls -ldi {} +

(which also has the benefit of sorting the file list, though possibly in big independent chunks if there's a large number of files in the current directory).

Kusalananda
  • 333,661
8

ls doesn’t have an option to do this, and you shouldn’t parse its output to filter regular files.

find can be used to find and list regular files instead of ls. Another option is to use Zsh and its glob qualifiers:

ls -l -- *(D.)

lists all regular files, including those whose name starts with a dot.

Stephen Kitt
  • 434,908
2

Well when you use -a is shows everything that is hidden; hidden files and folders. Instead of ls, you'll probably want to use the find command instead. This should help you get started:

find -type f -exec ls -la {} \;

You'll need to change to the directory you want to search first.