0% found this document useful (0 votes)
42 views35 pages

Linux & UNIX Basics Guide

The document provides an overview of UNIX and Linux fundamentals, including various flavors of both operating systems, their architecture, and basic features. It covers the advantages of Linux, the concept of shells, categories of operating system shells, and the Linux file system hierarchy. Additionally, it details basic Linux commands, the grep command, and the differences between soft links and hard links.

Uploaded by

Barry Allen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views35 pages

Linux & UNIX Basics Guide

The document provides an overview of UNIX and Linux fundamentals, including various flavors of both operating systems, their architecture, and basic features. It covers the advantages of Linux, the concept of shells, categories of operating system shells, and the Linux file system hierarchy. Additionally, it details basic Linux commands, the grep command, and the differences between soft links and hard links.

Uploaded by

Barry Allen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

🫡 Tab 1

LINUX
UNIX Basic Fundamentals

1. List UNIX and Linux flavors


○ UNIX Flavors
■ AIX
■ HP-UX
■ Solaris
■ BSD (Berkeley Software Distribution)
■ SCO UNIX
■ IRIX
○ Linux Flavors
■ Red Hat Enterprise Linux (RHEL)
■ CentOS
■ Ubuntu
■ Debian
■ Fedora
■ Kali Linux

Architecture of Linux

2. Basic features of Linux


○ Multi-user - Not only can you have many user accounts on a Linux
System, you can also have multiple uses logged in & working on the
same system at the same time
○ Multitasking - In Linux,it is possible to have many programs running at
the same time,which means that only can you have many programs
going at once,but that the Linux operating system itself can have
programs running in the background
○ Hardware Support - You can configure support for almost every type
of hardware that can be connected to a computer. There is support for
floppy disk drives,CD-Roms,Sound Card, Tape Devices, Video Cards
etc.
○ Networking Connectivity - To connect your Linux system to a
network, Linux offers variety of LAN Cards, Modems and serial
Devices.
○ Network Servers - A variety of software packages are available that
enables you to use Linux as a Print Server, File Server, TP Server, Mail
Server, Web Server, News Server or Workgroup Server.

3. Advantages of Linux
○ Free & Open Source Operating System - The Linux Operating System
is available at No Cost & anyone can download it from Internet without
paying for it. The source code of the operating system is provided
with it so that anyone can edit the source code for convenience.
○ Reliable - As the Linux Operating System can be recovered easily the
data loss doesn’t happen, that is why it is reliable.
○ Secure - There is very less possibility of hacking of Linux that is why it
is more secure than any other Operating System
○ Help is available on Internet - There is always someone available on
Internet from Linux Community to help Linux Users.

4. Short note on Shells


○ In the family of Linux Operating System the use of a program that
serves as an interface between user & operating system is called the
Shell.
○ Its is a program that presents an interface to various operating system
functions & services.
○ The shell is so called because it is an outer layer of interface between
the user & the innards of the operating systems.
○ The shell is a kind of interpreter i.e. a shell is a program which takes
user input (e.g. commands which we type) & translates them into
instructions that the operating system can understand.

5. Categories of OS Shell
The Operating system shell has two categories :
○ Command Line Interface (CLI)
■ A CLI is a method of interacting with a computer by giving it lines
of textual commands either from keyboard input or from a script.
■ Shells like Bash, sh, Zsh, and Ksh are CLI-based.
■ It’s widely used by system administrators, developers, and users
who need precise control over the system.
■ Requires knowledge of commands and syntax.
■ Minimal resources.
○ Graphical User Interface (GUI)
■ A GUI is a method of interacting with a computer through a
metaphor of direct manipulation of graphical images & widgets.
■ GUI shells in Linux environments include GNOME, KDE, Xfce, etc
■ Commonly used by desktop users for general-purpose tasks (file
browsing, system settings, applications).
■ More intuitive with visual cues and prompts.
■ Higher resource consumption (graphics, memory).

6. Features of Shell
The shell offers the following interactive features
○ Command History - The command “history” buffer stores the
commands you enter & let you display them at any time. As a result,
you can select a previous command, or parts of previous commands,
& then re-execute them. This feature saves time because it lets you
reuse long commands instead of retyping them.
○ Command Aliases - The command aliases feature lets you abbreviate
long command lines or rename commands. You do this by creating
aliases for long command lines that you frequently use. In addition,
aliases let you make up more descriptive names for o.s. Commands.
○ File name completion - The file name completion feature saves typing
by allowing you to enter a portion of the file name, when you press the
tab/esc key, the shell will complete the file name for you.
○ Command Line Editing - This allows you to retrieve a previously
entered command & edit it.

7. List the various shells in Linux


There are many different types of shells
○ Bourne Shell (sh) -
■ One of the original Unix shells, known for its simplicity.
■ Commonly used for scripting and system administration tasks.
■ does not support any of the shell features such as history,
command line completion & command line editing.
○ Bourne Again Shell (Bash) -
■ The most widely used shell on Linux systems
■ an extension of the Bourne shell
■ uses the Bourne shell syntax.
■ A so-called superset of the Bourne shell.
■ Is compatible with bourne shell
○ C Shell (csh) -
■ Syntax is similar to the C programming language.
■ Popular for users familiar with C syntax but less common today.
○ Korn Shell (ksh) -
■ Combines features of the Bourne Shell and C Shell.
■ superset of bourne shell.
■ features built-in arithmetic evaluation & advanced scripting
capabilities found in awk, sed & perl.
○ Tenex C shell (tcsh) -
■ enhanced version of the C Shell (csh)
■ has programmable file-name completion, command line editing,
a history mechanism & other features lacking in csh.

Linux File System Architecture

8. Explain Linux File System Hierarchy (Linux Directory Structure) with


