163 Os Week-1
163 Os Week-1
… Date:…
02/07/2024……
OPERATING SYSTEMS
ASSIGNMENT-1
TASK-1
3) Ls (List Directory Contents) : This lists the files and directories in the current directory.
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
12) Paste : to merge lines of files horizontally (parallel merging). It can be very useful for
joining data from multiple files.
13) Head command: to display the beginning of a file. By default, it shows the first 10 lines
of a file, but you can adjust the number of lines displayed using various options.
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
15) Date command : to display or set the system date and time.
16) grep command: is used for searching text using patterns.It stands for "Global Regular
Expression Print" and is commonly used to search through files or command output for lines
that match a specified pattern.
17) touch command: to create empty files or update the timestamps of existing files.
18) Chmod command: change the permissions of files and directories. Permissions control
who can read, write, or execute a file. chmod can be used with symbolic or octal notation to
set these permissions.
Grant Execute Permission to the Owner Remove Write Permission from the Group
19) Man command: to display the manual pages for other commands and programs.
20) Clear command: clear the terminal screen of all previous commands and output.
21) Ln command: to create links between files. There are two types of links: hard links and
symbolic (or soft) links.
22) Mount command: to attach filesystems to the filesystem hierarchy. This allows access to
the contents of the filesystem at a specific directory (the mount point). The umount command
is used to detach filesystems.
23) Umount command: unmount filesystems that have been previously mounted using the
mount command.
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
3) Kill command : to send signals to processes.You can use kill to stop or restart processes,
among other tasks, by specifying different signals.
4) Nice command : to start a process with a modified scheduling priority. This can affect
how the CPU time is allocated to the process, which is useful for managing system load and
performance.
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
4) Nslookup command: to query Domain Name System (DNS) to obtain domain name or IP
address mapping information.
5) Telnet command : to connect to remote hosts using the Telnet protocol. It allows you to
interact with remote servers and services via a text-based interface.
6) Traceroute command: to trace the path that packets take from your machine to a
specified destination.
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
TASK-2
AIM : Explore the Linux/Unix vi editor and its features.
Aim: To identify the Linux/Unix systems directory structure and files Subsystem like
/proc ,/bin,/ lib, /etc
DESCRIPTION : vi operates in three modes: Normal (for navigation and commands), Insert
(for text entry), and Command-Line (for executing commands). Key commands include
navigating with h, j, k, l, editing text with i or a, and saving with :w or quitting with :q.
Advanced features include searching with /searchterm, replacing text with :s/old/new/, and
using Visual Mode (v or V) for text selection. Practice by opening a file with vi filename,
editing text, and saving changes.
TASK-1: Write about Linux directory structures specifications
1. (Root Directory): The top-level directory from which all other directories branch. It
contains the entire filesystem hierarchy.
2. /bin: Contains essential command binaries needed for basic system functionality and
single-user mode (e.g., ls, cp, rm).
3. /boot: Stores the bootloader files and the Linux kernel, which are necessary for system
booting.
4./dev: Contains device files that represent hardware devices (e.g., /dev/sda for disks).
5./etc: Holds system configuration files and directories for system-wide settings (e.g.,
/etc/fstab, /etc/hostname).
6./home: Contains user directories where individual user files and personal settings are stored
(e.g., /home/user1).
7. /lib: Contains essential shared libraries required by system programs and kernel modules.
8./media: Mount point for removable media (e.g., USB drives, CD-ROMs).
9./mnt: Traditional mount point for temporary filesystems and devices. Often used for
manually mounting filesystems.
10./opt: Used for optional software and third-party applications installed on the system.
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
11./proc: Virtual filesystem providing information about system processes and kernel
parameters (e.g., /proc/cpuinfo).
12./root: Home directory for the root user, distinct from /home and used for root’s personal
files.
13./run: Stores runtime data and system information, such as process IDs and system state,
which are needed while the system is running.
14./srv: Contains data for services provided by the system, such as web servers and FTP
servers.
15./sys: Virtual filesystem exposing kernel and hardware information, often used for system
management and debugging.
16./tmp: Holds temporary files created by system and user processes. Files in this directory
are often cleared on reboot.
17./usr: Contains user-related programs and data. It’s further divided into subdirectories like
/usr/bin for user binaries and /usr/lib for libraries.
18./var: Stores variable data files, such as log files (/var/log), mail spools (/var/mail), and
transient files.
Summary
The Linux directory structure provides a consistent and organized way to manage files and
system resources. Each directory has a specific purpose, from holding system configuration
files and binaries to storing user data and temporary files. Understanding these directories
helps in effective system administration and navigation.
TASK-2: What does the /proc folder consist. With a C program demonstrate how
operating system allocates the process resources in the form of file descriptors with help
of a program.
Contents of /proc
/proc/[pid]: Contains information about a specific process with the process ID pid.
This directory includes files such as cmdline, fd, status, and stat that provide details
about the process's status, memory usage, and file descriptors.
/proc/cpuinfo: Displays information about the CPU architecture, including processor
type and features.
/proc/meminfo: Shows detailed memory usage statistics, including total and available
memory.
/proc/uptime: Contains the system uptime and the amount of time the system has
spent in idle mode.
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
Here’s a simple C program that opens a file, writes to it, and then prints out the file
TASK-3: Identify and note down the system calls used by application to interact with
hard ware. Write down a short note on what is a System call and list out all system calls.
System Call : A system call is a request from a user-space application to the kernel for
performing operations that require privileged access. It acts as a bridge between user
applications and the core functionalities of the operating system. System calls are used to
request services such as:
System calls ensure that user applications do not directly access hardware, which helps
maintain system stability and security.
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
System calls vary between different Unix-like operating systems, but common system calls
across many systems include those listed above. To see a complete list of system calls on a
specific system, you can refer to the system's documentation or use tools like man pages.
For Linux systems, you can view system calls using the following commands:
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
TASK-3
DESCRIPTION: Operating system is an interface between the user and computer hardware.
It provides an environment to the user to run their programs in a convenient and efficient
manner. It also provides services to the programmers in the form of APIs or system calls.
a) Use the ‘ls’ without any arguments to display your current direcory contents. How many
files do you have?
b) Use ‘ls’ with -a option. How many files do you have? What is the difference you find?
Ans : The -a option shows all files, including hidden files (those starting with a dot .).
c) Use ‘ls’ with -F option. What is the difference between the output of task1 the current
task?
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
Ans : The -F option appends a character to each entry to indicate the type of file (e.g., / for
directories, * for executables).
Difference: ls by default omits hidden files, while ls -a includes them. Hidden files are
typically configuration files or directories used by applications.
d) Use the option -l (long listing). Check your output. How many columns are there?
What are those columns?
Columns:
1. File permissions
2. Number of links
3. Owner
4. Group
5. File size
6. Last modification date and time
7. File name
e) -R option is useful in several cases. Use the options -R and -Rl. What does the output
tells?
Description: The -R option lists directories and their contents recursively.The -Rl option
combines recursive listing with the long format, providing detailed information about files
and directories at all levels.
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
g) $ls -lFa
a) notice the ‘more’ prompt at the bottom of the page. Try pressing the return key,
space bar and the letter ‘b’ , latter ‘q’ and obseve the output for each key action.
The more command is used for viewing the contents of a file one screen at a time, allowing
for easier navigation through long text files.
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
b) use the search forward feature to find a word say “cse” with the Command /cse
This command searches forward from the current position in the file for the term "cse". The
cursor will move to the first occurrence of the term. You can press n to find the next
occurrence.
This command searches backward from the current position in the file for the term "CBIT".
The cursor will move to the first occurrence of the term found backward from the current
position. You can press n to find the previous occurrence.
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
a) Try the Command: $head -10 <filename>. How many lines are disayed this
time?
-10: Specifies that you want to display the first 10 lines of the file <filename>.
-8: Specifies that you want to display the last 8 lines of the file x.c.
Comments:
This command will output the last 8 lines of the file x.c. If the file has fewer than 8
lines, it will display all the lines in the file.
The tail -8 option is useful when you need to quickly review the most recent lines of a
file, especially in log files or output files where recent changes are more relevant.
If x.c does not exist or is empty, tail will provide an error message or display nothing.
5.check the man page of cat and try with the following Commands $cat file1; $cat file1
file2; $cat file1 file2 >file3; $cat file1 file2 >>file3. Write your observations for
the resonse of each attempt.
1. $ cat file1
Description: Displays the contents of file1 on the terminal. If file1 contains text, it will be
printed to the screen.
Observations:
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
Description: Concatenates the contents of file1 and file2 and displays them on the terminal,
one after the other.
Observations:
The contents of file1 are displayed first, followed immediately by the contents of
file2.
If either file1 or file2 does not exist, cat will display an error for the missing file and
continue with the existing files.
Description: Concatenates file1 and file2 and writes the combined output to file3. If file3
already exists, its contents will be overwritten.
Observations:
The contents of file1 and file2 are written to file3, with file3 being created if it does
not already exist.
If file3 exists, its previous content will be replaced with the new data.
The > operator is used for redirection, which means the output of cat is redirected to
file3.
Description: Concatenates file1 and file2 and appends the combined output to the end of
file3. If file3 does not exist, it will be created.
Observations:
The contents of file1 and file2 are appended to the end of file3.
If file3 does not exist, it will be created.
If file3 exists, the new content will be zdded after the existing content without
overwriting it.
a) Try the Command cp file1 file2. Copy a file from a different directory to your
current directory. ex. $cp /etc/passwd <ENTER>; use the cmmand $ls
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
Here, /etc/passwd is the source file, and . (dot) represents the current directory.
Explanation:
This command copies the file /etc/passwd from the /etc directory to your current
working directory.
b) use the Command cp -R <subdir1> <subdir2>; check with ls. Write your
comments
Comments:
a) Try the Command $mv x.c y.c; check with ls Command and write your comments.
This command renames (or moves) the file x.c to y.c. If y.c is in a different directory,
x.c will be moved to that directory with the new name.
The -i (interactive) option prompts you before overwriting an existing file. If y.c
already exists, you will be asked to confirm whether you want to replace it.
Comments:
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
8. check the man page of ‘rm’ Command. Try with some examples and write your
observations. Also try with -R option. Write your observations
This command deletes the file named file.txt from the current directory.
Observation:
The file file.txt will be removed immediately without any prompt or confirmation.
Warning: Deleted files using rm are not moved to a trash or recycle bin; they are
permanently removed from the file system.
The -i option makes rm interactive, prompting you to confirm the deletion of each
file.
Observation:
When using rm -i, you will be asked for confirmation before the file is deleted. You
will see a prompt like rm: remove regular file 'file.txt'?, and you can answer y (yes) or
n (no).
This provides a safeguard against accidental file deletions.
The -f (force) option forces the removal of files without prompting for
confirmation, and it suppresses error messages if the file does not exist.
Observation:
The -f option is useful for scripting or situations where you need to ensure that a file
is deleted without interaction.
Warning: Use this option with caution, as it will not ask for confirmation even if the
file is important or if it does not exist.
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
Observation:
If directory/ is a directory, the rm -R command will delete the directory and all of its
contents, including subdirectories and files.
Warning: This operation is destructive and cannot be undone. Use it carefully to
avoid accidental deletion of important directories.
Summary of Observations
Basic rm Usage: Deletes files without any confirmation, which can be risky if used
without caution.
-i Option: Provides an extra layer of safety by prompting for confirmation before
deletion. Useful for preventing accidental deletions.
-f Option: Forces deletion without confirmation and suppresses errors if files are
missing. Useful for automation but risky if used indiscriminately.
-R Option: Recursively deletes directories and their contents. Extremely powerful
and potentially dangerous, especially when dealing with important directories or data.
9. check the man page of ‘file’ Command. Try the Commands: file x.c; file <dir>;
file *. write your observations.
This command determines and displays the type of the file named x.c.
Observation:
The output will typically show the type of file x.c is. For example, if x.c is a C source
code file, you might see something like x.c: C source, ASCII text.
The file command reads the file’s magic number and file headers to determine its
type, which can include text files, executable files, or binary files, among others.
Replace <dir> with the name of a directory. For example, if the directory is named
docs, you would use file docs.
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
Observation:
The file command will output the type of the directory itself, which is typically
reported as something like docs: directory.
Unlike files, directories are identified by their type rather than their content. The file
command recognizes that <dir> is a directory and does not delve into the contents of
the directory.
This command processes all files and directories in the current directory. The * wildcard
expands to match all filenames.
Summary of Observations
file x.c: Determines and displays the type of x.c. It identifies the file type based on its
content and format, providing useful information about what kind of file it is (e.g.,
text, executable, binary).
file <dir>: Identifies that <dir> is a directory. The file command does not analyze the
contents of directories but simply reports that the type is a directory.
file *: Provides information about every file and directory in the current directory.
Useful for quickly identifying multiple items, including their file types and formats.
a) Try the Command to find the file x.c: $find . -name x.c. write your comments
This command searches for a file named x.c starting from the current directory (.) and
traversing all subdirectories.
Comments:
The find command is very powerful for locating files and directories based on various
criteria.
The -name option is used to specify the filename to search for, and it can be combined
with other options for more complex searches.
b) try to find only directories with “dev” as part of their name. Are there aany? (find . -
name ‘dev’ -type d -print
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
This command searches for directories (-type d) whose names contain the substring
dev, starting from the current directory (.).
11. read/scan the man page of diff and sdff. Write the purpose of those two Commands.
a) Use the Command to determine the difference between two files. Try the Command
$diff file1 file2. Write your observations
The diff output indicates that line 1 in file1 is different from line 1 in file2.
< shows the line from file1, and > shows the corresponding line from file2.The notation 1c1
indicates that line 1 in file1 should be changed to line 1 in file2.
b) try diff to determine the difference between two directories. Write your comments on
the output you got.
Only in dir1: file1.txt indicates that file1.txt exists in dir1 but not in dir2.
Only in dir2: file2.txt indicates that file2.txt exists in dir2 but not in dir1.
If there are matching files in both directories, diff will show the differences between those
files as well.
c) Try with the following Commands: sdiff file1 file2; sdiff -w file1 file2
This command displays the contents of file1 and file2 side by side, with differences
highlighted.The -w option allows you to specify the width of the output. For example,
sdiff -w 100 sets the width to 100 characters.
Common Options
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
-t <delimiter>: Specify a delimiter other than the default space or tab for separating
fields.
o Example: sort -t, -k 2 file.csv will sort lines in a CSV file based on the second
column, using a comma as the delimiter.
13. Create a text file aned ‘students.data’ with two columns ( roll number space name)
consisting of 10 students data.
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
The sort command in Unix/Linux sorts the lines of a file alphabetically by default. When you
run the command sort students.data, it will read the contents of the file students.data and
output the sorted lines to the terminal.
Additional Options
Comments
Sorting is useful for organizing data, especially when dealing with large files.
By default, sort is case-sensitive. Use sort -f to ignore case.
It’s a basic but powerful command that can be combined with other commands like
uniq, grep, and awk for more complex data manipulation.
15. try the following comands: sort stduent.data > sorted.data; cat sorted.data.
Sorting and Redirection: The contents of students.data are sorted, and the sorted output is
saved to sorted.data.
Display Sorted Data: The cat command then reads and displays the contents of sorted.data
in the terminal.
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
16. Sort the list by 1 st names. This requires skipping over the 1 st field: sort +1
student.data; also try sort +4 student.data. Write your comment
Comments
1. Syntax:
o The older syntax (sort +1) is deprecated and may not work in newer versions
of sort.
o The modern -k option is recommended for specifying the key (field) to sort by.
2. Field Separation:
o By default, sort uses whitespace to separate fields. You can specify a different
delimiter using the -t option if needed.
o Example: sort -t, -k2 student.data for a comma-separated file.
3. Flexibility:
o sort is flexible and powerful, allowing sorting by multiple keys or reversing
the order with -r.
4. Checking Results:
o Always check the results to ensure they meet your expectations, especially
when dealing with complex data.
Signature of the
Page No. …………………….. Faculty………………………...
Roll No:160122733163 Exp. No:…1.… Date:…
02/07/2024……
17. print your current working directory (pwd); create a new directory with the name
’OS’. The move to that directory and create a file with the name ‘Linux File Related
Commands’.Then change to your default, home directory:
ls: This command lists all the files and directories in the current directory.
Signature of the
Page No. …………………….. Faculty………………………...