The ls
command in Linux is used to list information about files and directories in the terminal. Here are some common usage examples and options for the ls
command:
- List all files and directories:
ls
- List all files, including hidden ones:
ls -a
- Long format listing (permissions, number of links, owner, group, size, and time of last modification):
ls -l
- Long format listing with file access times:
ls -l --time=access
- Display file sizes in human-readable format (e.g., K, M, G):
ls -lh
- Sort by file extension:
ls -lX
- Sort by modification time, newest first:
ls -lt
- Sort by size, largest first:
ls -lS
- List only directories:
ls -d */
- List files and directories excluding the current and parent directory:
ls -lX --hide='*/.*'
- Recursively list all files and directories in a directory and its subdirectories:
ls -R
- Use color to distinguish file types:
ls --color
- Include inode number in the listing:
ls -i
- Show block usage of files:
ls -s
- List only files with the ‘f’ extension:
ls *.f
- List files and directories and show tilde for hidden files:
ls -lF
- List only directories and show details:
ls -ld */
- List files and directories sorted by version (if version sort is supported by your system):
ls -v
- List files and directories sorted by extension:
ls -X
- List files and directories sorted by modification time, newest first, and show detailed information:
ls -lt
The ls
command is a fundamental part of navigating and managing files and directories in Linux. The options can be combined to provide the desired output for various tasks.