diagram.
○ / (root directory) - the home directory of the system administrator.
○ /bin - Contains essential binary executables for basic system
operations for both the system admin as well as non-priveleged users.
Ex. ls, cp, mv, chmod
○ /boot - Contains bootloader-related files necessary for booting the
system except for the configuration files not needed at the boot time.
○ /dev - Contains device files for hardware components.
○ /etc - The Nerve center of the system. Stores system-wide
configuration files.
○ /home - Stores user directories where personal files and data are
kept. For General user,home directory will be /home/username. For
root user, home directory is /root.
○ /lib - Contains shared libraries needed by essential binaries in /bin and
/sbin.
○ /media - Mount point for removable media like USB drives, CDs, etc.
○ /mnt - Temporary mount point for file systems mounted manually by
the system administrator.
○ /opt - Used for optional software & add-on packages.
○ /proc - Virtual file system that provides information about system
processes and kernel status.
○ /sbin - Contains system administration binaries, typically used by the
root user.
○ /tmp - Temporary files storage which is cleared during reboot.
○ /usr - Contains user programs and utilities. Has the largest share of
data on a system. one of the most important directory in the
system.User programs like telnet, ftp, etc are also placed here.
○ /var - Stores variable data, such as logs, temporary files, and mail.

9. Explain Basic Linux Commands


○ pwd - prints current working directory.
Syntax : pwd
○ date - shows current date along with time
Syntax : date
○ cal - shows calendar for the current month
○ touch - used to create an empty file
Syntax: touch filename
ex. touch file1 #creates an empty file named file1
○ cat - The concatenate (cat) command displays file content. It is used
to view file contents, combine files, and create new files.
Syntax: cat [options] [file_name]
■ Display contents of a single file
Syntax : cat file.txt
■ Create a new file & add content to them -
Syntax : cat > filename
■ Redirect contents of a single file -
Syntax : cat file1.txt > file2.txt
■ Append a file’s content to another file -
Syntax: cat file1 >> file2
■ Append Text to Existing File -
Syntax : cat >> test1.txt
■ Show Line Numbering -
Syntax : cat -n test1.txt
○ ls - lists directory contents of files and directories
Syntax: ls [options] [filename or directory name]
■ Listing files in reverse order
Syntax: ls -r
■ Listing file & directory permissions with -l option
Syntax: ls -l
using the -l flag, you can list the permissions of the files and
directories as well as other attributes such as folder names, file
and directory sizes, and modified date and time.
■ Viewing files in a human readable format
Syntax : ls -lh
To easily identify the file sizes as kilobytes (kB), Megabytes (MB)
or Gigabytes (GB), append the -lh flag
■ Viewing hidden files
Syntax : ls -a
Hidden files are usually system files that begin with a full stop or
a period.
■ Listing files recursively
Syntax : ls -R
It displays the directory tree of files & folders
■ Displaying the inode number of files & directories
Syntax : ls -i
inode number (index node) serves as a unique identifier for a
file.
○ cp - It is used to copy files & directories
Syntax : cp [option] source-file destination-file
■ Copying interactively
Syntax : cp -i source destination
used to overwrite the existing file
■ Copying Recursively a directory to another location
Syntax : cp -R dir1 dir2
It copies entire directory structure recursively with all
sub-directories & files
■ Copying while preserving permissions, ownership, timestamps -
Syntax : cp -p file1 file2
■ Copying while preserving all attributes -
Syntax : cp -a file1 file2
The -a option stands for archive, which ensures that the copied
items retain their original characteristics
○ mv - This command is used to move or rename the files or directories
Syntax : mv [option] sourcefile destinationfile
○ mkdir - This command is used to create a directory.
Syntax : mkdir directory-name
○ rmdir - This command is used to remove empty directory only.
Syntax : rmdir directory-name
○ rm - This command is used to remove directories with content inside.
Syntax : rm directory-name
■ Remove directories recursively
Syntax: rm -r dir-name
■ Remove directories interactively
Syntax : rm -i dir-name
■ Remove directories forcefully
Syntax : rm - f dir-name
○ more - This command is used to display whole contents of a file at a
time.
Syntax : more filename
○ less - This command is used to display one page at a time.
Syntax : less filename
○ head - This command is used to display first 10 lines of a file.
Syntax : head filename
■ Display custom no. of lines
Syntax: head -n number filename
ex. head -n 5 file2
○ tail - This command is used to display the last 10 lines of a file.
Syntax : tail filename
■ Display custom no. of lines
Syntax: tail -n number filename
ex. tail -n 3 file4
○ wc - calculates a file's word, line, character, or byte count.
Syntax : wc [option] filename
■ Display the number of lines
Syntax : wc -l file
■ Display the number of words
Syntax : wc -w file
■ Display the number of bytes
Syntax : wc -c file
○ chown - The command is used to change the owner of a file.
Syntax: chown newowner_name file_name
○ diff - compares two files line by line and shows the exact lines that
differ between them.
Syntax : diff file1 file2
Detailed output; shows exact changes required to make the files
identical.
○ cmp - compares two files byte by byte and reports the first point of
difference.
Syntax : cmp file1 file2
Minimal output; only shows the first point of difference.
○ history - displays the commands previously used.
Syntax: history
■ Display the last n commands used.
Syntax: history n
○ !! - repeat the last command executed in the shell.
Syntax: !!
■ Re-execute nth command from the command history
Syntax : !n
○ sort - Sort or arranges a file in alphabetical order.
Syntax : sort [option] filename
■ Sort in reverse order
Syntax : sort -r test.txt
■ Remove duplicate entries
Syntax : sort -u test.txt
■ Sort by months
Syntax : sort -M months.txt
■ Randomly sort data
Syntax : sort -R file.txt
■ Sort numerically
Syntax : sort -n numbers.txt
○ shutdown - This command is used to shutdown the system safely.
Syntax : shutdown [options] [time] [message]
■ Immediate shutdown
Syntax: shutdown now
■ Rebooting the system
Syntax : shutdown -r now
■ Scheduled shutdown
Syntax : shutdown -h +30
The system will shut down in 30 minutes.
-h -> halts (stops the system & powers it off)
■ Cancelling a Scheduled Shutdown
Syntax : shutdown -c
■ Shutdown with a Custom Message
Syntax : shutdown -h +10 “system will shutdown for
maintenance”
This schedules a shutdown in 10 minutes and sends a custom
message to all logged-in users.
○ init 0 - The system will be shutdown immediately.
Syntax: init 0
○ init 6 - The system will be rebooted immediately.
Syntax: init 6
○ poweroff - The system will be halted.
Syntax: poweroff
○ who - Lists all users currently logged into the system along with their
session details
Syntax: who
○ whoami - Shows the username of the user currently executing the
command.
Syntax: whoami

