Wednesday, June 19, 2013

1 - Command "ls"

Posted in ,
Linux has both Graphical User Interface(GUI) mode and Command Line Interface(CLI) mode,it is easy to deal with GUIs than CLIs because it is user friendly. But it is fun to work with commands and you can accomplish the same task you do by GUI through CLI with typing commands in the terminal.

From this section we are planning to talk about unix and linux commands.Before talking about commands you'll have to know about few basic symbols.

They are :

/ - root directory

./ - current directory

./command_name - run a command in the current directory when the current directory is not on the path

../ - parent directory

~ - home directory

$ - typical prompt when logged in as ordinary user

# - typical prompt when logged in as root or superuser

Today as the first lesson we are talking about the very basic command "ls",it is used to list files and directories..

command syntax

ls [options] [file]


ls - Lists the contents of a directory.
ex :



ls ~  - List the contents of your home directory
ex :



ls /   - List the contents of your root directory
ex :





ls ../ - List the contents of your parent directory

ls */ -List the contents of all sub directories

ls -d */ - Only list the directories in the current directory

ls -ltr - List all files by the time they were last modified. Last files listed are the most recently modified files.


You can use many options with "ls" command.

ls [-a][-A][-b][-c][-C][-d][-f][-F][-g][-i][-l][-L][-m][-o][-p][-q][-r][-R][-s][-t][-u][-x][pathnames]

-a - Shows you all files including hidden files(hidden files begin with a dot)

-A - List all files including the hidden files without displaying working directory(.) or the parent directory(..)

-b - Force printing of non-printable characters to be in octal\ddd notation

-c - Use time of last modification of the i-node(file created,mode changed,and so forth) for sorting(-t) or printing(-l or n)

-C - Multi-column output with entries sorted down the columns. This is the default option

-d - If an argument is a directory it only lists its name not its contents

-f - Force each argument to be interpreted as a directory and list the name found in each slot. This option turns off -l,-t,-s and -r and turn on -a. The order is the order in which entries appear in the directory

-F - Mark directories with a trailing slash(/),doors with a trailing greater-than sign(>), executable files with a trailing asterisk(*), FIFOs with a trailing vertical bar(|),symbolic links with a trailing at-sign(@) and AF_Unix address family sockets with a trailing equals sign(=)

-g - Same as -l except the owner is not printed

-i - For each file,print the i-node number (serial number or index number of a file) in the first column of the report

-l - Shows you huge amounts of information(permission,owners,size,last modified date and directory/file)

-L - If an argument is a symbolic link,list the file or directory the link references rather than the link itself.

-m - Stream output format;files are listed across the page,separated by commas

-n - The same as -l,except that the owner's UID and group's GID numbers are printed,rather that the associated character strings

-o - The same as -l,except that the group is not printed

-p - Displays a slash(/) in front of all directories

-q - Force printing of non-printable characters in file names as the character question mark(?)

-r - Reverses the order of how the files are displayed

-R - Includes the contents of sub directories

-s - Give size in blocks,including indirect blocks for each entry

-t - Shows you the files in modification time

-u - Use time of last access instead of last modification for sorting(with the -t option) or printing(with the -l option)

-x - Displays files in columns

-1 - Print one entry per line of output

pathnames - File or directory to list

Use an option and a file or directory name with "ls" command and see the output.

ex :



"-a" option shows you all files including hidden files(hidden files begin with a dot)

ex :







ex :
following output shows              
permission | directories | owners | group | size | last modified date | directory/file








Permissions - The permissions of the directory or file.

Directories - The amount of links or directories within the directory. The default amount of directories is going to always be 2 because of the . and .. directories.
The amount of links means the amount of hard links to that particular file.
The amount of directories means the amount of sub directories within that directory.

Owner - Owner of the file or directory

Group - The group assigned to the file or directory

Size - Size of the file or directory.

Date - Date of last modification.

Directory/file - The name of the file or file.


If you gain some knowledge from this lesson and if you think this is useful leave a comment to encourage us. Good comments or bad comments all are important to usLets meet from a new lesson soon, have a nice day!!!

0 comments :