OS Exp
OS Exp
Experiment 1:
Aim:Explore the internal commands of linux
1. Ls
Purpose:The command is used in listing contents inside a directory and is one of the few
commands beginners learn from the onset.
A.Open Last Edited File Using ls -t
student@LAB306PC29:~$ ls
Desktop Documents Downloads haha hahaha hello kana Kapil Music Pictures Public
TASM Templates Videos xyz
student@LAB306PC29:~$ ls -l
total 56
drwxr-xr-x 2 student student 4096 Jan 17 16:24 Desktop
drwxr-xr-x 2 student student 4096 Dec 13 14:31 Documents
drwxr-xr-x 2 student student 4096 Jan 16 10:41 Downloads
-rw-rw-r-- 1 student student 19 Jan 18 15:15 jg
-rw-rw-r-- 1 student student 26 Jan 18 15:14 Jitesh
-rw-rw-r-- 1 student student 556 Jan 17 14:27 kana
drwxrwxr-x 2 student student 4096 Jan 17 15:23 Kapil
drwxr-xr-x 2 student student 4096 Dec 13 14:31 Music
drwxr-xr-x 2 student student 4096 Dec 13 14:31 Pictures
drwxr-xr-x 2 student student 4096 Dec 13 14:31 Public
drwxr-xr-x 8 student student 4096 Dec 14 15:29 TASM
drwxr-xr-x 2 student student 4096 Dec 13 14:31 Templates
drwxr-xr-x 2 student student 4096 Dec 13 14:31 Videos
-rw-rw-r-- 1 student student 17 Jan 17 14:30 xyz
C.The ls command in linux is used for listing out all the files and directories within a
directory
$ls -al
student@LAB306PC29:~$ ls -al
total 196
drwxr-x--- 21 student student 4096 Jan 18 15:20 .
drwxr-xr-x 5 root root 4096 Dec 14 15:28 ..
-rw------- 1 student student 2171 Jan 17 16:36 .bash_history
-rw-r--r-- 1 student student 220 Dec 13 14:31 .bash_logout
-rw-r--r-- 1 student student 3771 Dec 13 14:31 .bashrc
drwx------ 10 student student 4096 Jan 16 10:34 .cache
drwxrwxr-x 4 student student 4096 Dec 13 14:32 .cinnamon
drwxr-xr-x 18 student student 4096 Jan 17 14:32 .config
drwxr-xr-x 2 student student 4096 Jan 17 16:24 Desktop
-rw-r--r-- 1 student student 27 Dec 13 14:31 .dmrc
drwxr-xr-x 2 student student 4096 Dec 13 14:31 Documents
drwx------ 2 student student 4096 Dec 14 15:32 .dosbox
drwxr-xr-x 2 student student 4096 Jan 16 10:41 Downloads
-rw-r--r-- 1 student student 22 Dec 13 14:31 .gtkrc-2.0
-rw-r--r-- 1 student student 516 Dec 13 14:31 .gtkrc-xfce
-rw-rw-r-- 1 student student 6 Jan 18 15:20 hello
-rw-rw-r-- 1 student student 7 Jan 18 15:19 hey
-rw-rw-r-- 1 student student 19 Jan 18 15:15 jg
-rw-rw-r-- 1 student student 26 Jan 18 15:14 Jitesh
-rw-rw-r-- 1 student student 556 Jan 17 14:27 kana
drwxrwxr-x 2 student student 4096 Jan 17 15:23 Kapil
-rw------- 1 student student 20 Jan 18 15:13 .lesshst
drwxrwxr-x 4 student student 4096 Jan 17 16:34 .linuxmint
drwxrwxr-x 3 student student 4096 Dec 13 14:31 .local
drwx------ 4 student student 4096 Jan 16 10:34 .mozilla
drwxr-xr-x 2 student student 4096 Dec 13 14:31 Music
drwx------ 3 student student 4096 Dec 14 15:30 .mysql
drwxr-xr-x 2 student student 4096 Dec 13 14:31 Pictures
-rw-r--r-- 1 student student 807 Dec 13 14:31 .profile
drwxr-xr-x 2 student student 4096 Dec 13 14:31 Public
-rw-r--r-- 1 student student 0 Dec 14 15:30 .sudo_as_admin_successful
drwxr-xr-x 8 student student 4096 Dec 14 15:29 TASM
drwxr-xr-x 2 student student 4096 Dec 13 14:31 Templates
drwxr-xr-x 2 student student 4096 Dec 13 14:32 .themes
drwxr-xr-x 2 student student 4096 Dec 13 14:31 Videos
-rw------- 1 student student 55 Jan 18 15:13 .Xauthority
-rw------- 1 student student 9065 Jan 18 15:25 .xsession-errors
-rw------- 1 student student 33583 Jan 17 16:38 .xsession-errors.old
-rw-rw-r-- 1 student student 17 Jan 17 14:30 xyz
ls -lt : To sort the file names displayed in the order of last modification time.You will be finding
it handy to use it in combination with -l option
student@LAB306PC29:~$ ls -lt
total 64
-rw-rw-r-- 1 student student 6 Jan 18 15:20 hello
-rw-rw-r-- 1 student student 7 Jan 18 15:19 hey
-rw-rw-r-- 1 student student 19 Jan 18 15:15 jg
-rw-rw-r-- 1 student student 26 Jan 18 15:14 Jitesh
drwxr-xr-x 2 student student 4096 Jan 17 16:24 Desktop
drwxrwxr-x 2 student student 4096 Jan 17 15:23 Kapil
-rw-rw-r-- 1 student student 17 Jan 17 14:30 xyz
-rw-rw-r-- 1 student student 556 Jan 17 14:27 kana
drwxr-xr-x 2 student student 4096 Jan 16 10:41 Downloads
drwxr-xr-x 8 student student 4096 Dec 14 15:29 TASM
drwxr-xr-x 2 student student 4096 Dec 13 14:31 Documents
drwxr-xr-x 2 student student 4096 Dec 13 14:31 Music
drwxr-xr-x 2 student student 4096 Dec 13 14:31 Pictures
drwxr-xr-x 2 student student 4096 Dec 13 14:31 Public
drwxr-xr-x 2 student student 4096 Dec 13 14:31 Templates
drwxr-xr-x 2 student student 4096 Dec 13 14:31 Videos
student@LAB306PC29:~$ ls *h
Jitesh
student@LAB306PC29:~$ ls h*
hello hey
student@LAB306PC29:~$ ls [h-j]*
hello hey jg
Sometimes you may want to know the inone number of a file for internal maintenance. Use -i
option as shown below to display inone number. Using inode number you can remove files
that has special characters in it’s name.
$ ls -i
student@LAB306PC29:~$ ls -i
14550027 Desktop 14550029 Downloads 14557166 hey 14550924 Jitesh 14680077
Kapil 14550035 Pictures 14550191 TASM 14550036 Videos
14550033 Documents 14557252 hello 14556915 jg 14550930 kana 14550034 Music
14550032 Public 14550031 Templates 14550464 xyz
2.Mkdir
Purpose:The mkdir stands for 'make directory'. With the help of mkdir command, you can
create a new directory wherever you want in your system. Just type "mkdir <dir name> , in
place of <dir name> type the name of new directory, you want to create and then press
enter.
student@LAB306PC29:~$ cd haha
student@LAB306PC29:~/haha$
4.rmdir
Purpose:rmdir command is used remove empty directories from the filesystem in Linux. The
rmdir command removes each and every directory specified in the command line only if
these directories are empty
5.Cat
Purpose:Cat(concatenate) command is very frequently used in Linux. It reads data from the
file and gives their content as output
6.rm
Purpose:rm stands for remove here. rm command is used to remove objects such as files,
directories, symbolic links and so on from the file system like UNIX. To be more precise, rm
removes references to objects from the filesystem, where those objects might have had
multiple references
student@LAB306PC29:~$ rm -i Jitesh
rm: remove regular file 'Jitesh'? y
student@LAB306PC29:~$ ls
Desktop Documents Downloads haha hahaha hello kana Kapil Music Pictures Public
TASM Templates Videos xyz
$rm -r filename : It will ask delete a Directory using recursive calls
student@LAB306PC29:~$ rm -r hahaha
student@LAB306PC29:~$ ls
Desktop Documents Downloads haha hello kana Kapil Music Pictures Public TASM
Templates Videos xyz
7.mv
Purpose :mv stands for move. mv is used to move one or more files or directories from one
place to another in a file system
8.cp
Purpose :cp stands for copy. This command is used to copy files or group of files or
directory. It creates an exact image of a file on a disk with different file name. cp command
require at least two filenames in its arguments.
9.head
Purpose:. The head command, as the name implies, print the top N number of data of the
given input. By default, it prints the first 10 lines of the specified files. If more than one file
name is provided then data from each file is preceded by its file name.
10.tail
Purpose :The tail command, as the name implies, print the last N number of data of the
given input. By default it prints the last 10 lines of the specified files. If more than one file
name is provided then data from each file is precedes by its file name
11.sort
Purpose :SORT command is used to sort a file, arranging the records in a particular order.
By default, the sort command sorts file assuming the contents are ASCII. Using options in
the sort command can also be used to sort numerically
12.wc
Purpose :wc stands for word count. As the name implies, it is mainly used for counting
purpose.
It is used to find out number of lines, word count, byte and characters count in the files
specified in the file arguments.
student@LAB306PC29:~$ wc -l hel
13 hel
student@LAB306PC29:~$ wc -w hel
15 hel
student@LAB306PC29:~$ wc -c hel
75 hel
13. chown
Purpose:The chown command changes the owner of the file or directory specified by the
File or Directory parameter to the user specified by the Owner parameter. The value of the
Owner parameter can be a user name from the user database or a numeric user ID
14.chmod
Purpose:The chmod command in Linux is used to change the permissions of a file or
directory. The syntax for the chmod command is as follows:
Here, MODE can be specified using either numeric or symbolic notation. The chmod
command does not have an option to specify the user directly. The user must have sufficient
privileges to change the permissions of a file, typically by being the owner of the file or
having superuser permissions.
chmod u+rw hel This will give user to write and read access for file hel
15.chgrp
Purpose:The chgrp command in Linux is used to change the group ownership of a file or
directory. The syntax for the chgrp command is as follows:
chgrp [OPTIONS] Group FileName : Group is the name of owner which we want to be of
that file
16.ps
Purpose: ps stands for “Process Status”. ps command is used to list the currently running
processes and their PIDs along with some other information depends on different options. It
reads the process information from the virtual files in /proc file-system. /proc contains virtual
files, this is the reason it’s referred as a virtual file system
jitesh@ubuntu:~$ ps
PID TTY TIME CMD
4242 pts/0 00:00:00 bash
5495 pts/0 00:00:00 ps
17.umask
Purpose:The chown command changes the owner of the file or directory specified by the
File or Directory parameter to the user specified by the Owner parameter. The value of the
Owner parameter can be a user name from the user database or a numeric user ID
student@LAB306PC29:~$ umask
0002
19.pipe
Purpose:Pipe is used to combine two or more commands, and in this, the output of one
command acts as input to another command, and this command's output may act as input to
the next command and so on. It can also be visualized as a temporary connection between
two or more commands/ programs/ processes.
$ ls command1 | command2
Output Redirection:
The ‘>‘ symbol is used for output (STDOUT) redirection
Input redirection:
The ‘<‘ symbol is used for input(STDIN) redirection
Combining redirections:
The following example combines input and output redirection. The file text.txt is first checked
for spelling mistakes, and the output is redirected to an error log file:
spell < text.txt > error.log
D.Display current shell, home directory, operating system type, current path setting,
current working directory
jitesh@ubuntu:~$ uname -r
5.11.0-38-generic