10. What is grep command. Explain with options.


○ The grep (Global Regular Expression Print) command in Linux is used
for searching text or searching for patterns within files or command
outputs.
Syntax: grep [options] pattern [file…]
○ Common options with grep
■ Search for the pattern in the specified file
Syntax: grep “pattern” file.txt
This searches for lines containing "patterb" in file.txt.
■ Make the search case-insensitive
Syntax: grep -i “pattern” file.txt
This matches “Pattern”, “PATTERN”, “pattern” etc.
■ Search recursively through directories
Syntax: grep -r “todo” /path/to/project
This searches for "todo" in all files within /path/to/project/ and its
subdirectories.
■ Display lines that do not match the pattern
Syntax: grep -v “error” file.txt
This displays all lines in file.txt that do not contain "error".
■ Count the number of matching lines and display only the count
Syntax: grep -c “error” logfile.txt
This outputs the number of lines containing "error" in logfile.txt.
■ List file names that contain at least one match for the pattern.
Syntax: grep -l “error” *.txt
This shows the names of .txt files containing "error".

11. Explain soft links and hard links in Linux with examples
○ Softlinks -
■ A soft link is a pointer to another file’s pathname. It works like a
shortcut and can point to files or directories on the same or
different file systems.
■ Has a different inode number than the target file.
■ If the target file is deleted, the soft link becomes a dangling link
(broken).
■ Can link to directories and files across file systems.
○ Command to create a Softlink -
ln -s /path/to/target /path/to/link_name
○ Ex. ln -s /home/user/file.txt /home/user/link_to_file.txt
This creates a symbolic link link_to_file.txt pointing to file.txt. If file.txt
is deleted, link_to_file.txt will not work.

○ Hardlinks -
■ A hard link is a reference directly to the inode of the file. Multiple
hard links can exist for a single file, and all hard links share the
same inode.
■ Shares the same inode and data as the target file.
■ If the original file is deleted, the data remains accessible through
the hard link.
■ Cannot link to directories or files across different file systems.
○ Command to Create a Hard Link:
ln /path/to/target /path/to/link_name
○ Ex. ln /home/user/file.txt /home/user/hardlink_to_file.txt
This creates a hard link hardlink_to_file.txt which shares the same
inode as file.txt. If file.txt is deleted, hardlink_to_file.txt still contains
the data.
The VIM Editor

12. What is the use of VIM editor in Linux? State its features, advantages and
disadvantages.
○ VIM is the standard text editor in Linux.VIM is used to edit, change &
save the contents of a file.
○ Following are some features of VIM editor:
■ Supports syntax highlighting for various programming
languages.
■ Customizable through the .vimrc file and supports plugins.
■ Allows quick navigation using keyboard commands (h, j, k, l).
■ Advanced search and replace functionality using regular
expressions like *, ., \, ^, $, etc.
■ Powerful undo and redo capabilities (u to undo, Ctrl+r to redo).
■ Efficient even on low-resource systems.
○ There are some advantages of VIM editor, such as:
■ Speed : Do more with fewer key-strokes
■ Simplicity : No dependence on mouse/GUI
■ Availability: Included with most Unix like Operating systems like
Linux distributions (like Ubuntu, Fedora, Debian) and macOS.
○ However, there are some disadvantages that you will discover, such
as
■ Difficulty: Steeper learning curve than simpler editors.
■ Key Binding emphasize speed over intuitiveness.
○ There are three main modes with VIM:
■ Command Mode : The default mode. Allows keys to be used for
Cursor Movement, copying, Cutting & Pasting Text.
■ Insert Mode: Allows key strokes to be inserted into the document
i.e. Modify Text
■ Exit Mode: Allows keys to be used to save, save as & quit the
document

13. Write a note about the Streaming nature of Data in Linux. (I/O channels)
Linux provides three I/O channels to processes:
○ Standard input
■ The default source for standard input is the keyboard
■ Processes can receive input directly from users via this channel,
making it a crucial aspect of user interaction in the
command-line interface.
■ represented by stdin with file descriptor number 0.
○ Standard Output
■ By default, standard output is directed to the terminal window
■ Most commands send their output to stdout without needing
explicit instructions.
■ This allows users to see the results of commands immediately on
their screens.
■ represented by stdout with file descriptor number 1.
○ Standard Error
■ Standard error is a secondary output stream used to convey
warnings, usage messages, error messages, and other essential
information that is distinct from standard output
■ Like stdout, stderr is typically directed to the terminal window.
■ The separation of error messages from regular output is
particularly beneficial for debugging and logging.
■ represented by stderr with file descriptor number 2.

14. List some common redirection operators & explain redirecting input &
output
Redirection operators in Linux allow users to control where the input and
output of commands are sent. Here are some common redirection operators:
○ Redirecting Output:
■ >: Redirects standard output (stdout) to a file, overwriting the file
if it exists.
Example: echo "Hello, World!" > output.txt
■ >>: Appends standard output to a file without overwriting it.
Example: echo "Hello again!" >> output.txt
■ 2>: Redirects standard error (stderr) to a file, overwriting the file
if it exists.
Example: command 2> error.log
■ 2>>: Appends standard error to a file without overwriting it.
Example: command 2>> error.log
■ &>: Redirects both stdout and stderr to a file (available in Bash).
Example: command &> output.log
○ Redirecting Input:
■ <: Redirects standard input (stdin) from a file, allowing a
command to read from the file instead of user input.
Example: sort < input.txt
○ Piping:
■ |: Pipes the output of one command as input to another
command, enabling data processing sequences.
Example: ls -l | grep "txt"

