ls command is one of the most frequently used command in Linux. I believe ls command is the first command you may use when you get into the command prompt of Linux Box. We use ls command daily basis and frequently even though we may not aware and never use all the option available. In this article, we’ll be discussing basic ls command where we have tried to cover as much parameters as possible.
![Linux ls Command](http://www.tecmint.com/wp-content/uploads/2012/08/Linux-ls-Commands.png)
Linux ls Command
### 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.
anaconda-ks.cfg Documents fbcmd_update.php install.log Music Public Videos
### 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 it’s permission.
# ls -l
total 176
-rw-r--r--. 1 root root 683 Aug 19 09:59 0001.pcap
23594 Desktop 23585 fbcmd_update.php 35 install.log.syslog 23601 Public
### 11. Shows version of ls command ###
Check version of ls command.
# ls --version
ls (GNU coreutils) 8.4
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
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.
### 12. Show Help Page ###
List help page of ls command with their option.
# ls --help
Usage: ls [OPTION]... [FILE]...
### 13. List Directory Information ###
With ls -l command list files under directory /tmp. Wherein with -ld parameters displays information of /tmp directory.
# ls -l /tmp
total 408
drwx------. 2 narad narad 4096 Aug 2 02:00 CRX_75DAF8CB7768
-r--------. 1 root root 384683 Aug 4 12:28 htop-1.0.1.tar.gz
drwx------. 2 root root 4096 Aug 4 11:20 keyring-6Mfjnk
drwx------. 2 root root 4096 Aug 16 01:33 keyring-pioZJr
drwx------. 2 gdm gdm 4096 Aug 21 11:26 orbit-gdm
drwx------. 2 root root 4096 Aug 19 08:41 pulse-gl6o4ZdxQVrX
drwx------. 2 narad narad 4096 Aug 4 08:16 pulse-UDH76ExwUVoU
drwx------. 2 gdm gdm 4096 Aug 21 11:26 pulse-wJtcweUCtvhn
-rw-------. 1 root root 300 Aug 16 03:34 yum_save_tx-2012-08-16-03-34LJTAa1.yumtx
----------
# ls -ld /tmp/
drwxrwxrwt. 13 root root 4096 Aug 21 12:48 /tmp/
### 14. Display UID and GID of Files ###
To display UID and GID of files and directories. use option -n with ls command.
# ls -n
total 36
drwxr-xr-x. 2 500 500 4096 Aug 2 01:52 Downloads
drwxr-xr-x. 2 500 500 4096 Aug 2 01:52 Music
drwxr-xr-x. 2 500 500 4096 Aug 2 01:52 Pictures
-rw-rw-r--. 1 500 500 12 Aug 21 13:06 tmp.txt
drwxr-xr-x. 2 500 500 4096 Aug 2 01:52 Videos
### 15. ls command and it’s Aliases ###
We have made alias for ls command, when we execute ls command it’ll take -l option by default and display long listing as mentioned earlier.
# alias ls="ls -l"
Note: We can see number of alias available in your system with below alias command and same can be unalias as shown below example.
# alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
To remove an alias previously defined, just use the unalias command.
# unalias ls
In our next article we’ll cover up more or advanced ls command with their examples. If we’ve missed anything in the list, please update us via comment section.