0% found this document useful (0 votes)
2 views6 pages

command in linux

ls command linux

Uploaded by

shayea.alantari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

command in linux

ls command linux

Uploaded by

shayea.alantari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

The `ls` command in Linux is used to list the contents of directories.

It has several
options to modify its behavior and display more detailed information about files
and directories. Below is a comprehensive list of `ls` command usage along with
all related options:

Basic Usage:

ls

- *Description:* Lists the files and directories in the current directory.

Commonly Used Options:

1- *`-l`* (Long Listing Format)

ls -l

- *Description:* Displays detailed information about each file, including


permissions, owner, group, size, and modification time.

- *Example Output:*

-rw-r--r-- 1 user user 12345 Dec 12 10:00 file1.txt

drwxr-xr-x 2 user user 4096 Dec 12 10:01 directory1

2- *`-a`* (Show All Files)

ls -a

- *Description:* Lists all files, including hidden files (those starting with a dot `.`).

- *Example:* Shows files like `.bashrc` and `.profile`.

3- *`-A`* (Show All Files Except `.` and `..`)

ls -A

- *Description:* Lists all files, including hidden files, but excludes `.` (current
directory) and `..` (parent directory).

‫ شائع العنتي‬.‫م‬
4- *`-h`* (Human-Readable Sizes)

ls -lh

*Description:* Displays file sizes in a human-readable format (e.g., KB, MB, GB).

- *Example Output:*

-rw-r--r-- 1 user user 12K Dec 12 10:00 file1.txt

5- *`-R`* (Recursive Listing)

ls -R

- *Description:* Lists all files and directories recursively, showing contents of all
subdirectories.

6- *`-d`* (List Directories Only)

ls -d */

- *Description:* Lists only directories, not their contents. Useful when you want
to see directories only without their files.

7- *`-S`* (Sort by File Size)

ls -S

- *Description:* Sorts files by size, with the largest files first.

8- *`-t`* (Sort by Modification Time)

ls -t

- *Description:* Sorts files by modification time, with the most recently


modified files first.

9- *`-X`* (Sort by File Extension)

‫ شائع العنتي‬.‫م‬
ls -X

- *Description:* Sorts files alphabetically by file extension.

10- *`-1`* (One File per Line)

ls -1

- *Description:* Lists one file per line. This is useful when you want a simple,
vertical list of files.

11- *`-F`* (Classify Files)

ls -F

- *Description:* Appends a special character to the end of each file to indicate


its type:

- `/` for directories

- `*` for executable files

- `@` for symbolic links

- `|` for FIFOs (named pipes)

- `=` for sockets.

12- *`-i`* (Display Inode Numbers)

ls -i

- *Description:* Shows the inode number of each file. Inodes are data
structures that store information about a file, excluding its name.

13- *`-l` + `-h`* (Long Listing with Human-Readable Sizes)

ls -lh

- *Description:* Combines long listing format with human-readable file sizes.

‫ شائع العنتي‬.‫م‬
14- *`-v`* (Natural Sorting by Version)

ls -v

- *Description:* Sorts files in "natural" order, useful for sorting files with
numbers (e.g., `file1`, `file2`, `file10`).

15- *`--color`* (Colorize Output)

ls --color

- *Description:* Colorizes the output to distinguish between different file types


(e.g., directories, executables, etc.).

- *Note:* This option is often enabled by default on many Linux distributions.

16- *`-u`* (Sort by Last Access Time)

ls -u

- *Description:* Sorts files by the last access time instead of modification time.

17- *`-U`* (Do Not Sort)

ls -U

- *Description:* Lists files without sorting them (based on the order they appear
in the directory).

18- *`--group-directories-first`*

ls --group-directories-first

- *Description:* Lists directories first, followed by files, regardless of sorting


order.

Combining Options:

You can combine multiple options to customize the output. For example:

‫ شائع العنتي‬.‫م‬
- *`ls -lha`*: Lists all files (including hidden ones) in long format with human-
readable sizes.

- *`ls -lS`*: Lists files in long format, sorted by size.

- *`ls -lR`*: Lists files recursively with detailed information.

- *`ls -d */`*: Lists only directories in the current directory.

Example Commands:

1. *List all files (including hidden) in long format:*

ls -la

2. *List files in human-readable format, sorted by size:*

ls -lhS

3. *List files recursively with detailed information:*

ls -lR

4. *List files with colorization and additional file type symbols:*

ls -F --color

Summary of Most Useful `ls` Options:

| Option | Description |

|-----------|----------------------------------------------|

| `-l` | Long listing format (detailed view) |

`-a` | Show hidden files (starting with `.`) |

| `-A` | Show hidden files, excluding `.` and `..` |

| `-h` | Human-readable file sizes |

‫ شائع العنتي‬.‫م‬
| `-R` | List directories recursively |

| `-d` | List directories themselves, not their contents |

| `-S` | Sort by file size |

| `-t` | Sort by modification time |

| `-X` | Sort by file extension |

| `-1` | One file per line |

| `-F` | Append file type indicator (e.g., `/` for directories) |

| `-i` | Show inode numbers |

| `--color` | Colorize output |

| `-u` | Sort by last access time |

| `-v` | Sort files naturally (useful for numeric filenames) |

This covers the main options for the `ls` command in Linux. You can always check
the manual page (`man ls`) for more advanced options and usage examples.

‫ شائع العنتي‬.‫م‬

You might also like