15.What is the use of pipes in Linux? Explain with example.


○ Pipes (|) are used in Linux to connect the output of one command
directly as the input to another command.
○ This allows for the creation of powerful command combinations,
enabling efficient processing of data without the need for intermediate
files.
○ Syntax: command1 | command2
Here the stdout (standard output) of command1 is redirected to the
stdin (standard input) of command2
○ Ex1. ls -l | grep "txt"
The ls -l command lists files in the directory in long format. The output
is then piped (|) to grep, which searches for files containing "txt" in
their names.
○ Ex2. cat file.txt | grep "keyword"
Displays the content of file.txt and searches for lines containing
“keyword” in the file.
○ Ex3. who | wc -l
Displays users currently logged into the system and counts the no, of
logged in users.

User & Group Administration


16. Explain user administration in Linux
○ useradd - The command-line utility useradd provides a simple method
for adding new users to the system.
Syntax: useradd [options] username
■ Specify the user’s home directory
Syntax: useradd -d /home/newuser newuser
■ Specify the default shell for the user
Syntax: useradd -s /bin/bash newuser
○ passwd - This command sets or changes the password for the user
newuser. The root user will be asked to enter and confirm the new
password for the target user.
Syntax: passwd username
○ userdel - used to delete an existing user account and optionally
remove the user's home directory and associated files.
Syntax: userdel [options] username
■ Remove user’s home directory & mail spool along with the user
account
Syntax: userdel -r olduser
This deletes the user olduser and removes their home directory.
○ usermod - The usermod command modifies the properties of an
existing user account. It allows you to change the user's home
directory, shell, groups, and more.
Syntax: usermod [options] username
■ Change user’s home directory
Syntax: usermod -d /new/home/directory newuser
■ Change default shell for the user
Syntax: usermod -s /bin/zsh newuser
■ Add user to an existing group
Syntax: usermod -aG groupname newuser
■ Change User’s Login Name
Syntax: usermod -l newname oldname
■ Lock user account to prevent user from logging in
Syntax: usermod -L username
■ Unlock user account to allow user to login
Syntax: usermod -U username
■ Add Information to a User
Syntax: usermod -c “information” username
■ Change User’s UID
Syntax: usermod -u newUID username
A UID (user identifier) is the unique number assigned to the user
upon account creation with the useradd command.
■ Change User’s Primary Group
Syntax: usermod -g group username

17. Explain group administration in Linux


○ groupadd - used to create new groups on the system.
Syntax: groupadd [options] groupname
■ Create a system group
Syntax: groupadd -r groupname
System groups usually have a Group ID (GID) lower than 1000
(on many Linux distributions), and they are used for internal
system processes.
○ groupdel - The groupdel command is used to delete a group from the
system. It removes the group entry from /etc/group and /etc/gshadow
files.
Syntax: groupdel groupname
○ groupmod - The groupmod command is used to modify an existing
group's attributes, such as the group name or GID.
Syntax: groupmod [options] groupname
■ Change the name of the group
Syntax: groupmod -n newgroupname oldname

18. Explain switching accounts in linux


○ The su command in Linux stands for substitute user or switch user,
and it allows you to switch to another user account within a terminal
session.
○ It is most commonly used to switch to the root (superuser) account to
gain administrative privileges, but it can be used to switch to any other
user account as well.
○ Syntax: su [options] [username]
○ Following are some common options:
■ Switching to Root user
Syntax: su
This switches to the root user. You will be prompted for the root
password.
■ Switching to Another User
Syntax: su username
This switches to a different non-root user account. You will be
prompted to enter the password of that user.
■ Switching to Root with a Login Shell
Syntax: su -
The - option (or -l or --login) starts a login shell for the root
user.This simulates a full login, resetting environment variables
and switching to the root user's home directory (/root).
■ Execute a command as another user
Syntax: su -c command username
Executes a single command as another user, then returns to the
original user.

Files, Directories & Special Permissions

19. What are the basic file permissions in Linux.


Linux has a permission system based on three key attributes:
○ Read access - this is symbolized as ‘r’; it gives user access to read the
file.
○ Write access - this is symbolized as ‘w’; it gives user access to write
or modify the file.
○ Execute access - this is symbolized as ‘x’; it gives user access to
execute a command on the file.

20. Explain the three entities that Linux file permissions are assigned to
These permissions are usually assigned to three entities on the Linux file
system.
○ Owner (u): Signifies the user who created the file and is usually your
default Linux user.
○ Group (g): A group of users with shared ownership or access to the
file.
○ Others (o): This user didn’t create the file or isn’t in the group with
access. They could have a specific permission attribute access to the
file.

21. How to grant file permissions?


○ In Linux, granting file permissions can be tricky.
○ The chmod command is the tool for managing file permissions.
○ The syntax is as follows:
chmod [entity + permissions] [file]
- entity represents identities: u,g,o (user, group, other)
- here + could be any action. +, -, = (add, remove, set exact)
- permissions represents access levels: r, w, x (read, write,
execute)
○ Ex1. chmod g+w file.txt
The command will set write permission for a user group of the file
file.txt. The current owner of the file will still have read and write
permission.
○ chmod o+r file.txt
The command below will add read permission to the other group
entity for the file file.txt. The owner and user group will still have read,
write, and execution permission.

22. How to grant permissions using Number Notation


○ You can grant permissions using number notations. The permission
access represented using numbers (octal format):
■ 4: Read (r)
■ 2: Write (w)
■ 1: Execute (x)
○ The numeric value is a sum of these numbers:
■ 7: Read, write, and execute (rwx)
■ 6: Read and write (rw-)
■ 5: Read and execute (r-x)
■ 4: Read only (r--)
○ Ex. chmod 755 file sets permissions as follows
Owner: Read, write, and execute (7)
Group: Read and execute (5)
Others: Read and execute (5)

