Assignment # 4
Submitted To
SIR RIZWAN JAMIL
Submitted By
Nateqa Waqas mtf23006657
Post ADP in Information Technology
DIVISION OF SCIENCE & TECHNOLOGY
University of Education
man Command – Linux Manual Pages
man in Linux ?
The man command in Linux is used to read the manual pages of different commands. It helps
us understand what a command does, how to use it, and what options we can use with it.
Like a user guide for Linux commands.
"When we use the man command, we usually type the name of a command, or function to
see its manual page."
Some common ways are:
• man ls → shows the manual page for the ls command
• man -k copy → searches all manuals related to the word "copy"
1. Command: ls
This command is used to list the files and folders in the current directory. When we just
type ls, it shows us the names of files and folders without any extra details.
man ls
Purpose:
When we want to learn more about the ls command and what options we can use with it,
we run man ls. This opens the manual page, which tells us how ls works and lists many
useful options. It's like a built-in help guide.
5 Parameters of ls (from man ls):
a) ls -a
Purpose:
This option shows all files, including the hidden ones. Hidden files in Linux start with a dot
(.), like .bashrc or .git. Normally, ls hides these files, but with -a, we can see everything
in the folder.
b) ls -l
Purpose:
This shows the files in a long listing format. We can see extra details like file permissions,
number of links, file owner, group, size, and the last modified date and time.
c) ls -S
Purpose:
This sorts the files by size, from biggest to smallest. It helps us quickly see which files are
taking up more space in the folder.
d) ls -1
Purpose:
This displays each file and folder on a new line. It’s helpful when there are many files and
we want to see them clearly, one by one.
e) ls -t
Purpose:
This option sorts the files by time, showing the most recently modified files at the top.
It's useful when we want to see which file was updated last.
Command: rm
Purpose:
The rm command is used to remove (delete) files or folders in Linux. When we delete
something with rm, it doesn’t go to the Trash — it's removed permanently. So we should use
it carefully.
man rm
Purpose:
To understand how rm works and what options (parameters) we can use, we type man rm.
This opens the manual page for rm, which explains everything in detail.
5 Parameters of rm (from man rm):
a) rm -f
Purpose:
This option removes files forcefully, without showing errors or asking for permission. Even
if the file doesn’t exist, it won’t give an error.
There is no file named 'new', but the command still runs without showing any error.
b) rm -i
Purpose:
This option asks "Are you sure?" before deleting every file. It's helpful when we want to be
safe and avoid deleting something by mistake.
c) rm -I
Purpose:
This option asks one time only before deleting more than 3 files or folders. It gives us a
simple warning instead of asking for each file.
d) rm -r
Purpose:
This option lets us delete folders and everything inside them. Normally, rm can’t remove
folders unless we add -r.
e) rm -v
Purpose:
This shows a message for every file that’s being deleted. It helps us see what’s happening
step-by-step.
Command: uname
Purpose:
This command shows system information like the name of the operating system or the
kernel. If we type just uname, it will show us the kernel name (like Linux). It's useful to
know about the system we're working on.
man uname
It shows detail about how the uname command works and what options we can use, we run
man uname. It opens the manual (help page) where we can see all available parameters and
what they do.
5 Parameters of uname:
a) uname -a
Purpose:
This shows all system information in one line — including the kernel name, version,
machine type, and OS. It's a complete view of the system details.
b) uname -r
Purpose:
Shows the kernel release version. This helps us know what kernel version the system is
using.
c) uname -v
Purpose:
Displays detailed version info, including when the kernel was built.
d) uname -p
Purpose:
Displays the processor type.
e) uname -o
Purpose:
Shows the name of the operating system.
4. Command: cmp
Purpose:
The cmp command is used to compare two files byte by byte. It tells us the first
location where the files are different. If there's no difference, it shows nothing (silent
success).
It’s useful when we want to check if two files are exactly the same — like comparing
backups, binaries, or config files.
man cmp
Purpose:
This command shows the manual page of cmp with all available options and details.
cmp Parameters:
a) cmp -b
Purpose:
Shows the differing bytes from both files side by side (byte values shown clearly).
b) cmp -i
Purpose:
Skips the first SKIP bytes in both files before starting the comparison.
c) cmp -I
Purpose:
Shows all differing byte positions and values, not just the first difference.
d) cmp -n
Purpose:
Compare only the first LIMIT number of bytes.
e) cmp -s
Purpose:
No output at all. Just checks if the files are the same or not.
Command: diff
Purpose:
The diff command is used to compare two text files line by line. It tells us what is
different between them — such as added, removed, or changed lines.
It's commonly used by developers to see changes between source code files or
configurations.
man diff
Parameters of diff:
a) diff -q
Purpose:
Only tells whether the files are different or not.
It does not show the actual changes.
b) diff -u
Purpose:
Shows differences in a compact format, with a few lines of context before and after each
change.
This is the most commonly used format by developers.
It shows lines starting with:
• - for removed lines
• + for added lines
• A few unchanged lines around the change
c) diff -e
Purpose:
Creates an edit script that can be used with the ed editor to convert file1 into file2.
The output is a list of editing commands.
d) diff -y
Purpose:
Shows the two files next to each other in two columns.
It helps us easily see the changes line by line.
e) diff -r
Purpose:
Used to compare folders (directories).
It also compares all files inside subfolders.
Command: mv
Purpose:
use the mv command to rename files and folders.
man mv
Parameters of mv:
• mv file.txt folder/
Purpose:
Moves 'file.txt' into the 'folder' directory.
• mv oldname newname
Purpose:
Use to rename the files. Like Renames 'oldname.txt' to 'newname.txt'.
• mv -i
Purpose:
asks for confirmation before overwriting if a file exists.
• mv -v
Purpose:
prints what mv is doing (e.g., "renamed ‘file1.txt’ -> ‘folder/file1.txt’").
Command: touch
Command: ln
man ln
Parameters of ln:
Purpose:
Creates a hard link named 'newlink' pointing to 'newfile'.
• ln -s
Purpose:
Creates a symbolic (soft) link named 'newlink' to 'newfile'.
Works across file systems and shows the original path.
• ln -v
Purpose:
Verbose mode: shows confirmation message of link creation.
Command: grep
Purpose:
It can search for specific patterns or strings in one or more files and filter the output of
other commands.
man grep
Parameters of grep:
• grep -i
Purpose:
Case-insensitive search (matches "new", "New", "NEW", etc.)
• grep -r
Purpose:
Recursively searches for "new" in all files inside 'folder/' and subdirectories.
• grep -n
Purpose:
Shows line numbers alongside matched lines.
Command: cat
Concatenate and display file contents
Purpose:
When you want to output the contents of a file or print anything to the terminal output, we
use the cat or echo commands.
man cat
Parameters of cat:
• Purpose:
Displays contents of both files one after another
• Purpose:
Takes input from keyboard and writes to mynewfile
• Purpose:
Displays file contents with line numbers.
Command: cp
Purpose:
cp' means copy. 'cp' command is used to copy a file or a directory.
man touch
Parameters of cp:
• cp -r
Purpose:
Recursively copies a directory and its contents.
• cp -i
Purpose:
Prompts before overwriting mynewfile if it exists.
Command: chmod
Purpose:
The chmod command is used to change the permissions of a file or directory,
man chmod
Parameters of chmod:
• chmod 755
Purpose:
Sets read, write, execute for owner; read and execute for group and others.
• chmod +x
Purpose:
Adds execute permission to file.
• chmod -x
Purpose:
Removes execute permission from file
• chmod u+w
Purpose:
Adds write permission to the file for the owner (user).
Command: echo
Purpose:
When you want to output the contents of a file or print anything to the terminal output, we
use the cat or echo commands.
man echo
Parameters of echo:
• echo $HOME
Purpose:
Prints the current user's home directory path.
• echo -n
Purpose:
Prints text without a trailing newline.
• echo -e
Purpose:
Enables interpretation of backslash escapes (like newline).
Command: whoami
Purpose:
The whoami command in Linux returns the current user’s username. It stands for “who am
I?” and it’s often used to determine the current user’s identity in shell scripts or the
terminal.
man whoami
Parameters of whoami:
• echo
echo "You are $(whoami)"
Purpose:
Uses the whoami command inside another.
• sudo
Purpose:
Shows "root" if you're using sudo.
• whoami > file
Purpose:
Saves the current user name to a file.
Command: history
Purpose:
Shows history- which commands run on the terminal.
man whoami
Parameters of history:
• history 10
Purpose:
Shows the last 10 commands.
• !25
Purpose:
Re-runs command number 25 from history.
• !!
Purpose:
Re-runs the last command.
• history -c
Purpose:
Clears the entire command history.
Command: clear
Purpose:
The clear command in Linux clears the terminal screen. It removes all the text and output
currently displayed on the terminal and gives you a clean slate to work with.
Man clear
Parameters of clear:
•
clear && echo "Clean screen"
Purpose:
Clears screen, then prints a message.
• Ctrl +L
Purpose:
Keyboard shortcut for clear (same effect).
• alias c=clear
Purpose:
Creates a shortcut alias to clear.