Basic Commands

These are basic terminal commands that every Linux user must know. Most of the Linux administrators will tell you that that the Linux terminal is the most powerful tool for server management and other security stuff. Open your terminal on any Linux distribution and try out the list of commands given below. In case you don't have Linux installed kindly refer our article on how to install Linux on system or how to install it on Sun VirtualBox , to access Linux inside Windows itself. So, lets practice them one by one.

The commands are highlighted in bold letter.

"#" Indicates that you are a root user or super user

"$" Indicates that your power is limited

Now lets begin with

pwd

Command to view the present working directory

Syntax

[[email protected] root]#pwd

 

cd

to change the working/present directory

Syntax

[[email protected] root]#cd /home/student

where '/home/student' is the desired directory to be change from '/root'

 

ls -l

for listing the files as well as directories those are kept in the particular working directory

Syntax

[[email protected] root]#ls -l

 

ls -la

same as 'ls -l' but by this command we can also see the hidden files.

Syntax

[[email protected] root]#ls -la

 

ls -li

same as 'ls -la' but it will also shows us the inode number of

each and every file

Syntax

[[email protected] root]#ls -li

 

ls

by this command we can see only file name nothing else

Syntax

[[email protected] root]#ls

 

mkdir

to make a new directory

Syntax

[[email protected] root]#mkdir newdirname

 

rmdir

to remove a empty directory

Syntax

[[email protected] root]#rmdir directoryname

 

rm

 to remove a empty file

Syntax

[[email protected] root]#rm filename

rm [-i/-r/-f]

to remove a directory with its subdirectories as well as its

files that is to remove a directory which already contains some files in it

Syntax

[[email protected] root]#rm -i directory/filename

-i stands for interactively

-r stands for recursively

-f stands for forcefully

 

cp

 to copy something in a destination file or directory

Syntax

[[email protected] root]#cp sourcepath destinationpath

 

mv

to move one file or directory from one place to another place, it

is also used for renaming a directory or file

Syntax

[[email protected] root]#mv source destination

[[email protected] root]#mv oldfilename newfilename [to change the file name]

 

touch

to create a new empty file

Syntax

[[email protected] root]#touch

 

cat

to view the contents of a file and it is also used for creating a

new file with some contents

Syntax

[[email protected] root]#cat <file name> to view file contents

[[email protected] root]#cat > newfilename enter,then you can write something in

the file and then to save the file contents press ctrl+d then enter

 

clear

it will clear the screen(short cut ctrl+l)

Syntax

[[email protected] root]#clear

 

exit

to end a current session as well current terminal logging

Syntax

[[email protected] root]exit

 

man

 to view the manual page of commands for syntax and  usage

Syntax

[[email protected] root]#man commandname

 

info

to view the information about any command

Syntax

[[email protected] root]#mkdir info

 

--help

to view the help documents of a command

Syntax

[[email protected] root]#commandname --help

 

find location_to_search_in -name

to find any file or directory in linux file system

Syntax

[[email protected] root]#find / -name filename

 

su –

to become a super user

Syntax

[[email protected] student]$su -

output wil be

[[email protected] root#]

 

su username

to switch from one user to another users home directory

Syntax

[[email protected] root]#su student

output will be

[[email protected] root]#cd

[[email protected] student]#

 

su - username

to switch from one user to another user users home directory directly

Syntax

[[email protected] root]#su - student

 

useradd

to create a new user

Syntax

[[email protected] root]#useradd username

 

passwd

to give a password of a user

Syntax

[[email protected] root]#passwd nitesh

output will be

give a password for user nitesh:(here you have to type a password for nitesh user)

confirm password:(again type the same password)

 

userdel

to remove a user from linux

Syntax

[[email protected] root]#userdel nitesh

 

groupadd

to add a new group

Syntax

[[email protected] root]#groupadd groupname

 

groupdel

to delete a group

Syntax

[[email protected] root]#groupdel groupname

 

chown

to change the ownership of a file or directory

Syntax

[[email protected] root]#chown ownername filename

example:

[[email protected] /]#ls -l

output

drwxrw-rw- 2 root root 4096 Mar 11 12:03 abcd

(permission) (own) (group own)(size) (name)

[[email protected] root]#chown nitesh /abcd

in this example /abcd directory owner will be change to nitesh user

effect

[[email protected] /]#ls -l

drwxrw-rw- 2 nitesh root 4096 Mar 11 12:03 abcd

 

chgrp

to change the group ownership of a file or directory

Syntax

[[email protected] root]#chgrp newgroupownername filename

example

[[email protected] /]#ls -l

drwxrw-rw- 2 nitesh root 4096 Mar 11 12:03 abcd

[[email protected] root]#chgrp nitesh /abcd

effect

[[email protected] /]#ls -l

drwxrw-rw- 2 nitesh nitesh 4096 Mar 11 12:03 abcd

 

chmod

to change the permission of a file or directory

Syntax

[[email protected] root]#chmod value fileordirectoryname

example

[[email protected] /]#ls -l

drwxrw-rw- 2 nitesh root 4096 Mar 11 12:03 abcd

[[email protected] /]#chmod 402 /abcd

[[email protected] /]#ls –l

drw-----w- 2 nitesh nitesh 4096 Mar 11 12:03 abcd

  

Tags: