{

Top 10 ls command examples with tutorials in Linux/Unix


Ls Command Examples unix/linux

ls command

Ls is one of the frequently used commands in Linux as well as UNIX and it is important to know about this command Ls command list the names of files or directories in a directory.

ls command sort the files alphabetically and output to the standard console. when the ls command is executed, the Linux server does inode sorting and outputs the files alphabetically

in Linux, files metadata is stored in a data structure that includes file owner, file access rights, and file type. Each inode is a unique index number in an organized file system data structure.

ls is one of the basic commands of the Unix/Linux operating system.

ls command works on bash shell as well as CentOS of Unix.

ls command syntax usage

$ls (options) (file name or directory)

ls command syntax is shown above and ls command examples are shown below

How to display the content of a directory using the ls command

bash-3.2$ ls
cloud.txt  directory1
```

ls command without options displays the files and directories in a current directory



```markup
bash-3.2$ ls
cloud.txt  directory1
```

**How to list the inode information using the ls command line**

```markup
$ls -l filename
12345 filename
```

here 12345 is the index number

l without options list the files and in the directory

**How to list the files and directories in a given path**
```markup
$ls -l
```

ls command with option -l list out the long file format information about files and directories

**How to list the files based on sorting order modification time.**
```markup
$ls -t
```
ls command with option -t displays the recently modified file first and so on

**How to list directories using commands**
```markup
$ls -d
```
ls command with option -d outputs a list of directories in a given path, but not subdirectories

**How to print the files without doing the sorting?**

```markup
$ls -f  or ls -U
```

ls command does sort the files alphabetical and outputs it, Suppose In a given directory, if there are 500 files, To view all these files if the ls command is supplied without any arguments, the server does sorting of this file's inode and takes more time in hours, so in this case, we need to use ls command with option -f to list the filenames without doing the sorting



**How to display the content of files/directory recursively**



to list the files in directories and subdirectory or recursive directories

```markup
$ ls -R

T


**How to show hidden files in the command line**

```markup
$ ls -a  or ls -A

ls command with option -a outputs the normal files as well as hidden files. to differentiate normal files from hidden files, hidden files always start with ‘.’

THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
Subscribe
You'll get a notification every time a post gets published here.