23. List special types of file permissions in Linux with its numeric value.
In addition to the basic file permissions (read, write, execute), Linux has
three special permissions that provide additional control over file and directory
access:
○ Set User ID (SUID)
■ When set on an executable file, it allows the file to be executed
with the permissions of the file owner, rather than the user
executing the file.
■ Commonly used for programs that need elevated privileges,
such as passwd.
■ Numeric Value: 4
■ Symbolic Representation: s in the owner’s execute field (e.g.,
rwsr-xr-x).
■ ex. chmod 4755 /path/to/file
○ Set Group ID (SGID)
■ When set on a directory, any files created within that directory
inherit the group ownership of the directory instead of the user’s
primary group.
■ When set on an executable file, it runs the file with the
permissions of the file’s group.
■ Numeric Value: 2
■ Symbolic Representation: s in the group’s execute field (e.g.,
rwxr-sr-x for files or drwxrwsr-x for directories).
■ ex. chmod 2755 /path/to/file_or_directory
○ Sticky Bit
■ When set on a directory, it ensures that only the owner of the file
(or the root user) can delete or modify files within that directory,
even if others have write permissions.
■ Commonly used on directories like /tmp to prevent users from
deleting each other’s files.
■ Numeric Value: 1
■ Symbolic Representation: t in the others’ execute field (e.g.,
rwxrwxrwt for directories).
■ Ex. chmod 1755 /path/to/directory

24. Explain ACL (Access Control List) in Linux with examples


○ Access Control Lists (ACLs) provide a more granular permission
system than the traditional Linux file permissions (rwx)
○ They allow you to specify permissions for individual users and groups
beyond the file's owner, group, and others, giving you more flexibility
in managing file and directory access.
○ ACLs let you assign permissions (read, write, execute) to specific
users and groups in addition to the standard owner, group, and others.
○ Following is the ACL Structure
■ user::rwx: Permissions for the owner of the file.
■ user:user2:r--: Permissions specifically set for user2.
■ group::r--: Permissions for the group owner.
■ group:group2:rwx: Specific permissions for another group
(group2).
■ other::---: Permissions for others not covered by user or group
entries.
■ mask::r--: Defines the maximum permissions that can be applied
to users and groups (other than the owner).
○ Following are some commands regarding ACLs
■ To check the ACLs for a file or directory, use:
Syntax: getfacl filename
This shows the standard permissions and additional ACL entries
■ To modify ACL use
Syntax: setfacl -m u:user2:rwx
Grants full access to a specific user (user2)
■ To remove an ACL for a specific user
Syntax: setfacl -x u:user2 filename
■ To remove all ACLs
Syntax: setfacl -b filename

25. Explain the use of yum command with various options and examples.
26. Explain the use of xfsdump and xfsrestore commands with examples

Processes & Signals

27. Short note on Daemons


○ A daemon is a background process in Linux (and UNIX-like operating
systems) that runs continuously, waiting for requests or events to
occur
○ Unlike regular applications that are initiated by a user, daemons
typically start during the boot process and run autonomously, often
without any direct user interaction.
○ Daemons usually have names ending in "d" (e.g., httpd for the Apache
web server).
○ They provide essential services such as hardware management,
network communication, and scheduled tasks.
○ Daemons are initiated during the boot process and continue running
until the system is shut down.
○ They can be managed by system initialization frameworks like
systemd or older systems like init.
○ Daemons often log their activities to system log files, aiding in
monitoring and troubleshooting
○ Daemons can be controlled with commands such as systemctl for
starting, stopping, restarting, or checking the status of services.
Ex. systemctl start <service_name>
○ Daemons are critical for maintaining system operations, enabling
various functionalities, and enhancing overall system performance
○ Common Daemon examples are
■ httpd: Apache web server daemon.
■ sshd: OpenSSH daemon for secure shell connections.
■ cron: Daemon for executing scheduled tasks.

28. Define process in Linux and list its different states.


○ A process is a set of instructions loaded into the memory.
○ Every process has state property.
○ They are:
■ Running - The process is actively using the CPU Usage
■ Sleeping - The process is in memory but not doing anything
■ Sleeping Uniterruptible - Process is sleeping & can’t be woken
up until an event occurs. It can’t even be woken up by a signal. It
is the result of an I/O operation, such as failed network
connection.
■ Zombie - Just before a process terminates it sends a signal to its
parent & waits for the acknowledgement before terminating.
Even if the parent process doesn’t acknowledge immediately, all
resources except the ‘pid’ are released. Zombie processes are
cleared from the system in the next reboot.

29. Explain ps with Options.


○ The ps (Process Status) command in Linux is used to display
information about the currently running processes on the system.
○ It provides details like the process ID (PID), terminal associated with
the process, CPU usage, memory usage, and more. It’s an essential
tool for monitoring and managing processes.
○ Syntax: ps [options]
○ Common options for the ps command:
■ Show processes associated with the current shell session
Syntax: ps
Displays PID, terminal (TTY), CPU time, and the command name.
■ Shows all processes on the system from all terminals
Syntax: ps -e OR ps -A
This lists every process currently running, regardless of the user
or terminal
■ Print process percentage
Syntax: ps -f
Provides a more detailed view, including user, PID, parent PID
(PPID), CPU time, and command.
■ Include process non attached to terminals
Syntax: ps -x
Displays all processes that are running without an associated
terminal (TTY). It shows both foreground and background
processes
■ Print process owner information
Syntax: ps -u [username]
Displays processes owned by a specific user.
■ Print custom information; pid, %cpu, %mem, etc
Syntax: ps -o pid,%cpu,%mem,
This displays the PID, memory usage, and CPU usage for each
process.

30. What are Signals


○ Signals are the simple messages that can be communicated to
processes with some commands such as kill, killall, pkill etc.
○ Signals are specified by name or number when they are sent.
○ They act like notifications sent to process to indicate events like
interrupts, termination or errors.
○ They can be sent by the kernel, users, or other processes.
○ Ex.
Signal 15 or TERM
Signal 9 or KILL
Signal 17 or STOP

