Part of Linux Commands Cheat Sheet
List directory contents.
"ls" stands for "list".
ls ls /another/directory # -a for display hidden files ls -a
. .. a b
Append file types to listing
./ ../ a/ b
Notice the appended "/" after file name, it indicates the file is a directory, for all possible types, see the list below:
@- a symbolic link
|- a FIFO
=- a socket
>- a door
- nothing - a regular file
List files with separate lines
. .. a b
Show a long listing
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.
The command above will list files in current working directory, then list every directories it found recursively.