0% found this document useful (0 votes)
7 views

File

The document outlines practical exercises for Linux, including installation, GCC compiler usage, file manipulation commands, and directory-oriented commands. It details various Linux commands such as cat, cp, mv, rm, and their options, as well as user status commands like su, sudo, and uname. Additionally, it covers time stamping, automation using Makefiles, and provides step-by-step instructions for each experiment.

Uploaded by

gargdilkash
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

File

The document outlines practical exercises for Linux, including installation, GCC compiler usage, file manipulation commands, and directory-oriented commands. It details various Linux commands such as cat, cp, mv, rm, and their options, as well as user status commands like su, sudo, and uname. Additionally, it covers time stamping, automation using Makefiles, and provides step-by-step instructions for each experiment.

Uploaded by

gargdilkash
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

INDEX

Sr. No. Practical Name Teacher Sign


1 a) Installation: Configuration & Customizations of Linux
b) Introduction to GCC compiler: Basics of GCC, Compilation of
program, Execution of program.
c) Time stamping in Linux.
d) Automating the execution using Make file.
2 Implement the commands that is used for creating and manipulating
files: cat, cp, mv, rm, ls and its options, touch and their options, which
is, where is, what is
3 Implement Directory oriented commands: cd, pwd, mkdir, rmdir,
Comparing Files using diff, cmp, comm.
4 Implement the basic and user status commands like: su, sudo, man,
help, history, who, whoami, id, uname, uptime, free, tty, cal, date,
hostname, reboot, clear

Experiment 1 (a): Installation: Configuration & Customizations of Linux.

Step 1: Download VirtualBox (VM)


Go to https://www.virtualbox.org/ and download VM for Windows.
Step 2: Download Ubuntu Linux ISO File.
Go to https://ubuntu.com/download and download ISO file for Linux.

Step 3: Create a new Virtual Machine.


Step 4: Allocate RAM Memory and No of Processors.

Step 5: Create a Virtual Hard Disk.


Step 6: Install Linux.

Linux is Now Installed on your PC using VirtualBox VM.


Experiment 1 (b): Introduction to GCC compiler: Basics of GCC, Compilation of
program, Execution of program.
 What is a GCC Compiler?

GCC (GNU Compiler Collection) is a collection of compilers for various


programming languages, including C, C++, and Fortran. It is the default
compiler used in Linux. GCC converts source code written in a high-level
programming language into machine code that the computer can understand.

 How can we compile a code using GCC in Linux?

Step 1: Open a Terminal Window.


Step 2: Create a new directory using the “mkdir” command and navigate into
it.
Step 3: Using any text editor (I have used VI text editor) create a simple C
program.
Step 4: Save the file and exit the text editor.
Step 5: Run the command “ gcc -o <executable name> <file_name>”.
At Step 5, The program will get compiled using GCC Compiler.
Step 6: Run the command “./ <executable name>”.
The Output will be displayed.

Experiment 1 (c): Time stamping in Linux.

 What is Time stamping?

In Linux, time stamping refers to the process of recording the date and time
when a particular event occurs, such as when a file is created, modified, or
accessed. This information is crucial for tracking changes, managing files, and
auditing system activities. Time stamps are stored in the file metadata and can
be accessed using various commands and tools in the Linux operating system.

a) The touch command in Linux is primarily used to create new empty files or
update the access and modification times of existing files.
b) The stat <file_name>command in Linux offers significant benefits for
timestamping by providing detailed information about file access,
modification, and status change times.

This precise timestamp data enables users to analyze the timing of events
accurately, compare timestamps between files, and create detailed audit trails
for security and compliance purposes.

c) In linux you can directly acess an file using cat <file_name> command.
In this you can see we have directly changed access timings without changing

timings of modify
and change.

d) The touch -m <file name> command in Linux provides a quick and efficient way
to update the
modification timestamp of a file without altering its contents.

In this we can see only the timings of modify and change are changed.

e) The touch -a <file name> command in Linux is beneficial for updating the
access timestamp
of a file without altering its content.

Experiment 1 (d): Automating the execution using Make file.


