We are going to learn about Linux command called ls
. It is regular usage command in any distro of Linux to list out the directories and files in the current directory.
- To list out the directories and files in the working directory simply use the command
ls
1) Classification of Files
ls -F
- Here we have to note the indicator patterns at the end of the directories and files to determine the type.
- Regular file: No indicator
- Directory: /
- Executable file: *
- Symbolic link: @
- Unix domain socket: =
- Named pipe (FIFO): |
- Socket: =
2) Long Listing of Files
ls -l
- Displays detailed information about each file, including permissions, number of links, owner, group, size, and time of last modification.
- It's a daily driver command, alias could be
alias ll="ls -l"
3) List the files with human readable
ls -lh
- When used with
-l
, this option shows file sizes in human-readable format (e.g., KB, MB) instead of bytes, mostly for the files present in the current directory.
4) List all Files
ls -a
- List all the files and directories including hidden ones those starting with
.
5) Recursive
ls -R
- Lists all files in the current directory and all sub-directories recursively.
6) Sort by time
ls -lt
- Sorts the files by the time of last modification, with the most recently modified files appearing first.
7) Sort by Size
ls -lS
- Sorts files by size, with the largest files appearing first.
8) One file per line
ls -1
- Lists one file per line. Mostly useful when there are many files in the current Directory.
9) Directories only
ls -d */
- Lists directories themselves, not their contents.
10) Inode Number
ls -li
- Displays the inode number of each file, which is a unique identifier for the file on the filesystem.
11) Sort by Extension
ls -lX
- Sort the files or directories alphabetically.
12) Natural Sort by order
ls -lv
- Sorts files by natural version number order, which is useful when filenames contain numbers
(e.g., file1, file2, file10)
.
13) Group the Directories
ls --group-directories-first
- Lists directories first, then files, rather than mixing them together.
14) Color the output
ls --color=auto
- Forces the output to be colorized or not
(never, always, or auto)
.
15) Time style on long listing
ls -l --time-style=long-iso
- Customizes the format of the time stamps. Common styles include
full-iso
,long-iso
, andiso
.
16) Access Time Sorting
ls -lu
- Sorts files by their last access time instead of modification time.
17) Ignore pattern
ls --ignore-pattern=*.tmp
- Excludes files matching the specified pattern
(e.g., *.tmp)
from the output, very useful if there is lot of files with same extension
Mastering the ls
command enhances your efficiency by customizing directory listings. I hope you found this content helpful and learned something new.
Top comments (0)