In this Blog we are going to discuss all the necessary and basic commands which every IT professional working on linux platform should know.
Computer-savvy individuals consider Linux as the best operating system owing its feature of getting customized more easily than its popular counterparts.
To learn better there are screenshot attached with every commands to practice and refer for understanding.
This command is used to list all the files and directories.
All the files present in the current directory are shown once the ls command was typed in the terminal.
b) Syntax :- ls -ltr filename
command is used to list one file with name mentioned in command.
Here you can see the command gives full detail about the file acadgild.
c)Syntax: – ls –ltr
-l long listing
Command is used to lists in the order of their creation time . list of files and directories contains permissions, links, ownership, group, date, time and file-name .
Here you can see the list of all files present in the directory arranged in order of creation . Different columns indicate permissions, links, ownership, group, date, time and file-name. For every file all these content are stored in computer by default .
d) Syntax:- ls –lc filename
-l long listing
-c character specific file
Here you can see the listing of file in alphabetical order.
e)Syntax:– ls -la
To display all hidden files. All Hidden files are start with DOT(.)
Here you can see all the hidden files present in the current directory. We can notice all file is prefixed with .(dot) which indicates all file are system files, hidden from users.
a)Syntax:- touch <filename>
To create an empty file. Size of file is 0 bytes.
Here file will be generated with name acadgild and will be present in same location until user modifies/deletes it.
b)Syntax: touch f1 f2 f3 f4
Here the command will create 4 files named f1,f2,f3 and f4 at same location in the system.
a)Syntax:- mkdir directoryname
To create a new directory
Here you can see a directory named acadgild is created by the user.
b)Syntax:- mkdir -p d1/d2/d3/d4/…………
-p parent directory
To create a directories & subdirectories recursively
Here you can see several directories and subdirectories are created and given parent permission at a time.
a)Syntax:- rm filename
It is used for to remove a file/files
Here you can see the file f1 is being deleted.
b)Syntax:- rm -rf < filename/directoryname >
To remove files, directories and subdirectories Recursively or Forcefully
Here you can see the the directory which contain data inside will also get deleted by using this -rf along with rm.
c)Syntax:– rmdir < directoryname >
To remove an empty directory
Here you can see directory named sasi is being deleted.
It reflects back the content ,whatever written after echo command.
Here you can see the comment written just after the command echo is printed again i.e anything following the echo command is displayed on the terminal.
b)Syntax:- echo “some content” > filename
To insert text inside a file and will delete all previous data of the file.
Here you can see the statement is redirected to the file acadgild as content and later the content can be printed by cat command.
c)Syntax:- echo “some content” >> filename
Here you can see the statement is redirected to the file acadgild along with the previous data as content and later the content is printed by cat command.
Syntax:- cat filename
To read a file
Here you can see the cat command is used to through all the contents of file to the terminal.
Syntax:- more filename
To read a file page-by-page,
use SPACE-BAR to move for NEXT PAGE
Here you can see the data of /etc/profile is shown page by page. It is used to read long file, with lots of data.
Syntax:- ls –i filename
Each inode stores the attributes and disk block location(s) of the filesystem object’s data
Here you can see for a file(acadgild) one inode will be created and that inode will be associated to file(acadgild).
It shows the information about the users who are logged into the system currently.
Here you can see two user logged in named root and pranu with detail of what date, time and IP they used to log IN.
b)Syntax: who –b
-b indicates the time and date of the last reboot.
To see when the server/system was started.
Here you can see the last time when system started/booted was 29/12 at 12.06 pm.
c)Syntax:- who -r
-r indicates the current run level of the init process
A run level is a state of init and the whole system that defines what system services are operating.
Here you can see the run level is 3
d)Syntax:- who -a
-a lists processes, variables, users, run-levels
Here you can see all the who commands summary at glance.
Can be used in two ways, either way will result change in directory
a)Syntax:- cd <directory name>
Is used to change directory
Here you can see we entered inside acadgild directory.
b)Syntax:- cd ..
This command is used to exit from a directory.
Here you can see the command brings us one directory prior to where we was.
To display the present Working Directry
Here you can see the path of the current working directory. It is very useful while working on terminal.
To display the current date and time of the system.
Here you can see the current day,month,date and time followed by timing zone and year.
It shows the present month calendar
Here you can see the calendar for a particular month.
b)Syntax:- cal <year>
To display the calendar of the year mentioned.
Here you can see the calendar for year 2015.
Syntax:- mv <sourcefile> <destinationfile>
It is used to rename a file or move the file from one location to another location
Here you can see a file f2 is being moved with the new name f3, with all the contents of file f2 preserved in f3.
a)Syntax:- cp <source file> <targetfile>
To copy a file in same directory.
Here you can see the file m1 content is copied to file m2.
b) Syntax:-cp -r :
To copy all files and subdirectories recursively present inside a parent directory.
Here you can see directories named big data, frontend and hadoop is copied when the parent directory is copied
c) Syntax:-cp -f :
-f Unlink. If a file descriptor for a destination file
cannot be obtained, this option attempts to unlink the
destination file and proceed.
d)Syntax:-cp -i :
-i Interactive. cp prompts for confirmation whenever the
copy would overwrite an existing target.
e) Syntax:-cp -p :
it is use to (keep the same detail record of original file)preserve the permission, time, date of source file to target file
f)Syntax:- cp –rpfi <sourcefile> <destinationfile>
Here you can see the the contents of p1 is forcefully pushed into p2 by deleting all the previous data of p2.
a)Syntax:- df -k
-k prints the allocation in Kilobytes
To display/read the free DISK FILES.
It lists file system name, allocated size, used size, available size, used size in %, mounted on.
Here you can see list of all the mounted disk path with actual disk utilization status in detail.
b)Syntax: df -h
-h prints the allocation in human readable format. scaling is done by repetitively dividing by 1024.
To display/read the DISK FILES in format
Here you can see the output is same as previous command but with only one difference the size are displayed in GB and MB which is more comfortable for humans to understand, as storage constraint is negligible in today’s era.
Syntax:- man <command-name>
It displays the full information about the command. Any command detail can be found inside man.
Here you can see the description of a command cat.
Syntax:- which <command-name>
It display where the command is residing
Here you can see cat location is shown as output i.e, cat is being used from /usr/bin/cat .
To find out since how long the server is up & running
Here you can see the server is in running state science 2:14pm for 2 hours and 8 minutes.
To display the present logged in user-id and group-id with username and groupname.
Here you can see the present user id and group id you are logged in.
b)Syntax:- id -g username
it shows only the group id
Here you can see only the group ID for acadgild user.
To see how many users logged into the system and also display the user name and its idle time.
Here you can see the root user is sitting idle for 2 hours and 7 minutes.
The write utility reads lines from the user’s standard input and writes them to the terminal of another user. When first invoked, it writes the message:
Message from sender-login-id (sending-terminal) [date]…
to user. When it has successfully completed the connection,
the sender’s terminal will be alerted twice to indicate that
what the sender is typing is being written to the
To send a message to the user who is using the same system
To see which username you logged in
<span style="color: #ff6600;"><strong><span style="font-size: 12.8px; line-height: 1.5; background-color: #f4f4f4;">Note: If output is not displayed then we can given</span></strong></span>
Step 1:- PATH=/usr/bin:/usr/ucb (enter)
Step 2:- Export PATh (enter)
Step 3:- Whoami
Here you can see the username of system.
Syntax:- ping ipaddress
This command is used to find out either server is alive are not.
Here you can see the the IP 192.168.56.24 is alive.
For continous reply ping -s Ipaddress
Note : in windows ping -t Ipaddress
a)Syntax:- telnet ipaddress
Note: telnet uses the port number --- > 23
This command is used to connect the server (remote server).
Here you can see server is connected and after login it shows few details on last login.
Syntax:- nslookup DNS name (ip address from DNS)
It is a name server lookup to resolve the host IP address from DNS name ( forward zone ) and to get hostname from the ip address ( reverse zone ) .
Syntax:- nslookup ipaddress
DNS from ip address
Here you can see the lookup command will search for the address of google and communicate with it, either with domain name or IP.
a)Syntax:- ifconfig -a
-a = to all the interfaces
To see the Ip Address of the server we use this command
Note: if not display output then give
Step 1:-PATH=/usr/bin:/usr/ucb (enter)
Step 2:-Export PATH (enter)
Step 3:-Ifconfig -a
Here you can see the IP of the server is 192.168.56.24
In windows we use the command in cmd prompt for the same.
The full permission of a file/directory is 7 -7 -7 = rwx -rwx -rwx = ownership -group -other group
x-Execution = 1
so total rwx =7
The maximum permissions for a file is 6 -6 -6 = -rw- -rw- -rw-(- prefixed in owner represents the type; file)
When we create a file the default permissions will 6 – 4 – 4. it Is obtained by reducing umask value to maximum permissions . i.e 666 – 022 = 644 (d prefixed in owner represent the type; directory)
Note: the umask value is 022 by using the below command we can see the command Syntax:- cat /etc/profile
The maximum permissions for a directory is 7 – 7 -7. it is obtained by reducing umask value to maximum permissions. i.e 777-022 = 755.
a)Syntax:- chmod 755 filename
To change permissions of a file or directory
Here you can see the permission for the file is changed to 755 for user,group and owner.
b)Syntax:- chmod -R 755 directory_name
This command is used to change the permissions recursively for a directory
Here you can see the directory dishitha is changed with permission 755.
c)Syntax:- chmod 755 *
This command is used to change the permissions for all files & directories of present working directory
Note:- DOT (.) represent for present directory(..) represent for parent directory
Here you can see all files permission is changed to 755 in the current directory.
d) Syntax:-chmod 444 file name
Read permissions only we can given
Here you can see the file dishitha is given only read permission.
There are different ways to use this command
a)Syntax:-chown username(or)groupname filename (command is used only in root)
This command is used for the change the ownership
b)Syntax:– chown username:group directory name (or) file name
To change the ownership of the file or directory. This command should be executed by root ( / ) user.
c)Syntax:– chown –R username:group directory name (or) filename
-R=for recursive change
Here you can see the file hadoop owner is changed from root to 555.
a)Syntax:- ps -ef
PROCESS STATUS. To list all the process status.
e = entire running process
f = generate full listing process
Here you can see the list of all process status in detail.
b)Syntax:- ps -ef |grep java
To display the java process
Grep is used for filtering/searching
| pipe symbol is used for sending output of one command to next command as a input if we use two or more commands in the program.
Note : grep -i ….to ignore case sensitive
Grep -v …..void excluding
Here you can see the java process status in details.
a)Syntax:– du -k filename
-k Write the files sizes in units of 1024 bytes,
rather than the default 512-byte units.
DISK UTILITY. To see how much size is occupying in the disk by each file & directory.
Here you can see the file dishu is occupying 1 disk utility.
b)Syntax:- du -sk filename
-s Instead of the default output, report only the
total sum for each of the specified files.
To display the each file & directory size recursively of present working directory.
Here you can see the dishitha is taking 1 disk utility for parent.
c)Syntax:- du -sh filename
-h All sizes are scaled to a human readable format,
for example, 14K, 234M, 2.7G, or 3.0T. Scaling is
done by repetitively dividing by 1024.
To display the disk utility of a file & directory in kilobytes.
To display the utility size in human readable format
Here you can see the current directory is taking 1 KB of disk utility.
Syntax:- useradd<new username>
This command adds new user to login with
To check if user got added successfully to the system. we can see inside the master directory where all users of the system is present. i.e. /etc/passwd.
we can follow the screenshot below.
We see here the user which we created using command useradd is present.
It clears the terminal by bringing the current line with the cursor to the top of the terminal.You may see the screenshot for better unserstanding.
After the command executes we get our terminal screen like below.
diff <filename1> <filename2>
diff3 <filename1> <filename2> <filename3>
(a)Syntax:- diff filename1 filename2
Helps us tocomparee contents of two files.
(b)Syntax:- diff3 <filename1> <filename2> <filename3>
This also compares the file but instead fo 2 it can compaire 3 files at a time.
This commnad when entered in terminal it opens the CD-Rom drive out.
Syntax:- head <filename>
This command shows only few starting lines of any file. Unless like cat printing the complete file records, it saves memory, process time and resource time of the system.
Syntax:- tail filename
This command shows only few end lines of any file. Unless like cat printing the complete file records, it saves memory, process time and resource time of the system.
Syntax:- kill <process id>
If we know the process id of any program we can stop it through the terminal using kill command. In below screenshot, we find processid for java processes and we stop one of the process using kill.
Syntax:- locate filename
The command helps user to find any type of file or directory present in system.
This will cange the pasdword for the user you are currently logged in.
(a)Syntax:- tar -cf <filename>
This command shows the list of files compressed inside.
(b)Syntax:- tar -tvf <filename>
This will list all the files along with properties of files such as there permissions, user access ,file size, date and time.
(c)Syntax:- tar -xvf <filename>
This will extract the file sin the present directory.
Scp (secure copying) is a remote file copy program
For fetching or copying:
syntax:- scp [email protected]:location of a file/filename where to copy location
scp [email protected] :/opt /app/acadgild/math.sh /tmp/satya
Here you can see the file topology.sh is being fetched from another/remote user PATH = /home/hadoop/Desktop/topology.sh and copied to local user PATH = /home/hadoop/Desktop . The 100% indicates the file transfer is complete.
Syntax : scp senders filelocation/filename [email protected] :/path/location to copy
Ex: scp /opt/app/satyam/filename [email protected]:/opt/app/acadgild
Here you can see the file topology.sh is being copied to another/remote user PATH = /home/hadoop and local user PATH = $HOME. The 100% indicates the file transfer is complete.