“ls” Command

The listing command in UNIX and UNIX like operating System ‘ls‘ is one of the most basic and widely used utility in command-line. It is POSIX compliant utility available for GNU coreutils and BSD variants.

ls syntax

$ ls [options] [file|dir]  or

$ [file dir] ls comand

ls command options

ls command main options:

option description
ls -a list all files including hidden file starting with ‘.’
ls –color colored list [=always/never/auto]
ls -d list directories – with ‘ */’
ls -F add one char of */=>@| to enteries
ls -i list file’s inode index number
ls -l list with long format – show permissions
ls -la list long format including hidden files
ls -lh list long format with readable file size
ls -ls list with long format with file size
ls -r list in reverse order
ls -R list recursively directory tree
ls -s list file size
ls -S sort by file size
ls -t sort by time & date
ls -X sort by extension name

ls command examples

You can press the tab button to auto complete the file or folder names.

List directory Documents/Books with relative path:

$ ls Documents/Books

 

List directory /home/user/Documents/Books with absolute path.

$ ls /home/user/Documents/Books

 

List root directory:

$ ls /

 

List parent directory:

$ ls ..

 

List user’s home directory (e.g: /home/user):

$ ls ~

 

List with long format:

$ ls -l

 

Show hidden files:

$ ls -a

 

List with long format and show hidden files:

$ ls -la

 

Sort by date/time:

$ ls -t

 

Sort by file size:

$ ls -S

 

List all subdirectories:

$ ls *

 

Recursive directory tree list:

$ ls -R

 

List only text files with wildcard:

$ ls *.txt

 

ls redirection to output file:

$ ls > out.txt

 

List directories only:

$ ls -d */

 

List files and directories with full path:

$ ls -d $PWD/*

ls code generator

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s