31. What is the use of scheduling in Linux? Explain the working of crontab
command with various options and examples.
○ Scheduling in Linux allows users and administrators to automate tasks
at specified times or intervals.
○ It is essential for automating repetitive tasks, running system
maintenance jobs, backups, and managing system resources
efficiently.
○ crontab is used to schedule recurring tasks (jobs) in Linux. It uses the
cron daemon, which runs in the background, executing scheduled
jobs defined in the crontab file.
Syntax: crontab [options]
○ Following are the common options in crontab
■ crontab -e : Edits the crontab file for the current user, allowing
you to add, modify, or delete scheduled jobs.
ex. crontab -e
This opens the crontab file in the default editor where you can
define your scheduled tasks.
■ crontab -l : Lists all the scheduled jobs for the current user.
ex. crontab -l
This shows all the jobs currently scheduled in the user’s crontab.
■ crontab -r : Removes all schedules jobs for the current user.
ex. crontab -r
This deletes all jobs from the current user's crontab file.
■ crontab -u username : Used by the root user to edit, list or
remove crontabs for another user.
Ex. crontab -u username -e
This opens the crontab file for the specified user.
○ Each user can have their Crontab file, where they can define the
scheduling commands that are to be executed.
○ Crontab stands for “cron table, ” because it uses the job scheduler
cron to execute tasks;
○ Each line in the crontab file follows this structure:
* * * * * command
○ The five * fields represent:
■ Minute (0-59)
■ Hour (0-23)
■ Day of the Month (1-31)
■ Month (1-12)
■ Day of the Week (0-7, where both 0 and 7 represent Sunday)
○ Ex1. Run a Script Every Day at Midnight
0 0 * * * /path/to/script.sh
This runs the script at 12:00 AM every day
○ Ex2. Run a Backup Script Every Month on the 1st at 3 AM
0 3 1 * * /path/to/backup.sh
This runs the backup script on the 1st day of each month at 3:00 AM

32. What is the XINETD Service


○ XINETD (Extended Internet Service Daemon) is a super-server
daemon in Linux that manages a variety of internet-based network
services.
○ It acts as a replacement for the older INETD service, providing
additional security features and more flexible configuration options.
○ Services which are needed less frequently or requiring additional
resource management, are typically controlled by the xinetd service.
○ Xinets uses /etc/services in its configuration of port-to-service
management.
○ The default installed configuration of xinetd is provided by the top
level configuration file /etc/xinetd.conf & service specific files under
the etc/xinetd.d directory tree.
○ The top level configuration file /etc/xinetd.conf sets the global
configuration options shared by all managed services.
○ It also provides the path to service specific configuration.

File System & related commands

33. Explain Swap File


○ A swap file is a special file on a disk used by Linux (and other
Unix-like operating systems) to provide additional virtual memory
beyond the physical RAM available in the system
○ It acts as an overflow space for data that cannot fit into RAM, allowing
the operating system to move inactive or less frequently used data
from memory to the swap file
○ It provides additional virtual memory when RAM is full, allowing the
system to manage memory more effectively.
○ It helps maintain performance by offloading inactive data from RAM,
preventing crashes or slowdowns.
○ It enables the hibernation feature by saving the contents of RAM,
allowing the system to restore its previous state upon waking.
○ It isolates processes and manages memory allocation, ensuring that
applications do not interfere with each other.
○ It accommodates applications that require more memory than is
physically available, preventing out-of-memory errors.

34. What is RPM? What are the options of RPM?


○ The Red Hat Package Management (rpm) command is used to install
the packages (softwares) into the linux system.
○ Following are the common rpm commands:
■ Install a package -
Syntax : rpm -ivh package_name.rpm
-i -> installs packages
-v -> shows verbose output
-h -> prints hash marks, which are visual indicators that
show the installation progress.
■ Upgrade a package -
Syntax : rpm -Uvh package_name.rpm
-U -> Upgrades packages.
-v -> Shows verbose mode.
-h -> Prints hash marks to show the upgrading process.
■ Remove a package -
Syntax : rpm -e package_name.rpm
-e -> Uninstall or erase an RPM package
■ Freshen a package -
Syntax : rpm -Fvh package_name.rpm
-F -> Upgrade packages but only if a package with the
same name is already installed.
-v -> Shows verbose mode.
-h -> Prints hash marks to show the upgrading process.
■ List all installed packages -
Syntax : rpm -qa
-q -> query RPM package(s) or display information about
installed packages.
-a -> lists all installed packages.
■ Querying RPM package (retrieve detailed information about a
specific package) - displays information like the package name,
version, architecture, and more.
Syntax : rpm -q package_name
■ Query an uninstalled RPM package - lists the possibly
uninstalled package.
Syntax : rpm -qp rpmfile
-q -> query the package.
-p -> indicates that the query is being run on an RPM file
(i.e., the package is not yet installed on the system)
■ Verifying a RPM package - checks if the package’s files have
been modified or deleted.
Syntax : rpm -V package_name
-V -> Verify the integrity of installed packages.

35. Explain the working of tar command with various options and examples
○ Archiving places many files into a single targeted file.
○ The tape archiving (tar) command is used for archiving the files in
linux.
○ It supports compression using gzip, gunzip, bzip & bunzip.
○ Basic syntax of tar command :
tar [options] [archive-file] [file or directory to be archived]
■ [options] - Optional flags or settings that modify the behavior of
the tar command.
■ [archive-file] - The name of the archive file you are creating or
working with(usually with a .tar, .tar.gz, or .tar.bz2 extension).
■ [file or directory to be archived] - The file or directory you want
to include in the archive.
○ Following are the various options that come with the tar command:
■ -c : create archive
■ -v : verbose mode (displays the progress and the names of the
files being processed)
■ -f : archive name
■ -t : lists the contents
■ -x : extract the contents
■ -z : used for gzip compression
■ -j : used for bzip compression
○ Following are some common tar commands:
■ Creating an archive -
Ex. tar -cvf archive.tar file1 file2
■ Viewing contents of an archive -
Ex. tar -tvf archive.tar
■ Extracting an Archive -
Ex. tar -xvf archive.tar
■ Using gzip compression -
Ex. tar -czvf archive.tar.gz directory1
■ Using bzip2 compression -
Ex. tar -cjvf archive.tar.bz2 directory2

