The most commonly used and fundamental command in the Linux world is <span>ls</span>.
What does ls do?
<span>ls</span> is used to view the files in the current directory.
Open the terminal and simply type:
ls
Press Enter, and you will see all the files and folders in the current directory!
app@linux-c:~$ ls
Desktop Documents Downloads Music Pictures Public snap Templates Videos
Let ls tell you more information
While the basic <span>ls</span> command is useful, sometimes we want to know more details: How large is this file? When was it created? What are its permissions? In this case, we need to use our “enhanced” version of ls:
ls -l
The <span>-l</span> option will display file information in a detailed list format. You will see results like this:
app@linux-c:~$ ls -l
total 36
drwxr-xr-x 2 app app 4096 Jun 20 10:49 Desktop
drwxr-xr-x 2 app app 4096 Jun 20 10:49 Documents
drwxr-xr-x 2 app app 4096 Nov 10 04:38 Downloads
drwxr-xr-x 2 app app 4096 Jun 20 10:49 Music
drwxr-xr-x 2 app app 4096 Jun 20 10:49 Pictures
drwxr-xr-x 2 app app 4096 Jun 20 10:49 Public
drwx------ 5 app app 4096 Nov 10 03:00 snap
drwxr-xr-x 2 app app 4096 Jun 20 10:49 Templates
drwxr-xr-x 2 app app 4096 Jun 20 10:49 Videos
Let me briefly explain the meaning of these mysterious codes:
- The first column (e.g.,
<span>-rwxr-xr-x</span>): File permissions (we will explain file permissions in detail in the next section) - The fifth column (e.g.,
<span>4096</span>): File size (in bytes) - The sixth to eighth columns: Last modification time
- The last column: File name
The leading letters are also interesting:
<span>-</span>represents a regular file<span>d</span>represents a directory<span>l</span>represents a link file
Some Useful Tips
-
View Hidden Files:
ls -aIn Linux, files that start with a dot
<span>.</span>are hidden files.
app@linux-c:~$ ls -al
total 136
drwxr-x--- 17 app app 4096 Nov 17 04:44 .
drwxr-xr-x 3 root root 4096 Jun 20 10:48 ..
-rw------- 1 app app 2755 Nov 13 07:06 .bash_history
-rw-r--r-- 1 app app 220 Mar 31 2024 .bash_logout
-rw-r--r-- 1 app app 3794 Nov 10 04:42 .bashrc
drwx------ 15 app app 4096 Nov 10 04:48 .cache
drwx------ 15 app app 4096 Nov 10 04:39 .config
drwxr-xr-x 2 app app 4096 Jun 20 10:49 Desktop
drwxr-xr-x 2 app app 4096 Jun 20 10:49 Documents
drwxrwxr-x 3 app app 4096 Nov 10 04:48 .dotnet
drwxr-xr-x 2 app app 4096 Nov 10 04:38 Downloads
-rw------- 1 app app 20 Nov 10 09:12 .lesshst
drwx------ 4 app app 4096 Jun 20 10:49 .local
drwxr-xr-x 2 app app 4096 Jun 20 10:49 Music
drwxr-xr-x 2 app app 4096 Jun 20 10:49 Pictures
-rw-r--r-- 1 app app 872 Nov 10 10:33 .profile
-
Human-Readable File Sizes:
ls -lhThis will display file sizes in units like K, M, G.
app@linux-c:~$ ls -lh
total 40K
drwxr-xr-x 2 app app 4.0K Jun 20 10:49 Desktop
drwxr-xr-x 2 app app 4.0K Jun 20 10:49 Documents
drwxr-xr-x 2 app app 4.0K Nov 10 04:38 Downloads
drwxr-xr-x 2 app app 4.0K Jun 20 10:49 Music
drwxr-xr-x 2 app app 4.0K Jun 20 10:49 Pictures
drwxr-xr-x 2 app app 4.0K Jun 20 10:49 Public
drwx------ 5 app app 4.0K Nov 10 03:00 snap
drwxr-xr-x 2 app app 4.0K Jun 20 10:49 Templates
-rw-rw-r-- 1 app app 46 Nov 17 04:47 text.txt
drwxr-xr-x 2 app app 4.0K Jun 20 10:49 Videos
-
Sort by Time:
ls -ltThe most recent files will be listed first.