0% found this document useful (0 votes)
13 views11 pages

OS Exp

Uploaded by

viyege2108
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views11 pages

OS Exp

Uploaded by

viyege2108
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Operating Systems

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

B. Display All Information About Files/Directories Using ls -l

$ ls -l : To show long listing information about the file/directory.

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

D.Order Files Based on Last Modified Time Using ls -lt

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

E.To list Files containing specific Alphabets

$ ls *h To list file name containing ‘h’


$ ls h* To list File name starting with ‘h’
ls [h-j]* to list file names starting with H to J

student@LAB306PC29:~$ ls *h
Jitesh
student@LAB306PC29:~$ ls h*
hello hey
student@LAB306PC29:~$ ls [h-j]*
hello hey jg

F. Display File Inode Number Using ls -i

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:~$ mkdir haha


student@LAB306PC29:~$ mkdir hahaha
student@LAB306PC29:~$ ls
Desktop Documents Downloads haha hahaha hello hey jg Jitesh kana Kapil Music
Pictures Public TASM Templates Videos xyz
3.chdir
Purpose:The chdir command is a system function (system call) which is used to change the
current working directory. On some systems, this command is used as an alias for the shell
command cd. chdir changes the current working directory of the calling process to the
directory specified in path.

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

student@LAB306PC29:~$ rmdir haha


rmdir: failed to remove 'haha': Directory not 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

student@LAB306PC29:~$ cat Jitesh


hello this is first pract
student@LAB306PC29:~$ cat > jg
hellllllloooooooooostudent@LAB306PC29:~$
student@LAB306PC29:~$ ls
Desktop Documents Downloads jg Jitesh kana Kapil Music Pictures Public TASM
Templates Videos xyz

A. To view multiple files


$ cat fileName1 Filename2
B.Copy the contents of one file to another file.
Command:
$cat [filename of source] > [destination-filename]

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

$rm -i filename : It will ask before deletion for a File

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

$mv fileName SourceDestination

student@LAB306PC29:~$ mv hey jg /home/student/hahaha


student@LAB306PC29:~$ cd hahaha
student@LAB306PC29:~/hahaha$ ls
haha hey jg ohoh

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.

cp -i filename Destination : it will ask for confirmation to Overwrite

student@LAB306PC29:~/haha$ cp -i HHAHAHAHAH hahaah


cp: overwrite 'hahaah'? y

cp -r Directory_to be copied Destination_directory : it will copy all files of one directory to


another

student@LAB306PC29:~$ cp -r haha hahaha


student@LAB306PC29:~$ cd hahaha
student@LAB306PC29:~/hahaha$ ls
haha

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.

student@LAB306PC29:~$ cat > hel


hello
one
day
i
will
be
nice
to myself
and
to others
food
was
great
student@LAB306PC29:~$ head hel
hello
one
day
i
will
be
nice
to myself
and
to others

$head -n(Number_of_lines) FileName : to see number of lines of the file

student@LAB306PC29:~$ head -5 hel


hello
one
day
i
will

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

student@LAB306PC29:~$ tail hel


i
will
be
nice
to myself
and
to others
food
was
great

$ tail -n(number of lines) tail : To display last N lines

student@LAB306PC29:~$ tail -2 hel


was
great

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

student@LAB306PC29:~$ sort hel


and
be
day
food
great
hello
i
nice
one
to myself
to others
was
will

$ sort -r FileName :To reverse Sort the file

student@LAB306PC29:~$ sort -r hel


will
was
to others
to myself
one
nice
i
hello
great
food
day
be
and

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:~$ sort -r hel


will
was
to others
to myself
one
nice
i
hello
great
food
day
be
and
student@LAB306PC29:~$ wc hel
13 15 75 hel

$ wc -l hel :Prints Only number of lines

student@LAB306PC29:~$ wc -l hel
13 hel

$ wc -w hel :Prints Only number of words

student@LAB306PC29:~$ wc -w hel
15 hel

$ wc -c hel :Prints Only number of BYTES

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

jitesh@ubuntu:~$chown jitesh hel

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:

jitesh@ubuntu:~$ chmod [OPTIONS] MODE FILE

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

jitesh@ubuntu:~$ chgrp jitesh hel

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

jitesh@ubuntu:~$ cat hel | sort


and
be
day
food
great
hello
i
nice
one
to myself
to others
19.Redirection Operators

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

The >> operator:


Instead of overwriting file data, you can also append text to an existing file using two
subsequent greater-than signs:

jitesh@ubuntu:~> cat capJ


Hello this is J
jitesh@ubuntu:~> date >> capJ
jitesh@ubuntu:~> cat capJ
Hello this is J
Tue Jan 31 20:23:07 IST 2023

20.Explore commands for following:

A. Display top 10 processes in descending order

tsec2@ubuntu:~$ ps -eo pid,ppid,%mem,%cpu --sort=%mem | head -n 10


PID PPID %MEM %CPU
2 0 0.0 0.0
3 2 0.0 0.0
4 2 0.0 0.0
6 2 0.0 0.0
7 2 0.0 0.0
8 2 0.0 0.0
9 2 0.0 0.0
10 2 0.0 0.0
11 2 0.0 0.0

B.Display the process with highest memory usage

tsec2@ubuntu:~$ ps -eo %cpu,%mem,cmd --sort=-%cpu | head


%CPU %MEM CMD

C.Display current user logged in and logname


tsec2@ubuntu:~$ echo "Your logname is :$(echo $LOGNAME)"
Your logname is :tsec2
tsec2@ubuntu:~$ echo "Your username is :$(echo $USER)"
Your username is :tsec2

D.Display current shell, home directory, operating system type, current path setting,
current working directory

tsec2@ubuntu:~$ echo "Current shell is :$echo ($SHELL)"


Current shell is : (/bin/bash)
tsec2@ubuntu:~$ echo "Current home directory is :$echo($HOME)"
Current home directory is :(/home/tsec2)
tsec2@ubuntu:~$ echo "Current working directory is :$echo($PWD)"
Current working directory is :(/home/tsec2)

E.Display OS version, release number, kernel version.

jitesh@ubuntu:~$ uname -r
5.11.0-38-generic

You might also like