ls Command in Unix and Linux Examples

  • Updated
  • Posted in Programming
  • 4 mins read


ls is essentially the most extensively used command in unix or linux. ls command is used to listing the contents of a listing. Learn the ability of ls command to make your life straightforward. The syntax of ls command is

ls [options] [pathnames]

1. Write a unix/linux ls command to show the hidden information and directories?

To show the hidden information and directories in the present listing use the -a choice of the ls command.

> ls -a
. .. paperwork .hidden_file sum.pl

Hidden information are the one whose title begins with dot (.). The las -a shows the present listing (.) and mum or dad listing (..) additionally. If you wish to exclude the present listing, mum or dad listing, then use -A choice.

> ls -A
paperwork .hidden_file sum.pl

2. Write a unix/linux ls command to categorise the information with particular characters

The -F choice to ls command classifies the information. It marks the

  • Directories with trailing slash (/)
  • Executable information with trailing asterisk (*)
  • FIFOs with trailing vertical bar (|)
  • Symbolic hyperlinks with trailing on the price signal (@)
  • Regular information with nothing
> ls -F
paperwork/ sum.pl [email protected]

3. Write a unix/linux ls command to print every file in a separate line?

The -1 choice to the ls command specifies that every file must be displayed on a separate line

> ls -1
paperwork
sum.pl

4. Write a unix/linux ls command to show the inode variety of file?

In some instances, you wish to know the inode variety of a file. Use -i choice to the ls command to print the inode variety of a file.

> ls -i1
10584066 paperwork
3482450 sum.pl

5. Write a unix/linux ls command to show full details about the information?

The -l choice offers a lot of details about the file kind, proprietor, group, permissions, file measurement, final modification date.

> ls -l
complete 16
drwxr-xr-x 2 matt db 4096 Jan 30 23:08 paperwork
-rw-r--r-- 1 matt db 49 Jan 31 01:17 sum.pl
  • The first character signifies the kind of the file. – for regular file, d for listing, l for hyperlink file and s for socket file
  • The subsequent 9 characters in the primary subject signify the permissions. Each 3 characters refers the learn (r), write (w), execute (x) permissions on proprietor, group and others. – means no permission.
  • The second subject signifies the variety of hyperlinks to that file.
  • The third subject signifies the proprietor title.
  • The fourth subject signifies the group title.
  • The fifth subject represents the file measurement in bytes.
  • The sixth subject represents the final modification date and time of the file.
  • And lastly the seventh subject is the title of the file.

6. Write a unix/linux ls command to type the information by their modification time?

The -t choice permits the ls command to type the information in descending order based mostly on the modification time.

> ls -t1
sum.pl
paperwork

7. Write a unix/linux ls command to type the information in ascending order of modification time?

The -r choice reverses the order of the information displayed. Combine the -t and -r choices to type the information in ascending order.

> ls -rt1
paperwork
sum.pl

8. Write a unix/linux ls command to print the information recursively?

So far the ls command prints the information in the present listing. Use the -R choice to recursively print the information in the sub-directories additionally.

> ls -R
.:
paperwork sum.pl

./paperwork:
file.txt

9. Write a unix/linux ls command to print the information in a particular listing?

You can move a listing to the ls command as an argument to print for the information in it.

> ls /usr/native/bin

10. Write a unix/linux ls command to show information in columns?

The -x choice specifies the ls command to show the information in columns.

> ls -x

Leave a Reply