Linux ls Command Explained with Options and Examples for Beginners
One of the most frequently used Linux command is ls command. It just means list and it displays the files and the directories within your current folder.
It may seem straightforward, but with the available options, ls can show hidden files, sort results, provide information about files, and so on. Let us now proceed step by step through the most useful options, with real examples.
Basic ls Command
By default, it is displaying the files and folders in your current directory.
Option: -l
What it does: Displays files in long list format.
Why it comes in handy: You can view file permissions, owner, size and last modified date.
Explanation :
-rw-r--r-- → permissions
user user → owner and group
1200 → file size in bytes
Sep 5 → last modified date
report.txt → file name
This is used when you require additional information regarding files.
Option: -a
What it does: Displays all files, even those that are hidden (files that begin with a dot).
Why it is useful: Linux contains a large number of hidden config files, and without this option you will not see them.
Explanation:
. → current directory
.. → parent directory
.bashrc, .profile → hidden files
This should be used when you have to access concealed files.
Option: -h
What it does: Displays file sizes in human readable format (KB, MB, GB).
Why it is useful: File sizes in bytes are often difficult to read; -h simplifies their process.
Instead of 1200, the size of the file is 1.2K (kilobytes).
Quickly know the size of files.
Option: -t
What it does: Orders files by most recently changed time (newest first).
Why it is useful: It assists to locate your most recently modified files.
It is shown here that, since notes.txt was last modified more recently, it appears first.
Use it when you are in a hurry to find your most recent files.
Option: -S
What it does: It organizes files by size, the largest first.
Why it helps: It helps to locate large files easily.
video.mp4 is displayed at the beginning since it is the biggest file.
This should be used when you are searching big files.
Option: -F
What it does: It will add symbols to the end of file names to indicate their type.
Why it is useful: You can immediately find out what is a file, what is a folder, and what is an executable.
Explanation:
/ means a directory
* means an executable
@ means a symbolic link
Combining Options
You can add several options to receive more useful results.
This command shows:
Long listing with details (-l)
Human-readable sizes (-h)
Hidden files included (-a)
This is one of the most widely-used combinations.
Final Notes
The ls command is what you use whenever you want to examine files and directories in Linux. And by having only a few choices, you can transform a plain list into comprehensive, well-structured, and useful information.
Comments
Post a Comment