DEV Community

loading...
Cover image for Linux Commands with "ls"

Linux Commands with "ls"

satizzzzz profile image Sathish Kumar ・3 min read

Welcome back..

In previous article, I have posted about Linux File hierarchy structure Link , please check if you haven't visited.

ls is one of basic commands which lists files/directories that one should know when working with Linux. It is used on daily basis even though we may not aware and never use of all the ls options that are available.

In this article, we will be seeing purpose and different ways of using ls commands with options in Linux.

1.List files using ls with no option

ls with no options lists all the files and directories in a bare format with no other details like file size, owner, permissions, date and time.

image

2.List files using ls with option -l

ls -l will lists the available files and directories with details like file/directory name size, owner, permissions, date and time.

image

3.View hidden files

ls -a will lists hidden files available

image

4.List Files in Human Readable Format with option -lh

You know ls -l will list files/directories along with size and other details. By adding h(Human Readable Format) to it, ls -lh will lists files/directory size in human readable format like bytes, Kb, Gb

image

5.List Directories adding / at the end with option -F

ls -F will list files and add "/" at the end of directories

image

6.List Files/Directories in reverse order

ls -r will list files/directories in reverse order

image

7.Recursively lists Sub-directories

ls -R list all files that are available inside the sub-directories

image

8.Listing latest updated files/directories

ls -ltr will lists files and directories in reverse order with latest modification as last

image

9.Sorting files by file size

ls -lS will lists the file size in order, by displaying big size first

image

10.Display Inode number of File or Directory

Inode number is unique identification number that are assigned when new file/directory is created.

ls -i will display the inode number of a file/directory

image

11.ls version

ls --version will return the version of ls

image

12.Show help page

ls --help will display the help page

image

13.List directory information

ls -l /Dir_name will lists all the files/directories inside the defined directory

image

14.Display UID and GID of Files

ls -n will display the UserID and GroupID of files/directories

image

Hope the above information is useful. :)

Discussion (0)

pic
Editor guide