The ls command is used to list all files and directories present in a given directory.
To get manual documentation for any command, use:
man lsThis provides complete information about the ls command.
- Displays all files and directories in alphabetical order.
- Displays all files and directories in reverse alphabetical order.
- Displays content line by line.
- Press
qto exit.
- Displays content page by page (each page contains 20 lines).
- Press
qto exit.
- Displays a long listing of files with details such as permissions, owner, size, and modification date.
- Displays files sorted by last modified date and time (most recent at the top).
- Displays files sorted by last modified date in reverse order (oldest at the top).
- Displays inode numbers for each file.
- Inodes store file attributes such as size, owner, creation date, last modified time, etc.
4) Hidden Files
- Displays all files, including hidden files (
.and..are included).
- Displays almost all files, excluding
.and...
- Displays files with type indicators:
- Directory →
/ - Executable file →
* - Link file →
@
- Directory →
Example Output:
initctl@ # Link File
pts/ # Directory
ls* # Executable File- Disables color formatting in the output.
- Displays all files and directories, including subdirectory contents.
- Displays the number of blocks used by each file (1 block = 1KB in Ubuntu).
- Displays file sizes in human-readable format (e.g., KB, MB, GB).
-
Paginated Display:
ls /dev | less ls /dev | more
-
Show only a fixed number of files:
ls /dev | head -5 # Displays the top 5 files ls /dev | tail -5 # Displays the bottom 5 files
Options can be combined in any order. The following commands are equivalent:
ls -l -t -r
ls -t -r -l
ls -l -r -t
ls -ltr
ls -trlQ1) Command to display all files (including hidden files) in last modification order (oldest first), including inode numbers and block usage, in long listing format?
ls -atrislExample Output:
131279 4 -rw-r--r-- 1 user user 807 Jan 3 12:57 .profile
131277 4 -rw-r--r-- 1 user user 3771 Jan 3 12:57 .bashrc
162011 4 -rw-r--r-- 1 user user 220 Jan 3 12:57 .bash_logout
Q2) Which command lists all files, including hidden files, along with their inode numbers?
ls -aiQ3) Command to make a long listing of all files, including hidden ones, sorted by modification date (oldest first)?
ls -latr- False
ls -rlists files in reverse alphabetical order.- To list files by modification date (oldest first), use:
ls -rt
- True
- The order of options does not matter:
ls -lais equivalent tols -al.