The ls
command in Linux is shorthand for “list.” It is used to list the contents of directories. The ls
command provides various options to display files and directories in different formats and orders.
Initial Example
Using ls
without any options lists the files and directories in the current directory:
ls
LS Parameters
Parameter | Description |
---|---|
-a, --all | Show all files, including hidden files starting with . |
-A, --almost-all | Show all files except . and .. |
--author | With -l , display the author of each file |
-b, --escape | Print C-style escapes for non-printable characters |
--block-size=SIZE | Display file sizes scaled by SIZE (e.g., --block-size=M ) |
-B, --ignore-backups | Do not list backup files ending with ~ |
-c | Sort by and display ctime (last status change time) with -lt or -l |
-C | List entries by columns |
--color[=WHEN] | Colorize the output; WHEN can be always , auto , or never |
-d, --directory | List directories themselves, not their contents |
-D, --dired | Generate output for Emacs’ dired mode |
-f | Do not sort, enable -aU , disable -ls --color |
-F, --classify[=WHEN] | Append indicator (one of */=>@| ) to entries based on their type |
--file-type | Same as -F , but do not append * to executable files |
--format=WORD | Specify output format (e.g., across , commas , horizontal , long ) |
--full-time | Display full timestamp using -l with ISO format |
-g | Like -l , but do not list owner |
--group-directories-first | Group directories before files; overrides --sort=none (-U) |
-G, --no-group | In long listing, do not display group names |
-h, --human-readable | With -l and -s , print sizes in human-readable format (e.g., 1K , 234M , 2G ) |
--si | Similar to -h , but use powers of 1000 instead of 1024 |
-H, --dereference-command-line | Follow symbolic links listed on the command line |
--dereference-command-line-symlink-to-dir | Follow each command line symbolic link that points to a directory |
--hide=PATTERN | Do not list implied entries matching the shell PATTERN |
--hyperlink[=WHEN] | Hyperlink file names WHEN; WHEN can be always , auto , or never |
--indicator-style=WORD | Append indicator with style WORD to entry names (none , slash , file-type , classify ) |
-i, --inode | Print the inode number of each file |
-I, --ignore=PATTERN | Do not list implied entries matching the shell PATTERN |
-k, --kibibytes | Use 1024-byte blocks for file system usage; used with -s and per directory totals |
-l | Use a long listing format |
-L, --dereference | When showing file information for a symbolic link, show info for the referenced file |
-m | Fill width with a comma-separated list of entries |
-n, --numeric-uid-gid | Like -l , but list numeric user and group IDs |
-N, --literal | Print entry names without quoting |
-o | Like -l , but do not list group information |
-p, --indicator-style=slash | Append / indicator to directories |
-q, --hide-control-chars | Print ? instead of non-printable characters |
--show-control-chars | Show non-printable characters as-is (default for terminal output) |
-Q, --quote-name | Enclose entry names in double quotes |
--quoting-style=WORD | Use specified quoting style for entry names (e.g., literal , locale , shell , c , escape ) |
-r, --reverse | Reverse the order of the sort |
-R, --recursive | List subdirectories recursively |
-s, --size | Print the allocated size of each file in blocks |
-S | Sort by file size, largest first |
--sort=WORD | Sort by specified WORD instead of name (e.g., none , size , time , version , extension ) |
--time=WORD | Select the timestamp to use (e.g., atime , ctime , mtime , birth ) |
--time-style=TIME_STYLE | Set the time/date format for -l (e.g., full-iso ) |
-t | Sort by modification time, newest first |
-T, --tabsize=COLS | Assume tab stops at each COLS instead of 8 |
-u | With -lt , sort by and show access time; with -l , show access time and sort by name |
-U | Do not sort; list entries in directory order |
-v | Sort numbers naturally within text |
-w, --width=COLS | Set output width to COLS; 0 means no limit |
-x | List entries by lines instead of by columns |
-X | Sort alphabetically by file extension |
-Z, --context | Print security context of each file |
--zero | End each output line with NUL instead of newline |
-1 | List one file per line |
--help | Display help message and exit |
--version | Output version information and exit |
Examples
1. List all files in long-listing format
The -l
option displays files in long-listing format, which includes detailed information such as permissions, number of links, owner, group, size, and modification date.
ls -l
2. List all files in reverse sort order of creation time
The -rt
options combine to sort files by modification time in reverse order (oldest first).
ls -rt
3. List all files in reverse order and in long-listing format
The -lrt
options combine to display files in long-listing format and sort them by modification time in reverse order.
ls -lrt