36. Explain disk related commands in Linux


○ df (Disk Free) - The df command is used to display the amount of disk
space used and available on filesystems.
Syntax: df [options]
○ Following are some common options:
■ Display sizes in human-readable format
Syntax: df -h
print sizes in human readable format (e.g.,KB,MB,GB)
■ Restrict the output to local filesystems only
Syntax: df -l
It excludes any remote filesystems (like NFS, SMB, etc.) from the
report.
■ Displays all filesystems
Syntax: df -a
Shows all filesystems, including pseudo and virtual filesystems
○ du (Disk Usage) - The du command estimates and displays the disk
space used by files and directories.
Syntax: du [options]
Displays the memory of files residing in the current working directory.
○ Following are some common options
■ Display in Human readable format
Syntax: du -h
■ Show sizes for all files, not just directories
Syntax: du -a
■ Display only the total size for each argument.
Syntax: du -s

37. Explain fdisk


○ The fdisk (Partition Table Manipulator) command is used to manipulate
disk partition tables.
○ Following are some common options
■ List Partitions
Syntax: fdisk -l /dev/sda
lists the partition table for the specified device. This includes
information such as partition sizes, types, and IDs.
■ Print Partition Table
Syntax: fdisk /dev/sda
Command (m for help): p
prints the current partition table for the specified device. (same
as fdisk -l)
■ Create New Partition
Syntax: fdisk /dev/sda
Command (m for help): n
■ Write Partition Table
Syntax: fdisk /dev/sda
Command (m for help): w
writes the changes made to the partition table to the disk.
■ Toggle Partition Type
Syntax: fdisk /dev/sda
Command (m for help): t
allows you to specify a different filesystem type for the selected
partition.
■ Delete Partition
Syntax: fdisk /dev/sda
Command (m for help): d
specify which partition you want to delete.

38. Explain Making a File System in Linux


○ The mkfs command in Linux is used to create a filesystem on a
specified storage device or partition.
○ Syntax: mkfs [options]
○ Following are the options
■ Specify Block Size
Syntax: mkfs -b 4096 /dev/sda1
■ Specify Bits/Inode Ratio
Syntax: mkfs -i 16384 /dev/sda1
■ Specify Number of Inodes Reserved for the Filesystem
Syntax: mkfs -N 1000 /dev/sda1
■ Specify Percentage of Reserved Blocks
Syntax: mkfs -m 10 /dev/sda1
■ Set the Label
Syntax: mkfs -L MyData /dev/sda1
■ Create Ext3 Journal Inode
Syntax: mkfs -j /dev/sda1
■ Specify Filesystem Type
Syntax: mkfs -t ext4 /dev/sda1

39. Explain mount command with options


○ The mount command in Linux is used to attach filesystems to a
specified directory in the directory tree, making them accessible to
the system and users.
○ Syntax: mount [options] <device name> <mount point>
<device name> The filesystem (device or file) to be mounted
<mount point> The directory where the filesystem will be
mounted
○ Following are some options
■ Specify Filesystem Type
Syntax: mount -t ext4 /dev/sda1 /mnt/data
Common types include ext4, ntfs, vfat, nfs, etc.
■ Mount All Filesystems
Syntax: mount -a
mount all filesystems listed in /etc/fstab (the filesystem table)
that are not currently mounted.
■ Read-Only mount
Syntax: mount -r /dev/sda1 /mnt/data
mounts the filesystem in read-only mode.
■ Specify various mount options
Syntax: mount -o <options like ro, rw, noexec, nosuid,
bind> /dev/sda1 /mnt/data
Multiple options can be separated by commas.
■ Remount a Filesystem
Syntax: mount -o remount,rw /mnt/data
Remounts a filesystem with different options without unmounting
it.

40. Explain how to manage a Linux system remotely


Linux is a great system when it comes to doing remote administration. You
can connect to a remote system using many different techniques. Here are the
most common ones:
○ Telnet : This command will enable you to connect to another computer
and establish a shell session. You will then be able to enter commands
just as if you were directly in front of the remote computer.
○ Ssh: ssh is more or less the same thing as telnet except it is a more
secure way of doing it. Telnet uses clear text authentication and no
encryption. Ssh is using a more secure authentication mechanism that
can even use security public certificates and it then encrypts the
whole session.
○ Ftp: The ftp command enables you to connect to an ftp server enabled
machine and manage files. This is a very common technique on the
internet and most people don’t really know about its potential. Ftp
stands for File Transfer Protocol and can move files from one
computer to another. It contains many commands that you should
have basic knowledge of.
○ You can also redirect an Xwindows session or use a remote desktop
software like AT&T’s VNC.

41. Write a note on init levels (run levels ) in Linux.


○ Init levels, also known as run levels, are predefined states that
determine what services and processes should be running on a Linux
system at a given time.
○ A runlevel is defined when the computer starts up.
○ When it boots, Linux starts the kernel which loads a first process
called init.
○ This process monitors the system run state and then consults the init
table (located at /etc/inittab) to start daemons and the other
processes.
○ The init table file contains information on the runlevel.
○ There are 7 levels:
■ Run Level 0 - Shuts down/halts the system (Do NOT set
initdefault to this)
■ Run Level 1 - Used for system maintenance; only the root user
has access. (Single User mode)
■ Run Level 2 - Multi-user mode without networking (NFS)
■ Run Level 3 -(Full Multiuser Mode) A common mode for servers
without a graphical interface (CLI only)
■ Run Level 4 - Unused/Custom
■ Run Level 5 - Provides a graphical user interface (GUI), often
used for desktop systems.
■ Run Level 6 - Reboots the system. (Do NOT set initdefault to this)

Network Configuration

42. Explain standard Network troubleshooting tools in Linux


