Operating System (Lab Manual) : Department of Computer Science COMSATS University Islamabad, Vehari
Operating System (Lab Manual) : Department of Computer Science COMSATS University Islamabad, Vehari
The Linux file system is the structure in which all the information on your computer is stored.
Files are organized within a hierarchy of directories. Each directory can contain files, as well
as other directories.
If you were to map out the files and directories in Linux, it would look like an upside-down
tree. At the top is the root directory, which is represented by a single slash ( / ). Below that is
a set of common directories in the Linux system, such as bin, dev, home, lib , and tmp , to
name a few. Each of those directories, as well as directories added to the root, can contain
subdirectories.
Some of the Linux directories that may interest you include the following:
• /bin - Contains common Linux user commands, such as ls, sort , date , and chmod .
/boot - Has the bootable Linux kernel and boot loader configuration files
(GRUB).
• /dev - Contains files representing access points to devices on your systems. These
include terminal devices ( tty* ), floppy disks ( fd* ), hard disks ( hd* or sc* ), RAM (
ram* ), and CD-ROM ( cd* ). (Applications normally access these devices directly
through the device files, but end users rarely access them directly.)
/etc - Contains administrative configuration files.
• /home - Contains directories assigned to each user with a login account.
• /media - Provides a location for mounting devices, such as remote file systems and
removable media (with directory names of cdrom , floppy , and so on). In Fedora and
RHEL, many removable media are mounted automatically in this directory when the
media is inserted (CD or DVD) or connected (USB pen drives or cameras ).
• /proc - Provides a mechanism for the kernel to send information to processes.
• /root - Represents the root user's home directory.
• /sbin - Contains administrative commands and daemon processes.
• /sys - A /proc -like file system, added with the Linux 2.6 kernel and intended to
contain files for getting hardware status and reflecting the system's device tree as it is
seen by the kernel. It pulls many of its functions from /proc .
• /tmp - Contains temporary files used by applications.
• /usr - Contains user documentation, games , graphical files (X11), libraries (lib), and a
variety of other user and administrative commands and files.
• /var - Contains directories of data used by various applications. In particular, this is
where you would place files that you share as an FTP server ( /var/ftp ) or a Web
server ( /var/www ). It also contains all system log files ( /var/log ). In time, FTP,
HTTP, and similar services will move to the /srv directory to adhere to the Linux
Standards Base ( www.freestandards.org/spec ).
COMMAND:
1: Date Command:
This command is used to display the current data and time.
Syntax:
$date
An operand with a leading plus (+) sign signals a user-defined format string which specifies
the format in which to display the date and time. The following examples are tested on
GNU/Linux, Apple OS X Unix, and FreeBSD unix operating system.
a = Abbreviated weekday.
A= Full weekday.
b= Abbreviated month.
B= Full month.
c= Current day and time.
C= Display the century as a decimal number.
d= Day of the month. D= Day in „mm/dd/yy‟
format h= Abbreviated month day.
H= Display the hour.
L=Day of the year.
m=Month of the year.
M=Minute.
P=Display AM or PM
S=Seconds
T=HH:MM:SS format
u=Week of the year. y=Display
the year in 2 digit.
Y=Display the full year.
Z=Time zone .
2. Calendar Command:
This command is used to display the calendar of the year or the particular month of calendar
year.
Syntax:
a) $cal
b) $cal <year>
c) $cal <month> <year>
Here the first syntax gives the calendar of current month and command b shoes entire
calendar for given year & the third Syntax gives the calendar of reserved month of that year.
3. Echo Command:
echo is one of the most commonly and widely used built-in command for Linux bash and C
shells, that typically used in scripting language and batch files to display a line of text/string
on standard output or a file. This command is used to print the arguments on the screen.
Syntax:
$echo <text>
a) Input a line of text and display on standard output Syntax:
$echo <string>
b) Declare a variable and echo its value. For example, Declare a variable of x and assign
its value=10 Syntax:
x=10
$echo the value of variable x= $x
c) Using option ‘\b‘– backspace with backslash interpreter ‘-e‘ which removes all the
spaces in between.
Note: The ‘-e‘ option in Linux acts as interpretation of escaped characters that are
back slashed.
Syntax:
$ echo -e “we \b are \b learning \b Linux \b commands”
d) Using option ‘\n‘ – New line with backspace interpreter ‘-e‘ treats new line from
where it is used.
Syntax:
$ echo -e “we \n are \n learning \n Linux \n commands”
e) Using option ‘\t‘ – horizontal tab with backspace interpreter ‘-e‘ to have horizontal
tab spaces.
Syntax:
$ echo -e “we \t are \t learning \t Linux \t commands”
f) How about using option new Line ‘\n‘ and horizontal tab ‘\t‘ simultaneously. Syntax:
$ echo -e “we \n \t are \n \t learning \n \t Linux \n \t commands”
g) Using option ‘\v‘ – vertical tab with backspace interpreter ‘-e‘ to have vertical tab
spaces.
Syntax:
$ echo -e “we \v are \v learning \v Linux \v commands”
Exercise
Question: How about using option new Line and vertical tab simultaneously.
Syntax:
h) Print all the files/folder using echo command (ls command alternative).
Syntax:
$ echo *
4. Banner Command:
Banner command in Linux is used to print the ASCII character string in large letter to
standard output. It is used to display the arguments in „#‟ symbol.
Syntax:
$banner <arguments> Example
1: Printing “1234567890” in large letters. Syntax:
$banner 1234567890
Example 2: Printing “GeeksforGeeks” in large letters. There are two things:
• First, all the letter will be displayed in Capital letters in standard output.
• Second, only “GEEKSFORGE” will be printed as banner has a default capacity of 10
characters in a word. After that, you have to give space which is shown in further
examples.
Syntax:
$banner GeeksforGeeks
5.’who’ Command:
It is used to display who are the users connected to our computer currently.
Example 1: The “who” command displays the following information for each user currently
logged in to the system if no option is provided.
Syntax:
$who
$who <options>
Syntax:
$who -H
Example 3: To show the last booting date or time or when the system was lastely rebooted.
Syntax:
$who -b
6. ’who am i’ Command:
7. ’CLEAR’ Command:
Syntax:
$clear
8. ’MAN’ Command:
It help us to know about the particular command and its options & working. It is like “help‟
command in windows.
Syntax:
$man <command name>
9. LIST Command:
Syntax:
$ls
$ls – options <arguments>
If the command does not contain any argument means it is working in the Current directory.
Options:
a– used to list all the files including the hidden files.
c– list all the files column wise. d-
list all the directories. m- list the files
separated by commas.
p- list files include „/‟ to all the directories.
r- list the files in reverse alphabetical order.
f- list the files based on the list modification date.
x- list in column wise sorted order.
Syntax:
$pwd
CD Command:
Syntax:
$cd <directory name>
Example 1. Change from current directory to /usr/local.
Syntax:
$ cd /usr/local
Example 2. Change from current directory to /usr/local/lib using absolute path.
Syntax:
$ cd /usr/local/lib
Example 3. Change from current working directory to /usr/local/lib using relative
path.
Syntax:
:/usr/local$ cd lib
Example 4. (a) Switch back to previous directory where you working earlier.
Syntax:
:/usr/local/lib$ cd –
(b) Change Current directory to parent directory.
Syntax:
:/usr/local/lib$ cd ..
CREATE A FILE:
To create a new file in the current directory we use CAT command.
DISPLAY A FILE:
To display the content of file mentioned we use CAT command without „>‟ operator.
To copy the content of one file with another. If file does not exist, a new file is created and if
the file exists with some data then it is overwritten.
Syntax:
$cat filename source>> destination filename
Syntax:
$cat file1 | more
$cat file2 | less
Syntax:
$cat -T test
Syntax:
$cat test test1 test2 test3 | sort > test4
MOVE Command :
To completely move the contents from source file to destination file and to remove the
source file.
Syntax:
$mv <source filename> <destination filename>
REMOVE Command :
To permanently remove the file we use this command.
Syntax:
$rm <filename>
WORD Command :
To list the content count of no of lines, words, characters.
Syntax:
$wc<filename>
Options :
-c – to display no of characters.
-l – to display only the lines.
-w – to display the no of words.
Home Assignment 1: