Linux Commands for linux learner & engineering students

kamalkhatri12 10 views 15 slides May 15, 2025
Slide 1
Slide 1 of 15
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15

About This Presentation

Linux Commands for linux learner


Slide Content

Magnum Net Solutions Pvt. Ltd., 25, Saikrupa Apt, Central Excise Colony, Chhatrapati Square, Nagpur 15
Magnum
9850332133
The Creation of Linux :
In 1991, in Helsinki, Linus Torvalds began a project that later became the Linux kernel. It was initially
a terminal emulator, which Torvalds used to access the large UNIX servers of the university. He wrote the
program specifically for the hardware he was using and independent of an operating system because he wanted
to use the functions of his new PC with a 80386 processor. Linus Torvalds and countless number of people
around the world improved the OS later on.
Linux Features :
Multitasking : several programs running at once
Multiusers : several users at the same machine at once
Multiplatforms : it runs on many different CPU
Getting Started :
You can login to an Linux operating system after you had been assigned a username by a system admin-
istrator. Your login screen may look like
If you are administrator of the system then your user name will be root and you may get prompt like
below.
The # prompt indicates that you are Master User
User Name
Name Of Machine
Home Folder
$ Prompt is for Normal User
Understanding Linux

Magnum Net Solutions Pvt. Ltd., 25, Saikrupa Apt, Central Excise Colony, Chhatrapati Square, Nagpur 15
Magnum
9850332133
Operating Linux System :
Linux is case sensitive operating system. The commands are usually in lower case format un-
less otherwise specified. Environment variable and other macros are usually found in capital letters.
After login you can issue commands as below.
1. Clearing the screen :
This command clears the text screen. This is equivalent to CLS command in DOS.
2. date command :
[test@ns2 ~]$ date
Sun Dec 9 08:01:03 CST 2007
The date command shows the current date if used without any option. Some examples are,
a] The command below sets date as 08 December, 2007 with time as 08:15 PM
[test@ns2 ~]$ date 120820152007
b] With %D option you can get as mm/dd/yy format
[test@ns2 ~]$ date +%D
12/09/07
3. cal command :
The cal command shows calender of the current month if used with out option.
[test@ns2 ~]$ cal 2008
The above command prints calender of complete year.
[test@ns2 ~]$ clear

Magnum Net Solutions Pvt. Ltd., 25, Saikrupa Apt, Central Excise Colony, Chhatrapati Square, Nagpur 15
Magnum
9850332133
4. ls command :
The ls commands lists the directory contents of the present working directory. You can also add
path to get directory listing of other folders also. In Linux a file name can be up to 255 characters long.
Any characters can be used as file name but files begining with . are termed as hidden files. Let us
examine following output
The option ,
-a Do not hide entries starting with .
-l Display long listing
drwxr-xr-x 1 root root 4096 Dec 9 07:55 testfolder
Every file or folder has three types of permissions.
r Reading permission
w Writing permission
x Execution permission
In above example rwx permissions are enabled for user root. Reading and execution permis-
sions are enabled for group members of root. Also other users which do not belong to root group can
read and excute the file or folder.
The first letter d in example says that the entry is folder. You can find following letters in place
of d.
d : Folder - : Regular File
l : Soft Link b : Block Device
c : Character Device

Magnum Net Solutions Pvt. Ltd., 25, Saikrupa Apt, Central Excise Colony, Chhatrapati Square, Nagpur 15
Magnum
9850332133
5. who command :
The who command lists the currently logged users.
6. pwd command :
The pwd command shows the present working directory.
[test@ns2 ~]$ pwd
/home/test
[test@ns2 ~]$
7. cat command :
The cat command displays the contents of file on screen.
[test@ns2 ~]$ cat /etc/webalizer.conf
User can controle the output:
press space the next screen is displayed
press enter the next row is displayed
press q the command is finished
8. head command :
The head command displays the starting contents of file on screen.
[test@ns2 ~]$ head -5 /etc/webalizer.conf
The command above shows first 5 lines of file webalizer.conf located in /etc folder.
9. tail command :
The tail command displays the ending contents of file on screen.
[test@ns2 ~]$ tail -7 /etc/webalizer.conf
The command above shows last 7 lines of file webalizer.conf located in /etc folder.

