There are many commands to view and display contents but I would be sharing few commands, which are mostly used and common.

View Directories and Files in Unix and Linux_bashcodes

Present Working Directory – show where are you now in the terminal window.

$ pwd

Listing of directory content.

$ ls

lists the directories and files in a directory.

$ls -a

lists all file in directory, including hidden files[NOTE: hidden files begin with (.)].

$ ls -l

Shows detailed information about the content of directory.

$ ls –ld

directory name- shows detailed information for the directory only, not its contents

$ ls -R

directory name-displays the content of a directory and the contents of all the directory’s sub directories. This type of list is known as recursive list.

$ ls -F

displays the file types


[table id=2 /]


$ file filename

Used to determine certain file types. Knowing the file type helps you decide which command or program you need to use to read the file.

[table id=3 /]

$ cd /directory

to get into some directory.


$ cd..

moving to the previous directory.

$ cd../../..

moving to the root directory.

$ cd pathname

to directly move to that particular directory.

$ cd ~ user 


to move to the user’s home directory.

Viewing Files

$ cat filename

displays the content of one or more text files on the screen

$ more filename

view or page through the contents of a long text file.

$ head -n filename

The head command displays the first 10 lines of a file.

$ tail -n filename

The tail command displays the last 10 lines of a file. You can change the number of lines displayed by using the – n or + n options. The – n option displays n lines from The end of the file. The + n option displays from line n to the end of the file.