3

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)?

marked as duplicate by eyoung100, Isaac, Stephen Kitt, Stéphane Chazelas, jimmij Nov 6 '18 at 9:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

8
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).

7

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.

3

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.

  • 3
    You probably should use -maxdepth 1 to stop the find descending into subdirectories. – roaima Nov 6 '18 at 7:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.