Magnum Net Solutions Pvt. Ltd., 25, Saikrupa Apt, Central Excise Colony, Chhatrapati Square, Nagpur 15
Magnum
9850332133
10. cp command :
The cp command copies source file to destination file.
The command syntax is as below.
cp file_1 file_2
copies file_1 to file_2. The both files must be in the same working directory. If they are in
various directories, the path must be given. If you want to copy entire folder then you can use -R option
which means copy the source folder recursively.
[test@ns2 ~]$ cp -R /etc/ /home/test
In above example the entire contents of /etc folder will be copied to /home/test folder.
11. Rename and/or Move the File :
The mv command can be used to rename or move the file from current location to different one.
The command syntax is as below.
[test@ns2 ~]$ mv file_1 file_2
The mv moves file_1 to file_2. If both the files are in same working directory. If they are in
various directory then this command simply renames the file, but if they are in different folder then mv
command simply moves the files from source to destination.
12. Remove File :
The rm command can be used to remove / erase files from disk.The common syntax is give
below. You can also use wild cards to delete multiple / selective files.
The command syntax is as below.
[test@ns2 ~]$ rm file_a
removes the file_a from the system at all. If you use wildcard. For example
[test@ns2 ~]$ rm h*c
you will remove all files beginning with h and ending with c which are in working
directory.
If you write
[test@ns2 ~]$ rm *
you will erase all files from your working directory.

Magnum Net Solutions Pvt. Ltd., 25, Saikrupa Apt, Central Excise Colony, Chhatrapati Square, Nagpur 15
Magnum
9850332133
If you write
[test@ns2 ~]$ rm -i *
It will be done also but the system will ask for permission before removing each file.
The command
[test@ns2 ~]$ rm -r your_file
causes removing of the directory your_file even if this directory is not empty.
Attention!
Do not use such commands
[root@server1 ~]# rm -r /
This will erase all your directories (including not empty directories). If you were a system
administrator
13. Finding File :
The find command is used for finding files /folders on disk.The common syntax is give below.
You can add grep command to filter the output as below.
The command syntax is as below.
[root@server1 ~]# find path -name filename
For example, the command below looks passwd file in /etc folder.
The command below looks complete /etc folder and filters files containing quota word only
For more detailed options you can refer man page of this command as you can use regular
expressions syntax as well as wild card too.

Magnum Net Solutions Pvt. Ltd., 25, Saikrupa Apt, Central Excise Colony, Chhatrapati Square, Nagpur 15
Magnum
9850332133
14. Changing Directory :
cd is a command used to change directory from present one. Below are some examples of the
command
1. Change directory to /etc
[root@server1 ~]# cd /etc
[root@server1 etc]#
2. Move one folder behind present one.
[root@server1 xinetd.d]# cd ..
[root@server1 etc]#
3. Goto home folder from any location.
[root@server1 etc]# cd ~
[root@server1 ~]#
The ~ sign indicates home folder of the user. You can also find home folder as below.
[root@server1 ~]# echo $HOME
/root
[root@server1 ~]#
15. Making Directory :
mkdir is a command used to create directory. Below are some examples of the command
1. Let us create abc folder in present directory.
[root@server1 ~]# mkdir abc
2. Create abc xyz and pqr folder in one command.
[root@server1 ~]# mkdir abc pqr xyz
3. Create nested folder even if parent folder is missing the -p option can be used as below.
[test@server1 ~]$ mkdir -p 1/2/3/4/5/6/7/8/9/10
You can see the folder tree by tree command.
You can use -Z as well as -m option to set SE Linux and mode permissions.
Please refer info mkdir for more details.

