Which language do you prefer? English 简体中文 繁体中文
...

Part of Linux Commands Cheat Sheet

List directory contents.

"ls" stands for "list".


ls
ls /another/directory

# -a for display hidden files
ls -a

Sample output:


. .. a b

Append file types to listing


ls -F

Sample output:


./ ../ a/ b

Notice the appended "/" after file name, it indicates the file is a directory, for all possible types, see the list below:

  • / - directory
  • @ - a symbolic link
  • | - a FIFO
  • = - a socket
  • > - a door
  • nothing - a regular file

List files with separate lines


ls -a1

Sample output:


.
..
a
b

Show a long listing


ls -al

Sample output:


drwxr-xr-x 16 ubuntu ubuntu  4096 Jun 27 00:22 .
drwxr-xr-x  3 root   root    4096 Aug  8  2018 ..
-rw-rw-r--  1 ubuntu ubuntu     2 Jun 29 00:16 a
drwxrwxr-x  4 ubuntu ubuntu 4096 May 29 00:32 b

Each line contains detailed information for a file, for example, -rw-rw-r-- 1 ubuntu ubuntu 2 Jun 29 00:16 a, - indicates the file is a regular file, rw-rw-r-- shows the file's permission, 1 is hard link count, ubuntu shows the file owner, the second ubuntu shows the file owner group, 2 is the file size in bytes, Jun 29 00:16 is the last time this file is modified, and in the last, a is the file name.

For directories, the size will always count as 4096 bytes, no matter what file it contains.

List recursively


ls -R

The command above will list files in current working directory, then list every directories it found recursively.

References

ls Command in Linux for Listing Files

Linux and Unix ls command tutorial with examples | George Ornbo

ls(1) - Linux manual page

wbswjc-blog