File
File
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.
(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-:
(c) The function of cp <file1 name> <file 2 name> is used to copy content of
file 1 in file2.
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.
4) rm command-:
5) ls command-:
(b) The ls <directory name> command lists the contents of the directory
you want to know.
(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.
(g) The ls -s command lists the contents and file size in kilobytes of the current
directory.
(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-:
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-:
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).
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:
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.
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.
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.
date : Prints the current date and time according to the system's clock
settings.
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.