30 Linux LS Command Pratical Examples Really Useful

By | January 22, 2017

“LS” is linux shell command, which we use most of the time.Out of the all of the linux command’s,number one command which every one uses is “LS” command.

“LS” which will list the files and folders information in various formats.In Linux,we dont use graphical representation to see whether given file is really a file or folder.so,we have to use different command options to find out whether it is file or folder.we have various options for “LS” to find Size,Permissions.

30 Linux LS Command Practical Examples really useful

                                                                           30 Linux LS Command Practical Examples really useful

Let’s go ahead and find out the Various options available on “ls”.

Usage 1: List every file/folder in current folder without more information

## ls

Usage 2: List every file/folder in current folder in reverse order.

## ls -r

Usage 3: List every file/folder in current folder with every information like permissions,last modified time,size,owner of the file or folder and group information

## ls -lrt

Usage 4: List only directory information.

## ls -ld /tmp

Above command displays information about directory /tmp only

Usage 5: list current ls command version.

## ls --version

Usage 6: Create “ls” command alias “ls -l”.

##  alias ls = "ls -l"

whenever,we want to use “ls -ls”,we can use “ls” command.Which will save your typing type.

Usage 7: open the last edited file in the current directory.

## vi `ls -t |head -1`

Usage 8: List root directory.

## ls /

Usage 9: List hidden files in current folder.

## ls -a

Usage 10: List contents of home directory using tilde (~) for current logged in user.

## ls ~

Usage 11: List with long format and show every hidden file.

## ls -la

Usage 12: List every file/folder in reverse order

## ls -r

Usage 13: List every file/folder Recursively.

## ls -R

Usage 14: List every file/folder in current folder and sory by Size.

## ls -S

Usage 15: List every file/folder in current folder and sort by time.

## ls -t

Usage 16: List every file/folder in current folder and sort by extension.

## ls -X

Usage 17: List every file in current folder with readable format

## ls -lh

Usage 18: List every file/folder in current folder with GID and UID

## ls -n

Usage 19: Want to explore LS command itself ?

## man ls

Or

##help --ls

Usage 20: List inode number of every file/folder in current folder.

## ls -i

Usage 21: List every file/folder in current folder.

## ls

Usage 22: Sort files by it’s sizes in every file/folder.

## ls -lS

Usage 23: Find out Last modification of file in curent folder by it’s timestamp.

## ls -ltr

Usage 24: List every file/folder in current folder with special characters *

$ ls -F
Folder1/   LinkFile1@  mytextfile Folder2/  Folder3/  mynormalfile

## ls -F

  1. / –> directory.
  2. no speical symbol –> normal file.
  3. @ –> link file.
  4. * –> Executable file

with the above special charactes,one can identify whether given file is folder/link or directory.

Usage 25: List every file/folder in current folder with colours *

## ls --colour=auto

here separate colour given for similar types.

Usage 26: List contents of it’ sub directories.

## ls -d */

Usage 27: re direct the output of ls command to text output file.

## ls > output.txt

with the above command,we are storing the output into “output.txt”

Usage 28: List every file containing extension .log and .error and .warning in current folder.

## ls *.{log,error,warning}

 

Usage 29: List every file/folder in current folder without any error message.

## ls myfile.txt 2>/dev/null

Usage 30: List every file/folder in current folder,with full path

## ls  -d  $PWD/*

If you have any new LS command Usage,please share it in the Comment’s section.
I will add it here for every reader.Feel free to discuss in the comment section.

Happy Simply Learning 🙂

The following two tabs change content below.

SRINIVAS DARIPELLI

Myself SRINIVAS DARIPELLI. I have 15+ Years of Experience in Programming worked on multiple technologies.Apart from it,I am a blogger, writer, editor, artist and dad 🙂 .I believe in reality.I love to share the Helpful things around the Technology. Feel free to connect with me

One thought on “30 Linux LS Command Pratical Examples Really Useful

Leave a Reply