DEV Community

Cover image for Living in the Shell #5; ls (List Files/Directories)
Babak K. Shandiz
Babak K. Shandiz

Posted on • Originally published at babakks.github.io on

Living in the Shell #5; ls (List Files/Directories)

ls 🚚

Lists directory content.

Long list (detailed format) -l

cd ~ && ls -l
Enter fullscreen mode Exit fullscreen mode
drwxr-xr-x 5 babak babak       4096 Nov  1 12:49 Desktop
drwxr-xr-x 9 babak babak       4096 Nov 21 18:49 Documents
drwxr-xr-x 2 babak babak      20480 Nov 23 17:21 Pictures
...

Show directories first --group-directories-first

cd ~ && ls --group-directories-first
Enter fullscreen mode Exit fullscreen mode

List directory itself, not its content -d

cd ~ && ls -lhd Documents
Enter fullscreen mode Exit fullscreen mode
drwxr-xr-x 9 babak babak 4.0K Nov 21 18:49 Documents

List all files (include dot-files) -a

cd ~ && ls -a
Enter fullscreen mode Exit fullscreen mode

Print human-readable sizes -h

cd ~ && ls -lh
Enter fullscreen mode Exit fullscreen mode
drwxr-xr-x 5 babak babak 4.0K Nov  1 12:49 Desktop
drwxr-xr-x 9 babak babak 4.0K Nov 21 18:49 Documents
drwxr-xr-x 2 babak babak  20K Nov 23 17:21 Pictures
...

Sort by time -t

cd ~ && ls -lht
Enter fullscreen mode Exit fullscreen mode
drwxr-xr-x 2 babak babak  20K Nov 23 17:21 Pictures
drwxr-xr-x 9 babak babak 4.0K Nov 21 18:49 Documents
drwxr-xr-x 5 babak babak 4.0K Nov  1 12:49 Desktop

Sort by size -s

cd ~ && ls -lhs
Enter fullscreen mode Exit fullscreen mode

Reverse sort order -r

cd ~ && ls -lhsr
Enter fullscreen mode Exit fullscreen mode
drwxr-xr-x 2 babak babak  20K Nov 23 17:21 Pictures
drwxr-xr-x 9 babak babak 4.0K Nov 21 18:49 Documents
drwxr-xr-x 5 babak babak 4.0K Nov  1 12:49 Desktop

Top comments (2)

Collapse
 
ayaanraj profile image
ayaanraj

I always use ls -ltr, as it show the last modified one at the bottom

Collapse
 
waylonwalker profile image
Waylon Walker

My favorites are

ls -laht
ls -1