Magnum Net Solutions Pvt. Ltd., 25, Saikrupa Apt, Central Excise Colony, Chhatrapati Square, Nagpur 15
Magnum
9850332133
16. Removing Directory :
rmdir is a command used to remove directory provided the directory should be empty. If the
folder is not empty then this command fails to remove the folder. You can use rm -rf command to
delete complete tree. rmdir command can also be used to remove multiple folders in one single com-
mand.
Some examples are
1. Let us remove abc folder in present directory.
[root@server1 ~]# rmdir abc
2. Remove abc xyz and pqr folder in one command.
[root@server1 ~]# rmdir abc xyz pqr
3. Remove nested folder say you want to remove the 10 th folder from 1/2/3/4/5/6/7/8/9/
10
[root@server1 ~]# rmdir 1/2/3/4/5/6/7/8/9/10
But make sure that 10 folder is empty.
17. The tree command :
tree is a recursive directory listing program that produces a depth indented listing of files.
Following example is self explanatory.

Magnum Net Solutions Pvt. Ltd., 25, Saikrupa Apt, Central Excise Colony, Chhatrapati Square, Nagpur 15
Magnum
9850332133
18. The chown Command :
chown is a command changes the user and/or group ownership of each given file.
If only an owner (a user name or numeric user ID) is given, that user is made the owner of
each given file, and the files group is not changed. If the owner is followed by a colon and a group
name (or numeric group ID), with no spaces between them, the group ownership of the files is changed
as well.
You can use -R option to change the owner of the files and directories recursively.
Some examples are
1. Let us change owner of install.log file from root to test
[root@server1 test]# chown test /home/test/install.log
[root@server1 test]# ll
total 32
-rw-r--r-- 1 test root 29101 Dec 10 15:04 install.log
[root@server1 test]#
2. The following command changes ownership of all files and folder in /home/test to test
[root@server1 test]# chown -R test /home/test
3. The command below make owner as test and group as www for all files in folder.
[root@server1 test]# chown -R test:www /home/test
19. The chgrp Command :
chgrp is a command changes the group of given file. The syntax is same as chown command.
Below is example. You can equally use the -R option as that of previous command.
The command below changes group of /etc/passwd as root.
[root@server1 test]# chgrp root /etc/passwd
20. The chmod Command :
chmod command is used to change the rwx permissions of the file. The syntax of the command
is as below.
# chmod [Binary Permissions Set] file / folder
You can use -R option as below to change the permissions recursively.
# chmod -R [Binary Permissions Set] file / folder

Magnum Net Solutions Pvt. Ltd., 25, Saikrupa Apt, Central Excise Colony, Chhatrapati Square, Nagpur 15
Magnum
9850332133
chmod command is used to change the rwx permissions of the file. The syntax of the command
is as below.
Let us say reading / writing / execution permission is on for owner. We can write
rwx ==> 111 ==> 7 (1 means On and 0 means Off)
rw- ==> 110 ==> 6
r w xPermission for others
r w xPermission for group
r w xPermission for owner
Octal Scale Binary Scale
0 000
1 001
2 010
3011
4 100
5 101
6110
6110
7 111
In above example the permissions are rwx rwx r-x We can say like this
111 111 101 ==> 7 7 5
Now we can use chmod like
# chmod 775 srs
With -R option
# chmod -R 775 srs
The first command simply changes the folder
permissions, but the -R option command changes per-
missions of all the files / folders in folder ss.
chmod never changes the permissions of symbolic links; the chmod system call cannot
change their permissions. This is not a problem since the permissions of symbolic links are never
used. For more information please read man page of the command using man chmod command.