To compile multiple source files (main.c, hello.c, and add.c) and include a header
file (header.h) defining functions to be called in main.c, a Makefile can be created to
automate the build process. Each source file contains specific functions (hello() in
hello.c, add() in add.c), while main.c includes header.h to call these functions.

Experiment 2: Implement the commands that is used for creating and


manipulating files: cat, cp, mv, rm, ls and its options, touch and their options,
which is, where is, what is.
1) Cat command-:

(a) The benefit of cat > <file name> is that it allows you to quickly create a
new file and populate it with content from the cat command, all in a single
command without needing to open a text editor.

(b) The benefit of cat <file name> is that it allows you to quickly view the
contents of a file without needing to open it in an editor.

(c) The benefit of cat <file1 name> <file2 name> is that it allows you to
quickly view the contents of both the files without needing to open it in an
editor.

(d) The cat -n <file name> command displays the contents of the specified file
with line numbers prefixed to each line, allowing for easier reference or
identification of specific lines within the file.
(e) The benefit of cat <file name1> >> <file name2> is that it appends the
contents of <file name1> to <file name2>, effectively combining the
content of both files without overwriting <file name2>.

(f) The benefit of cat <file1 name> <file2 name> >> <file3 name> in one line
is that it concatenates the contents of <file1 name> and <file2 name> and
appends the result to <file3 name>

(g) The benefit of cat >> <file name> is that it allows you to append the
output of cat (which typically reads files sequentially and writes them to
standard output) to an existing file.
2) Cp command-:

(a)The function of cp <file name> <Directory name> is used to copy a file in


directory.

(b) The function of cp <file1 name> <file 2 name><Directory name> is used


to copy two files in directory.

(c) The function of cp <file1 name> <file 2 name> is used to copy content of
file 1 in file2.

(d) The function of cp -i <file name> <directory name> is used to overwrite


content of file.

(e) The function of cp -r<directory1 name> <directory2 name> is used to copy


a directory1 in directory 2.

3) mv command-:
(a) The function of mv <file1 name> <file 2 name> is to move content of one
file to another.

(b) The function of mv <file1 name> <file 2 name> is to rename a file .Like
in this if file2 doesn’t exist then it will rename file1 as file2.

(c) The function of mv <file1 name> <directory name> is to move file to


directory.

(d) The function of mv -i <file1 name> <directory name> is to overwrite a


file in directory if a file with same name already exists in it.

(e) The function of mv <directory1 name> <directory 2 name> is to move


content of one directory to another.

4) rm command-:

(a)The function of rm <file name> is to delete the files.

(b) The function of rm -r <directory name> is to delete the directories.


(c) The function of rm -i <file name> is to confirm for deletion of a file.

5) ls command-:

(a)The ls command lists the contents of your working directory.

(b) The ls <directory name> command lists the contents of the directory
you want to know.

(c) the ls / command lists the contents of your root directory.

(d) The ls .. command will tell us about the root directory and ls ../..
command will show contents of root dir.
(e) The ls -l command shows the content of the the directory in long format.

(f) The ls -a commad lists the normal and hidden files.

(g) The ls -s command lists the contents and file size in kilobytes of the current
directory.

(h) The ls -d */ shows only the directories.

(i) The ls -l>filename cmd creates a new file and store the output.

6) touch command-:
Linux touch command is used to create an empty file and change and modify
timestamps
Of the file (as discussed above in Experiment 1(d)).

7) Whichis command-:

The whichis command in Linux is used to locate the executable file


associated with a given command.

8) Whereis command-:

The whereis command in Linux is used to locate the binary, source, and
manual page files for a specified command. It provides a simple way to find
out where the executable, source code, and manual page of a command are
located on the filesystem.

9) Whatis command-:

The whatis command in Linux is used to display a one-line description of a given


command. It provides a brief summary of the purpose or functionality of the
specified command.
Experiment 3: Implement Directory oriented commands: cd, pwd, mkdir, rmdir,
Comparing Files using diff, cmp, comm.

The Different Directory Oriented Commands are listed below:


1. cd (Change Directory): The cd command is the most basic command in every
Command Line based Operating System. As the name suggests, it is used to
Change from one directory to another. There are several types of cd
commands in Linux:
 cd: used to change dir to user’s home dir.
 cd <dir>: used to change to specific dir.
 cd .. : Moves up one dir.
 cd / : Used to change to root dir.
