Home » Linux

Linux Terminal Commands - ls command in linux

Working with ls command (listing files & directories)

ls stands for “listing”, ls command lists the files and directories. It is commonly used command in linux.

command description
ls with out any options, ls displays list of files and directories in bare format. You can not get size, access options etc.
                                  
ih@linux:~$ ls
dir1  dir2  ok.txt  ok1.txt
ls --version This option shows the linux ls command version.
                                  
ih@linux:~$ ls --version
ls (GNU coreutils) 8.23
Packaged by Cygwin (8.23-4)
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Richard M. Stallman and David MacKenzie.
ls -l This option displays files and directories with size, modified date and time, access permission and owner’s name.
                                  
ih@linux:~$ ls -l
total 1
drwxr-xr-x+ 1 ih None   0 Apr  4 21:03 dir1
drwxr-xr-x+ 1 ih None   0 Apr  4 21:04 dir2
-rw-r--r--  1 ih None 128 Apr  4 01:05 ok.txt
-rw-r--r--  1 ih None   0 Apr  4 20:49 ok1.txt
ls -a This option shows the all files & directories including hidden files and directories.
ih@linux:~$ ls -a
.   .bash_history  .bashrc   .profile  dir2    ok1.txt
..  .bash_profile  .inputrc  dir1      ok.txt

ls -h
ls -lh
This option shows the all files & directories in human readable format.
ih@linux:~$  ls -h
dir1  dir2  ok.txt  ok1.txt

ih@linux:~$  ls -lh
total 1.0K
drwxr-xr-x+ 1 ih None   0 Apr  4 21:03 dir1
drwxr-xr-x+ 1 ih None   0 Apr  4 21:04 dir2
-rw-r--r--  1 ih None 128 Apr  4 01:05 ok.txt
-rw-r--r--  1 ih None   0 Apr  4 20:49 ok1.txt
ls -F This option shows the all directories with “/” character. So that you can easily understand which directory and which is file.
                                  
ih@linux:~$ ls -F
dir1/  dir2/  ok.txt  ok1.txt
ls -r This option shows the list of all files and directories in reverse order.
ih@linux:~$ ls -r
ok1.txt  ok.txt  dir2  dir1
ls -R This option shows the list of all files and directories in tree format.
                                  
ih@linux:~$ ls -R
.:
dir1  dir2  ok.txt  ok1.txt

./dir1:
f1  f2

./dir2:
f3  f4
ls -lt This option is used to display latest modified (according to date & time) files and directories in reverse order.
                                  
ih@linux:~$  ls -lt
total 1
drwxr-xr-x+ 1 Mike None   0 Apr  4 21:21 dir2
drwxr-xr-x+ 1 Mike None   0 Apr  4 21:21 dir1
-rw-r--r--  1 Mike None   0 Apr  4 20:49 ok1.txt
-rw-r--r--  1 Mike None 128 Apr  4 01:05 ok.txt
ls -lS This option shows the files and directories sorted according to size.
                                  
ih@linux:~$ ls -lS
total 1
-rw-r--r--  1 Mike None 128 Apr  4 01:05 ok.txt
drwxr-xr-x+ 1 Mike None   0 Apr  4 21:21 dir1
drwxr-xr-x+ 1 Mike None   0 Apr  4 21:21 dir2
-rw-r--r--  1 Mike None   0 Apr  4 20:49 ok1.txt
ls -i This option shows the files and directories with inode (indexing) number before files and directories name.

ih@linux:~$ ls -i
11258999068648575 dir1  17451448556084649 ok.txt
5910974511146142 dir2   9007199254962677 ok1.txt
ls -n This option shows files and directories with numeric UIDs, GIDs number.
                                  
ih@linux:~$ ls -n
total 1
drwxr-xr-x+ 1 197609 197121   0 Apr  4 21:21 dir1
drwxr-xr-x+ 1 197609 197121   0 Apr  4 21:21 dir2
-rw-r--r--  1 197609 197121 128 Apr  4 01:05 ok.txt
-rw-r--r--  1 197609 197121   0 Apr  4 20:49 ok1.txt




Comments and Discussions!










Copyright © 2023 www.includehelp.com. All rights reserved.