Magnum Net Solutions Pvt. Ltd., 25, Saikrupa Apt, Central Excise Colony, Chhatrapati Square, Nagpur 15
Magnum
9850332133
21. Getting Help :
man command is used to get information of commands as well as configuration files. We can
use the command as below.
a] The command below shows information about useradd command.
[test@server1 ~]$ man useradd
b] The command below fetches Section 8 of this command from built in manual.
[test@server1 ~]$ man 8 useradd
You can also get information as below.
a] Short help : --help option
[test@server1 ~]$ useraddd --help
b] Help using info command
[test@server1 ~]$ info useradd
c] For complete listing of commands type only info or pinfo as below.
[test@server1 ~]$ info
[test@server1 ~]$ pinfo
22. The write command :
write command allows you to communicate with other users, by copying lines from your
terminal to theirs.We can use the command as below. Say user test wants to send message to root user.
Then we can, start session like given below.
At the same time the user root receives following message.

Magnum Net Solutions Pvt. Ltd., 25, Saikrupa Apt, Central Excise Colony, Chhatrapati Square, Nagpur 15
Magnum
9850332133
You can turn write command off by mesg command. Typing mesg command without option
tells the status of write command. Alternatively, you can use y or n option to switch the write command.
Below is screen shot of the command for better understanding.
23. The file command :
file command tells the exact type of the file. The extension does not matters here. Below is
sample output of command.
[test@server1 ~]$ file test.tar
test.tar: POSIX tar archive
[test@server1 ~]$
24. The stat command :
The stat command displays the complete information of the file as contained in inode of the
file. You can use the command as below.
25. The tar command :
The tar command is used for creating archive of files / folders. In short this command is used to
create a container of multiple file. The can be later on extracted at same location or different one. The
command is mainly used for taking backup of large file system. We can use the zip option with this
command also. Some examples are given here.

Magnum Net Solutions Pvt. Ltd., 25, Saikrupa Apt, Central Excise Colony, Chhatrapati Square, Nagpur 15
Magnum
9850332133
Let us create tar file srs.tar for folder srs located in current folder. The command is
[test@server1 ~]$ tar -cvf srs.tar srs/
srs/
[test@server1 ~]$
Where,
-c Create tar file, if not present in the disk.
-v Verbose mode, which shows the process.
-f Create the file forcefully.
This command then creates srs.tar file in the current folder as shown below.
Extracting tar file :
You can now extract the tar as give below. The -x option is used to extract the file.
[test@server1 ~]$ tar -xvf srs.tar
Where
-x Extract the tar file.
You can use following options
-z zip the tar file. Ex. : tar -cvzf abc/
-j bzip2 the tar file. Ex. : tar -xvjf abc.tar
(Note : The tar command retains the owner / groupship and file permissions intact.)

Magnum Net Solutions Pvt. Ltd., 25, Saikrupa Apt, Central Excise Colony, Chhatrapati Square, Nagpur 15
Magnum
9850332133
26. Terminate running command / program :
Use (usually) keystroke ctrl-c to terminate the program. You can check the status of program by
typing echo $? on command prompt. If it shows 0 then execution is successful else it indicates abnor-
mal termination of the program.
If you are pressing ^C then the status code will be other than 0.
27. Leaving the system :
It depends on the system. Usually by ctrl-d but in a lot of systems you must use a special
commands
logout
exit
28. Changing password of your account :
You can change password of you account by using passwd command. The System Administra-
tor root can change password of any account.
As a Normal User :
As a root User :

Magnum Net Solutions Pvt. Ltd., 25, Saikrupa Apt, Central Excise Colony, Chhatrapati Square, Nagpur 15
Magnum
9850332133
29. User Password Expiry Information :
A normal user can view its account details by chage command, but he can not change the
information. root user can change account information of any user. Below are examples.
Following example displays the user account details. The -l option is used.
Following example shows how root user can change account details of user test.. The -l option
is not used here.
30. User Resource Limit Information :
There are two type of resource limitations. First is soft limit and another is hard limit. User can
not cross the hard limit but when he crossses the soft limit, system issues warning message to him. One
can view the resource (CPU, Memory, Files etc.) limits as below.
Soft Limit : [test@server1 ~]$ ulimit -Sa
Hard Limit : [test@server1 ~]$ ulimit -Ha