2. pwd (Print Working Directory): The pwd cmd is used to print the present
working directory in the shell.
 pwd

3. mkdir (Make Directory): The mkdir is also the most basic command used in
CLI OS. It is used to make a new dir. There are several types of mkdir
commands in Linux.
 mkdir <name> : Used to make a new dir of specific name.
 mkdir -p <parent dir>: Used to make nested dirs.

4. rmdir (Remove Directory): The rmdir is used to remove an empty dir in Linux.
 rmdir <dir_name> : Used to remove empty dir of specific name.
 rmdir -p <dir_name>: Used to remove specified dir and its parent dir.

5. diff (File Comparison): The diff cmd is used to spot and tell the difference
between files.
 diff <file1> <file2> : Tells difference between two files line by line.
 diff -u <file1> <file2>: Tells difference in unified format.
6. cmp (Compare Byte by Byte): Compares the two files byte by byte
 cmp <file1> <file2>: Compares two files byte by byte
 cmp -l <file1> <file2>: Displays the byte-by-byte diff along with
their byte position.

7. comm (Compare Two Sorted Files): Compare two sorted files line by line.
 comm <file1> <file2>: Compares two sorted files line by line and
displays lines unique to each file as well as lines common to both files.
Program 4

Implement the basic and user status commands like: su, sudo, man, help,
history, who, whoami, id, uname, uptime, free, tty, cal, date, hostname,
reboot, clear.

Solution

1. su (Switch User):
- Allows a user to switch to another user account, if they have the required
permissions.
2. sudo (Superuser Do):
- Enables a permitted user to execute a command with the security privileges of
another user (commonly the superuser or root).

3. man (Manual Pages):


- Displays the manual pages for a specified command, providing detailed
information on its usage, options, and examples.

4. help:
- Displays help information about built-in shell commands, typically specific to the
shell environment.
5. history:
- Displays a list of previously executed commands, allowing users to view and rerun
commands from their history.

6. who:
- Displays information about users currently logged in, including their username,
terminal, and login time.
7. whoami:
- Outputs the username of the current effective user.

8. id:
- Displays user identity information, including user and group IDs.

9. uname:
There are several sub commands of uname:

 uname : Displays Operating System name.

 uname -a : Provides basic system information such as system name, kernel


version, and architecture.

 uname -s : Displays Kernel Name.


 uname -v : Displays version of the OS.

 uname -r : Displays Kernel version.

 uname -p : Displays the processor type or architecture of the system.

 uname -o : Displays the operating system name.

10. uptime:
There are several sub commands of uptime:

 uptime : Displays how long the system has been running, as well as load
averages.
 uptime -p : Displays the duration since the system was last booted.

 uptime -h : Displays help box of uptime.

 uptime -s : Displays System up since.

11. free:
- Shows the amount of free and used memory (RAM) in the system.
12. tty:
- Prints the file name of the terminal connected to standard input.

13. cal (Calendar):


There are several sub commands associated with cal command:

 cal : Displays a calendar for the current month or any specified month and
year.

 cal <month> <year> : Displays a calendar for the specified year of the
specified month.

 cal <year> : Displays a calendar for the specified year.


14. date:
There are several sub commands associated with date command.

 date : Prints the current date and time according to the system's clock
settings.

 date “+%d/%m/%y” : Prints current system date in format


“day/month/year”.
 date “+%H : %M : %S” : Prints current system time in format
“Hour/Minute/Second”.

 date “+%y” : Prints current system year.

 date “+%B” : Prints current system month.

 date “+%A” : Prints current system Day.

 date -d “Tomorrow” : Prints date, time of Tomorrow.

 date -d “Yesterday” : Prints date, time of Yesterday.


 date -d “Month Ago” : Pronts date, time of a month ago.

15. hostname:
- Displays the system's hostname (computer name).

16. reboot:
- Initiates a system reboot, restarting the operating system.

17. clear:
- Clears the terminal screen, providing a clean workspace for new commands and
output.

You might also like