some basic commands that we use in linux

Pranaam to all bhai ji _/\_
in this post we will go through some basic commands which we use commonly in linux.

but first of all let me clear term full path and relative path.

full path is the path of something with respect to  /  
for example if we are in /root directory and we have file i.txt , then full path for the file will be 
for file , which exist in  var directory, having name log.txt , full path will be /var/log.txt
relative path is path respect to current working directory in which we are working
suppose, we are in directory /home/ica and there is file user.txt in directory document
the relative path for file user.txt will be document/user.txt
and full path will be /home/ica/document/user.txt  

we will discuss about following commands in this tutorial

pwd - to know present working directory
cd - change directory
cp - file/directory copy purpose
rm - removing file/directory

mkdir - create new directory
touch - make new file
su - switching from one user to another
passwd - setting/changing password

ls  - listing content of directory
cat - I/O  redirection command but will discuss its data displaying feature only
mv - rename a file or folder

pwd command
pwd stands for present working directory, directory in which we are working currently .
to know the location of current directory with respect to / (or we can say pwd show full path of directory where we are working )
syntex of pwd command:-  pwd

cd command :-
this command is use to change directory from present one(in which we are working) to that in which we want to work.
syntex for cd command :-  cd  directory_name/full_path_to_directory
example given below , we were in /home directory then we checked file/directory in present working directory using ls command and in result we got ic , ica and indishell directories in /home directory
we ntered into ica directory using command    cd  ica  .

we also used full path concept to jump into directory www , which is in /var and we were working in /home/ica in above screen shot. that is we checked our present working directory by using command pwd and found it was /home/ica . and to switch into /var/www directory we run used full path to directory www with cd command and command was cd /var/www

cp command :-
we use this command to copy files or directories from one location to another location .
for example we have a file having name  ica.txt in directory /root and we want to copy it to location /var directory , we will use cp command to copy file .

copy command file usage
cp   source   destination
here source stand for the file with or without full path
destination is the directory where we want to copy our file
full path is the path of something with respect to  /
for example if we are in /root directory and we have file ica.txt , then full path for the file will be
we will use full path if we are not in the same directory from where we want to copy file.we can use full path if we are in same directory from where we want to copy file but it will be irritating to type full path in that case :P. here is an example of cp command.

use  -R  when you are copying a directory having files from one location to another, else you will get an error .

-r stands for recursively .
rm command is use to remove file or directory. it take file/directory name as argument, which has to delete/remove.
syntex is :- rm  file/directory name  or   rm   /full_path_to_file_or_directory
lets have an example, we have file r.txt in /root directory. run pwd command to check full path of pesent working directory in which are working. if it is same directory from where we want to delete file/directory, just run  rm r.txt  command  and shell will ask to confirm file deletion action, press enter for yes or press ctrl+c to abort.

run  rm -f file_name command, if you dont want file deletion action confirm prompt. as you will run this command , file will just deleted without user confirmation.

if you are not in /root directory and want to remove file from /root directory then you need to specify full path of the file, like in the below example , i was in /home directory and file was in /root directory with name r.txt

if you want to delete a directory  which contains files , we need to supply  -r(recursively)f(forcefully) as argument with rm command that is  rm -rf  directory

mkdir command
to create new directory , we use mkdir command.
syntex for this command is  mkdir  directory_name/full_path_directory_name

for example we are in /var/www directory and want to create directory linux under /var/www directory
command will be mkdir linux
if we are in not in /var/www directory and want to create a directory with name linux in /var/www directory, then we need to specify full path of the directory in which we want to create directory and the directoyr name with which e want to create new directory.
like this
mkdir  /var/www/linux
this command will create directoyr linux if /var/www directory exist

touch command
touch command is use to create new files .
syntex for tuch command :-  touch  file/files_name_separated_by_space/full_path_to_dir_with_filename
touch r.txt  (single file creating touch command)
touch  r.txt  t.txt  w.txt (multiple file creation using touch command)
touch /var/www/html/r.txt  (creating r.txt file in /var/www/html directory)

su command :-
su stands for switch user that is changing from one user to another .
we required a user on linux machine so that we can login and can work. but if we want to switch to another user after login , we use switch command to change user .
syntex for su command :-  su     username_to_whom_we_want_to_switch
su  username
like we have logged in with user root and we want to change from root user to some other user, we just need to type su username in terminal and press enter. if we are running with user root , shell wont ask to provide password of that user to whom we are switching but if we are not root user and then using su command , shell will ask the password of that user and will let us switch if password is correct

passwd command
this command is mainly use to manage passwords and password related things like change/expire/lock/delete password for the user whose username got provided in command as argument
Syntex of passwd command is:-  passwd  [option]  username
here option represent option like deleting/changing/lock/expire

commonly user passwd command to change password
like we are user ica and want to change our current user, we will issue command  passwd  in terminal to set new password

if we are root user and want to chaange non-root user password which exist on system, command will be
passwd username

ls command
ls command use to list content of a directory .
syntax of ls command :-   ls  [option]  directory
let we want to list content of directory /var/www, we will run this command
ls  /var/ww

 listing all content of directory including hidden files
command is   ls -a
to list content of a directory with file permissions and hidden files , we use  ls -al directory

cat command
cat command is actually I/O redirection command but most of us consider it as data display command
we will discuss about cat command later , right now we are just going through data display feature of cat command
syntax of cat command :- cat file_name/fulle_path_to_file
cat  ica.txt
cat /root/ica.txt  (full path )

mv command
mv command is use to rename file/diretory .
syntax of mv command :- mv   source_file/directory   destination_name

source file may/may not exist in same directory where we are working .if file exist at another location on system , provide full path of the file/directory

Thank you

Greetz to:- Guru ji zero and whole Team IndiShell <3

Share this post


  1. Bhashit Pandya30 July 2013 at 08:30

    Bhaiji sahi blog banaya! :)
    Keep it up bhai! :)
    Proud to be with u!

  2. thank you bhai ji _/\_
    and you can also forward posts related to linux which can help beginners in learning :)

  3. Sure! :)


:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

© 2009 Start With Linux | Mannu Linux
Designed by cyb3r.gladiat0r
Posts RSSComments RSS
Back to top