Nitendra Gautam

Basic Linux Command

Linux is a family of free and open-source software operating systems built around the Linux kernel. This blog includes some of the basic commands that are used in unix environment

Present Working Directly(PWD) in Linux

Use the below command to find the present working directory .


Path in Linux

A path is a unique location of path or directory in Linux .

Linux has two type of path.

Absolute path: It is the full path of a file or a directory from the root directory(/).

Relative Path: It is the path relative to the present working directory .

Listing the files and directories

[email protected]:~/linuxtutorials$ ls
data  file1.txt
[email protected]:~/linuxtutorials$

list all files and directories with Permissions, Date and Time

ls -l

[email protected]:~/linuxtutorials$ ls -l
total 0
drwxrwxr-x 0 hduser hduser 512 Nov  9 18:14 data
-rw-rw-r-- 1 hduser hduser  20 Nov  9 18:12 file1.txt
[email protected]:~/linuxtutorials$

Lists all directories

ls -d /

[email protected]:~/linuxtutorials$ ls -d */
data/  docs/

Display files and directories of a relative path

ls /home
[email protected]:~/linuxtutorials$ ls /home
hduser  nitendragautam

Displays all the files and direcories of home directory

ls ~

[email protected]:~/linuxtutorials$ pwd
[email protected]:~/linuxtutorials$ ls ~
linuxtutorials   start_Apache_Hadoop.bash          

cd command is used to navigate in Linux/Unix system.

cd <directory_path>
cd ~
[email protected]:~/linuxtutorials$ cd ~
[email protected]:~$ pwd

cd /

[email protected]:~/linuxtutorials/data$ pwd
[email protected]:~/linuxtutorials/data$ cd /
[email protected]:/$ pwd

Move to previous directory from current directory

cd ..

Move two directories back from current directory

cd ../..

Change from PWD to another directory

cd <Directory Name>

Files and Directory manipulations

Create a directory in Linux

mkdir <Directory Name>**

Create a directory recursively

mkdir -p <Directory1/Directory 2/Directory 3>

-p means progressively creating

mkdir -p /home/hduser/dir1   :Create multiple directory         

deletes file in current path

rm <file name>
:~$rm file1.txt

Forcefully removes everything(Files and directory) in the path

rm -rf <Directory
:~$rm -rf /home/hduser/dir1/dir2

Permissions and Ownership in Linux

Changing Mode in Linux

Below command can be used to change permission of file for protection

chmod {options} filename
  • Option u :user g:group o:other a:all r:read w:write(and delete) x:execute(and access directory) +:add permission -take away permission

Give executable permission to Linux Script

 #making the executables 
 [email protected]:~/scriptingSample$ chmod a+x

Changing file ownership

chown <file permission > <file name> 

VI text editor

~$vi file.txt :Creates File.txt or opens file.txt for editing

It has three modes 3 Modes : Esc mode-Esc button {by default this mode} Insert Mode - pressing ‘i’ button Colon mode -Pressing “Shift +:” Button

In colon mode when seeing : Press “Wq” to save file and exit :q! -for exiting without saving file

Deleting the content with vi or Vim editor


#: tells vi to go in command mode
#% means all the line
#d : delete


Linux Tutorials