Tuesday, January 8, 2019

cheat sheet for ls



1. List Files using ls with no option
ls with no option list files and directories in bare format where we won’t be able to view details like file types, size, modified date and time, permission and links etc.


[vn04nxr@client-236651385-1-270480917 ~]$ ls
affiliate_spend_viq_08-13-2018_to_08-23-2018.tsv  employee    first_file  
2 List Files With option –l 
Here, ls -l (-l is character not one) shows file or directory, size, modified date and time, file or folder name and owner of file and its permission.
[vn04nxr@client-236651385-1-270480917 ~]$ ls -l
total 64
-rw-rw-r-- 1 vn04nxr vn04nxr    22 Aug 23 19:11 affiliate_spend_viq_08-13-2018_to_08-23-2018.tsv
-rw-rw-r-- 1 vn04nxr vn04nxr 14510 Sep  3 14:58 cat_more
-rw-rw-r-- 1 vn04nxr vn04nxr    35 Aug 23 21:46 employee



3.View Hidden Files List all files including hidden file starting with ‘.‘.
 ls -a
.                                                 .bash_history  .bashrc   employee    .hivehistory                 .mktg_viq_mta_daily_tmw.yaml.swp  sample2         tab_file.txt
..                                                .bash_logout 

4.List Files with Human Readable Format with option -lh With combination of -lh option, shows sizes in human readable format. # ls -lh
[vn04nxr@client-236651385-1-270480917 ~]$ ls -lh
total 64K
-rw-rw-r-- 1 vn04nxr vn04nxr   22 Aug 23 19:11 affiliate_spend_viq_08-13-2018_to_08-23-2018.tsv
-rw-rw-r-- 1 vn04nxr vn04nxr  15K Sep  3 14:58 cat_more

5.List Files and Directories with ‘/’ Character at the end Using -F option with ls command, will add the ‘/’ Character at the end each directory.
[vn04nxr@client-236651385-1-270480917 ~]$ ls -F
affiliate_spend_viq_08-13-2018_to_08-23-2018.tsv  employee  final_file  mktg_viq_mta_daily_tmw.yaml  sample1  sec_file      testcat
cat_more                                          f_dir/ 

6. List Files in Reverse Order The following command with ls -r option display files and directories in reverse order.
# ls -r
Videos     Public    Music               install.log  fbcmd_update.php  Documents  anaconda-ks.cfg
Templates  Pictures  install.log.syslog  index.html   Downloads         Desktop    0001.pcap

7. ls -R option will list very long listing directory trees. See an example of output of the command.
# ls -R
total 1384
-rw-------. 1 root     root      33408 Aug  8 17:25 anaconda.log
-rw-------. 1 root     root      30508 Aug  8 17:25 anaconda.program.log
./httpd:

Sort Files by File Size With combination of -lS displays file size in order, will display big in size first.
ls -ls
total 72
 4 -rw-rw-r-- 1 vn04nxr vn04nxr    22 Aug 23 19:11 affiliate_spend_viq_08-13-2018_to_08-23-2018.tsv
16 -rw-rw-r-- 1 vn04nxr vn04nxr 14510 Sep  3 14:58 cat_more
 4 -rw-rw-r-- 1 vn04nxr vn04nxr    35 Aug 23 21:46 employee

No comments:

Post a Comment