Linux, being based on one of the oldest network operating systems (UNIX),
is loaded with standard troubleshooting tools. Some of these tools are:
○ Ping - the ping utility enables you to verify basic connectivity between
two machines.
○ Route - the route utility helps you take a look at the various routes
defined within the Kernels routing table. You will be able to add,
delete, and modify routing information here. This is very helpful when
using your Linux box as a router or firewall.
○ Traceroute - this utility enables you to see every router between your
Linux machine and a given host. This way it is possible to see any
failing point between you and this host
○ Netstat - this utility helps you see your network interfaces statistics.
○ Lsof - this utility lets you see any open files.
○ Ifconfig - this utility lets you see your network interfaces and modify
certain settings.

43. Explain mii tool


○ mii-tool is a command-line utility which allows a system administrator
to view, monitor, log and change the negotiated speed of Ethernet
network cards.
○ It is especially useful for system administrators managing network
hardware that supports the MII (Media Independent Interface)
standard.
○ Not all Ethernet cards are compatible with mii-tool; it only works with
cards that have compatible chipsets.
○ It displays information such as the negotiated speed, auto-negotiation
status, and available capabilities of the network card.
○ Following are some of the basic usage of mii tool
■ Check the status
Syntax: mii-tool
Displays the status of all network interfaces supporting MII.
■ Viewing Ethernet Interface Details
Syntax: mii-tool -v eth0
This displays detailed information about the eth0 interface,
including Negotiated speed, Product information,
Auto-negotiation status, Link status.
■ Force settings
Syntax: mii-tool -F 10baseT-HD eth0
Forces the interface to 10Mbps half-duplex mode.

44. Explain the working of any four Network Management commands in


Linux
○ ping
■ Ping stands for Packet Internet grouper which is used to test
TCP/IP connectivity
■ When you run ping followed by a hostname or IP address:
$ping www.google.com
■ The command sends ICMP Echo Requests to the specified host
and waits for responses.
■ The default behavior of ping is to send a 64 byte ICMP packet to
the specified host very second until you cancel the operation
with Ctrl-C.
■ When the ping operation is canceled will report summary
statistics such as average packet loss, number of packets sent/
received,time taken for each packet, helping diagnose
connectivity issues or latency problems.
○ traceroute
■ The traceroute command will attempt to show the path of routers
network packets take between the local system and a remote
system showing each hop along the path.
■ Syntax: traceroute example.com
■ The command sends packets with increasing time-to-live (TTL)
values to the destination. Each hop (router) along the way
responds until the destination is reached. This reveals the route
and latency for each hop.
■ Used to diagnose routing issues and identify where delays or
problems occur in the network path.
■ This command by default uses UDP not ICMP.
○ ifconfig
■ Configures and displays network interface information.
■ When executed, it shows details such as IP address, netmask,
broadcast address, and MAC address for each interface.
■ It can also be used to enable or disable interfaces:
ifconfig eth0 up # Activates the eth0 interface
ifconfig eth0 down # Deactivates the eth0 interface
■ Primarily used for configuring older network setups, but it has
been mostly replaced by the ip command in modern Linux
distributions.
○ netstat
■ Displays network connections, routing tables, interface
statistics, and listening ports, helping to monitor network
performance and troubleshoot connectivity issues.
■ When you run,
netstat -an
The command shows all active connections and listening ports
with addresses in numeric form. It displays the protocol type
(TCP/UDP), local and remote addresses, and connection status.
■ You can also view the routing table using:
netstat -r
This displays routes and gateways configured on the system,
helping to understand how traffic is being routed.
■ Used to monitor network activity, inspect open ports, and
troubleshoot routing or connectivity problems in real-time.

Shell Scripting
45. What are Shell Scripts?
○ Shell scripts are the files that contain a series of commands to be
executed.
○ Shell scripts are used for automating commonly used commands,
performing system administration tasks and also for creating simple
applications while creating the shell scripts.
○ The first line contains #! (shebang sequence) followed by the path to
the interpreter. For ex.
■ #!/bin/bash : used for bash scripts.
■ #!/bin/sh : used for bourne shell scripts.
■ #!/bin/csh : used for c shell scripts.
■ #!/usr/bin/perl : used for perl shell scripts.
■ #!/usr/bin/python : used for python shell scripts
○ Shell scripts files have the extension “.sh”.
○ Scripts files are executed with the command:
#sh filename.sh
#./ filename.sh
○ For executing the script files, user should have execute permission:
chmod +x script.sh
○ # is used to write commands in shell scripts.

46. Variables
○ You can define and use variables to store data or command output.
○ There should be no spaces around the = sign.
Syntax: variable_name=value
Ex. name="Alice"
age=25
○ To access the value of a variable, prepend it with $:
echo $name # Outputs: Alice
echo $age # Outputs: 25
○ Preserves spaces and special characters using double quotes
message="Welcome to Shell Scripting"
echo "$message" # Preserves spaces
○ Arithmetic operations can be performed using $(( )) syntax:
num1=5
num2=3
sum=$((num1 + num2))
echo $sum # Outputs: 8
○ read command accepts input from the user and stores it in a variable:
read -p "Enter your name: " user_name
echo "Hello, $user_name!"
○ Using -s with read for silent input (useful for passwords)
read -s -p "Enter password: " password

47. Control Structures


○ Shell scripts support control structures such as if-else statements,
loops, and case statements to perform conditional and repeated tasks.
○ If-else
■ Syntax:
if condition; then
#commands
else
#commands
fi
■ Example:
if [ -f /etc/passwd ]; then
echo "File exists"
else
echo "File does not exist"
fi
○ for loop
■ Syntax:
for <var> in <value1 value2 ... valuen>; do
<command 1>
<command 2>
<etc>
done
■ Example:
for i in 1 2 3; do
echo "Number: $i"
done
○ While Loop
■ Syntax:
while [ condition ]; do
# Code to execute
done
■ Example:
counter=1
while [ $counter -le 5 ]; do
echo "Count: $counter"
((counter++))
done
○ until loop
■ Syntax:
until <condition>; do
<command 1>
<command 2>
<etc>
done
■ Example:
counter=1
until [ $counter -gt 5 ]; do
echo "Count: $counter"
((counter++))
done
48.

You might also like