Unix and Shell Programming
Unix and Shell Programming
1. Internal Commands
● Built into the shell (e.g., bash, sh, zsh).
● Do not require an external program to run.
● Execute faster because they do not need to load from disk.
● Used for simple file, directory, and process management.
2. External Commands
● Stored as separate executable files in system directories like /bin, /usr/
●
bin, and /sbin.
● The shell finds them using the PATH environment variable.
● Can be system utilities or user-installed programs.
● Run slower than internal commands because they require disk access.
Examples of External Commands
Command Description
ls List directory contents.
cp Copy files and directories.
mv Move or rename files.
rm Delete files or directories.
grep Search text in files.
find Locate files in directories.
awk Text processing tool.
wget Download files from the internet.
tar Archive files.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Summary of Cal(calendar) Command Options—>
Command Description
cal Shows the current month's
calendar.
cal 2025 Displays the calendar for the year
2025.
cal 07 2024 Shows the calendar for July 2024.
cal -m Starts the week on Monday instead
of Sunday.
cal -j Displays Julian days.
cal -h Highlights the current date.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Summary of date Command Options—>
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Summary of echo Command Option—>
The echo command is used to display messages, variable values, and
formatted text in the terminal.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Calculator (bc)—>The bc (Basic Calculator) command is a command-line
calculator in UNIX/Linux used for performing arithmetic operations, including
floating-point calculations.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Summary of passwd Commands—>
In UNIX/Linux, the passwd command is used to change the password of a user
account.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Knowing who are logged in (who)—>
The who command is used to display information about users currently logged
into the system.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
System Information using uname—>
The uname command is used to display system information such as the OS
name, kernel version, and hardware details.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
tty Command in UNIX/Linux—>
The tty command is used to display the file name of the terminal connected to
the standard input (stdin).
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Unix File System
Unix File System is a logical method of organizing and storing large amounts
of information in a way that makes it easy to manage. A file is the smallest unit
in which the information is stored. Unix file system has several important
features. All data in Unix is organized into files. All files are organized into
directories. These directories are organized into a tree-like structure called the
file system. Files in Unix System are organized into multi-level hierarchy
structure known as a directory tree. At the very top of the file system is a
directory called “root” which is represented by a “/”. All other files are
“descendants” of root.
The Unix file system is a hierarchical file system used by Unix-based operating
systems to store and organize files and directories. It is a tree-like structure
that starts with a single directory called the root directory, which is denoted by
a forward slash (/) character.
The Unix file system uses a directory hierarchy that allows for easy navigation
and organization of files. Directories can contain both files and other
directories, and each file or directory has a unique name.
Unix file system also uses a set of permissions to control access to files and
directories. Each file and directory has an owner and a group associated with it,
and permissions can be set to allow or restrict access to these entities.
One of the most important features of the Unix file system is its support for
symbolic links, which are pointers to other files or directories. This allows for
flexible organization of files and directories without having to physically move
them around.
Ordinary Files
An ordinary file is a file on the system that contains data, text, or program
instructions.
● Used to store your information, such as some text you have written or an
image you have drawn. This is the type of file that you usually work with.
● Always located within/under a directory file.
● Do not contain other files.
● In long-format output of ls -l, this type of file is specified by the “-” symbol.
Directories
Directories store both special and ordinary files. For users familiar with
Windows or Mac OS, UNIX directories are equivalent to folders. A directory file
contains an entry for every file and subdirectory that it houses. If you have 10
files in a directory, there will be 10 entries in the directory. Each entry has two
components. (1) The Filename (2) A unique identification number for the file or
directory (called the inode number)
● Branching points in the hierarchical tree.
● Used to organize groups of files.
● May contain ordinary files, special files or other directories.
● Never contain “real” information which you would work with (such as text).
Basically, just used for organizing files.
● All files are descendants of the root directory, ( named / ) located at the top
of the tree.
In long-format output of ls –l , this type of file is specified by the “d” symbol.
Special Files
Used to represent a real physical device such as a printer, tape drive or
terminal, used for Input/Output (I/O) operations. Device or special files are
used for device Input/Output(I/O) on UNIX and Linux systems. They appear in a
file system just like an ordinary file or a directory. On UNIX systems there are
two flavors of special files for each device, character special files and block
special files :
● When a character special file is used for device Input/Output(I/O), data is
transferred one character at a time. This type of access is called raw device
access.
● When a block special file is used for device Input/Output(I/O), data is
transferred in large fixed-size blocks. This type of access is called block
device access.
For terminal devices, it’s one character at a time. For disk devices though, raw
access means reading or writing in whole chunks of data – blocks, which are
native to your disk.
● In long-format output of ls -l, character special files are marked by the “c”
symbol.
● In long-format output of ls -l, block special files are marked by the “b”
symbol.
Pipes
UNIX allows you to link commands together using a pipe. The pipe acts a
temporary file which only exists to hold data from one command until it is read
by another.A Unix pipe provides a one-way flow of data.The output or result of
the first command sequence is used as the input to the second command
sequence. To make a pipe, put a vertical bar (|) on the command line between
two commands.For example: who | wc -l In long-format output of ls –l , named
pipes are marked by the “p” symbol.
Sockets
A Unix socket (or Inter-process communication socket) is a special file which
allows for advanced inter-process communication. A Unix Socket is used in a
client-server application framework. In essence, it is a stream of data, very
similar to network stream (and network sockets), but all the transactions are
local to the filesystem. In long-format output of ls -l, Unix sockets are marked
by “s” symbol.
Symbolic Link
Symbolic link is used for referencing some other file of the file system.Symbolic
link is also known as Soft link. It contains a text form of the path to the file it
references. To an end user, symbolic link will appear to have its own name, but
when you try reading or writing data to this file, it will instead reference these
operations to the file it points to. If we delete the soft link itself , the data file
would still be there.If we delete the source file or move it to a different location,
symbolic file will not function properly. In long-format output of ls –l , Symbolic
link are marked by the “l” symbol (that’s a lower case L).
●
● Parent Process ID (PPID) → The ID of the parent process.
Example usage:
● Shell commands:
When you run a command in a shell, the shell process creates a new child
process to execute that command.
● Background processes:
By using the "&" operator, you can create a child process that runs in the
background, allowing the parent process to continue execution.
Process Creation in UNIX—>
When a process is created, it follows these steps:
. The parent process calls fork(), which duplicates the process.
. The child process runs independently of the parent.
. The child can execute a different program using exec().
. The parent waits for the child process to complete using wait().
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
HOME Variable in UNIX—>
The HOME variable in UNIX/Linux represents the home directory of the
currently logged-in user. It is an environment variable that stores the absolute
path of the user’s home directory.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Changing the Current Directory (cd) in UNIX-->
The cd (change directory) command is used to navigate between directories
in UNIX/Linux.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Creating Directories (mkdir) in UNIX—>
The mkdir (make directory) command is used to create new directories
(folders) in UNIX.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Removing Directories (rmdir) in UNIX—>
The rmdir (remove directory) command is used to delete empty directories
in UNIX/Linux.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Listing Contents of a Directory (ls) in UNIX/Linux—>
The ls (list) command is used to display the contents of a directory in UNIX.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Important File Systems in UNIX/Linux—>
UNIX follows a hierarchical file system where directories serve specific
purposes.
Directory Purpose
/bin Essential system binaries
(e.g., ls, cp, mkdir) for all
users.
/usr/bin Additional system binaries for
regular users (e.g., python,
git).
/sbin System binaries for
administrators (e.g., fdisk,
reboot).
/usr/sbin Extra admin tools (e.g.,
/usr/bin Additional system binaries for
regular users (e.g., python,
git).
/sbin System binaries for
administrators (e.g., fdisk,
reboot).
/usr/sbin Extra admin tools (e.g.,
apachectl, ufw).
/etc System configuration files
(e.g., /etc/passwd, /etc/fstab).
/dev Device files (hardware
access) like disks, USB (/dev/
sda).
/lib System libraries needed by
binaries in /bin and /sbin.
/usr/lib Libraries for programs in /usr/
bin and /usr/sbin.
/usr/include C/C++ header files for
software development.
/usr/share/man Manual (man) pages for
commands (man ls).
/tmp Temporary files (deleted on
reboot).
/var Variable data (logs, emails,
databases, print jobs).
/home User home directories (e.g., /
home/sayan/).
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Displaying and Creating Files using cat in UNIX/Linux—>
The cat (concatenate) command is used to create, view, and concatenate
files.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Copying a File Using cp in UNIX/Linux—>
The cp (copy) command is used to copy files and directories.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Deleting a File Using rm in UNIX—>
The rm (remove) command is used to delete files and directories.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Renaming / Moving a File Using mv in UNIX—>
The mv (move) command is used to rename or move files and directories.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Paging Output Using more in UNIX/Linux—>
The more command is used to view large files page by page instead of
displaying everything at once.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Printing a File Using lp in UNIX/Linux—>
The lp (line printer) command is used to send files to the printer for printing.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Knowing File Type Using file in UNIX—>
The file command is used to determine the type of a file in UNIX.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Word and Character Counting Using wc in UNIX—>
The wc (word count) command is used to count lines, words, and characters
in a file.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Comparing Files Using cmp in UNIX—>
The cmp (compare) command is used to compare two files byte by byte and
find differences.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Finding Common Lines Between Two Files Using comm in UNIX—
>
The comm (common) command is used to compare two sorted files line by
line and find:
. Unique lines in file1
. Unique lines in file2
. Common lines in both files
Requirement: Both files must be sorted before using comm.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Displaying File Differences Using diff in UNIX—>
The diff (difference) command compares two text files line by line and shows
the differences.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Creating an Archive File Using tar in UNIX—>
The tar (tape archive) command is used to create, extract, and manage archive
files in UNIX/Linux.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Compressing Files Using gzip in UNIX—>
The gzip (GNU Zip) command is used to compress files in UNIX/Linux, reducing
their size.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Uncompressing Files Using gunzip in UNIX—>
The gunzip (GNU Unzip) command is used to decompress files that were
compressed using gzip.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Archiving and Compressing Files Using zip in UNIX—>
The zip command is used to create compressed .zip archives in UNIX/Linux.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Extracting Compressed Files Using unzip in UNIX—>
The unzip command is used to extract files from a .zip archive in UNIX/Linux.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Effect of cp, rm, and mv Commands on Directories in UNIX—>
1. cp (Copy Command) and Directories
● By default, cp does not copy directories unless the -r (recursive) option is
used.
● Example (Copy a directory and its contents):
cp -r source_directory destination_directory/
Effect: Creates a duplicate of source_directory inside
●
destination_directory.
2. Breakdown of Attributes
Field Example Description
File Type - or d - (file), d (directory), l
(symbolic link)
Permissions rw-r--r-- Read (r), Write (w),
Execute (x) for User,
Group, and Others
Links 1 Number of hard links
Field Example Description
File Type - or d - (file), d (directory), l
(symbolic link)
Permissions rw-r--r-- Read (r), Write (w),
Execute (x) for User,
Group, and Others
Links 1 Number of hard links
to the file
Owner user Username of the file
owner
Group group Group to which the file
belongs
Size 1024 File size in bytes
Date & Time Feb 10 12:00 Last modified date and
time
File Name file.txt Name of the file or
directory
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
File Ownership in UNIX—>
Every file and directory in UNIX/Linux has an owner and belongs to a group.
Ownership defines who can access and modify a file.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
File Permissions in UNIX—>
File permissions in UNIX/Linux control who can read, write, or execute a file or
directory.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Changing File Permissions in UNIX—>
There are two ways to change file permissions:
. Relative Permission (Symbolic Mode)
. Absolute Permission (Octal Mode)
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Hard Link vs Soft Link in UNIX—>
A link in UNIX/Linux is a way to create multiple references to the same file.
Links help manage files efficiently without duplicating data.
There are two types of links:
. Hard Link – Points directly to the same inode as the original file.
. Soft Link (Symbolic Link) – Points to the file name (path), not the inode.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Significance of File Attributes for a Directory in UNIX—>
File attributes in a directory define access control and functionality, ensuring
security and proper file management. Their significance includes:
. Access Control – Permissions (r, w, x) determine who can read, modify, or
enter a directory.
. File Management – Determines whether users can list files (ls), create new
files, or delete existing ones.
. Security Enforcement – Restricts unauthorized users from modifying or
accessing sensitive data.
. User & Group Ownership – Defines which user or group has control over
directory contents.
. Navigation Control – Execute (x) permission allows users to cd into a
directory, even if they cannot list its contents.
. Preventing Accidental Deletion – If a directory lacks w permission, files
inside cannot be deleted or modified.
. File System Integrity – Ensures only authorized processes can alter
system-critical directories (e.g., /etc, /var).
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Default Permissions of Files and Directories & Using umask in
UNIX—>
1. Default Permissions of Files and Directories
When a new file or directory is created, it is assigned default permissions
based on the system's default settings.
● Default File Permissions → rw-r--r-- (Readable & writable by the owner,
readable by others)
● Default Directory Permissions → rwxr-xr-x (Owner has full access, others
can read & enter)
However, these are not absolute defaults—they are determined by a setting
called umask.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Changing File Timestamps with touch Command in UNIX—>
The touch command is commonly used to update file timestamps or create new
empty files. You can modify the access time (atime) and modification time
(mtime) of a file using touch.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
File Locating with the find Command in UNIX—>
The find command is one of the most powerful tools for searching files and
directories on your system. It allows you to search based on various criteria like
file name, type, size, permissions, and timestamps.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Interpretive Cycle of the Shell in UNIX—>
The interpretive cycle refers to the sequence of steps that the shell follows to
interpret and execute commands that a user inputs into the terminal. The shell
acts as an interface between the user and the operating system, translating
user commands into actions that the operating system can understand and
execute.
The interpretive cycle is often described as a sequence of steps that the shell
follows to process a command. Here's an overview of the interpretive cycle of
the shell:
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Types of Shells in UNIX—>
In UNIX and Linux systems, the shell is a program that provides an interface for
users to interact with the operating system. It interprets and executes user
commands. Different types of shells offer varied features, scripting capabilities,
and user interfaces.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻
Pattern Matching in UNIX/Linux
Pattern matching is a mechanism used in UNIX/Linux systems to match files or
strings based on a specific pattern, often using wildcards or regular
expressions. It allows users to search for specific files, strings, or content
within files efficiently.
There are two primary types of pattern matching in UNIX/Linux systems:
1. Wildcard Pattern Matching (Globbing)
Wildcards are characters that allow you to match file names or parts of file
names in the terminal. The most common wildcards are:
● * (Asterisk):
○ Matches any string of characters, including an empty string.
○ Example: *.txt will match all files that end with .txt.
● ? (Question Mark):
○ Matches exactly one character.
○ Example: file?.txt will match file1.txt, fileA.txt, but not file10.txt.
● [] (Square Brackets):
○ Matches any one character within the specified range or set of
characters.
○ Example: file[1-5].txt will match file1.txt, file2.txt, ..., file5.txt.
● [!...] or [^...] (Negation in Square Brackets):
○ Matches any character except those within the brackets.
○ Example: file[!1-5].txt will match files like fileA.txt, fileX.txt, but not
file1.txt, file2.txt, etc.
Escaping Mechanism
In UNIX/Linux, the backslash (\) is the most commonly used escape character. It
is used to escape characters that would otherwise have special meanings.
Common Use Cases for Escaping:
. Escaping Special Characters:
○ If you want to include characters like spaces, parentheses, or dollar
signs in a string, you use the backslash (\).
. Examples:
○ Space: My\ File.txt (This represents a file with a space in its name: My
File.txt)
○ Dollar Sign: \$5 (This prevents the shell from interpreting $5 as a
variable.)
○ Parentheses: \(\) (This prevents the shell from interpreting the
parentheses as grouping symbols.)
. Escaping Quotes:
○ If you want to include single quotes (') or double quotes (") inside a
string surrounded by the same type of quote, you need to escape the
quote.
. Examples:
○ Single Quote Inside Single Quote: 'It\'s a good day'
○ Double Quote Inside Double Quote: "He said, \"Hello!\""
. Escaping Backslashes:
○ To include a backslash (\) in your string, you need to escape it with
another backslash (\\).
. Example:
○ C:\\Windows\\System32
Uses of /dev/null
1. Discarding Unwanted Output—>
If you don’t want to display the output of a command, redirect it to /dev/null.
ls > /dev/null
● The output of ls is discarded.
Uses of /dev/tty
1. Sending Messages to the User's Terminal—>
Even if output is redirected, you can force display on the terminal using /dev/
tty.
echo "Hello, User!" > /dev/tty
● This ensures the message appears only in the user's terminal.
2. Identifying Your Current Terminal—>
To check which terminal you're using:
tty
● Example output:
/dev/pts/0
time).
○ The process is actively executing instructions or is waiting to
○
execute.
. Sleeping (S)
○ The process is waiting for some event, like user input or I/O
SIGTSTP).
○ It can be resumed later.
. Zombie (Z)
○ Zombie state occurs when a child process has completed
. Defunct (D)
○ Sometimes used interchangeably with Zombie, the process is not
executing but has not been completely removed from the process
table.
Syntax:
command &
Example:
sleep 100 &
This runs the sleep command for 100 seconds in the background. The shell will
immediately return the prompt, allowing you to run other commands.
Syntax:
nohup command &
Example:
nohup sleep 1000 &
This command will run the sleep command for 1000 seconds in the
background, and the output will be saved to nohup.out.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻⸻⸻
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻⸻⸻
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻⸻⸻
Sending Jobs to Background and Foreground in UNIX/Linux
In UNIX/Linux, you can manage running processes by placing them in the
background or bringing them to the foreground. This allows you to continue
using the terminal while a process runs in the background or bring it back into
the foreground to interact with it.
Background Jobs (bg Command)
● bg is used to resume a suspended job in the background, allowing it to
continue running while freeing up the terminal for other tasks.
● If a job is paused (stopped), you can send it to the background using the bg
command.
Foreground Jobs (fg Command)
● fg is used to bring a background job back into the foreground, allowing
you to interact with it directly.
Job Control Commands Overview:
● &: Starts a command in the background.
● bg: Resumes a stopped job in the background.
● fg: Brings a background job to the foreground.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻⸻⸻
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻⸻⸻
Environment Variables in UNIX—>
Environment variables are variables that are defined outside the application or
script and are available system-wide for programs to use. These variables store
important information about the system environment and configuration, such as
the user’s home directory, system paths, and terminal settings.
Usage of Environment Variables:—>
. Configuring System Behavior:
○ Environment variables like PATH, TERM, and HOME influence how the
shell and applications behave, such as where to search for commands
or how to display output.
. Customizing the Command Prompt:
○ By modifying PS1 and PS2, you can change the look of your terminal
prompt, adding useful information like the current directory, username,
or system name.
. System Info for Applications:
○ Programs can access environment variables like USER, LOGNAME, and
HOME to get the current user's information or file paths.
. Storing System Configuration:
○ Many applications rely on environment variables for configuration, such
as TERM for terminal settings or PATH for locating commands.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻⸻⸻
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻⸻⸻
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻⸻⸻
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻⸻⸻
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻⸻⸻
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻⸻⸻
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻⸻⸻
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻⸻⸻
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻⸻⸻
Searching Patterns using grep:
The grep command is used to search for a specific pattern in a file.
Syntax:
grep 'pattern' file_name
Example:
grep 'hello' file.txt # Searches for the word "hello" in file.txt
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻⸻⸻
Basic Regular Expression (BRE), Extended Regular Expression
(ERE), and egrep:—>
● Basic Regular Expression (BRE): Used with grep to perform pattern
matching. The syntax for patterns is simpler (e.g., * is used as \*).
● Extended Regular Expression (ERE): Offers more advanced pattern
matching (e.g., * works without escaping, | for OR).
● egrep: An extended version of grep that supports ERE.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻⸻⸻
Using grep -E (Extended Regex with grep)—>
The grep -E option allows the use of extended regular expressions (ERE)
directly with grep.
Example:
grep -E 'a|b' file.txt # Searches for lines containing 'a' or 'b' in file.txt
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸺
⸻⸻⸻
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻—
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻—
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻—
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻—
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻—
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻—
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻—
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻—
Essential Duties of a UNIX System Administrator—>
A UNIX system administrator is responsible for managing and maintaining
UNIX-based systems. Their primary duties include:
. System Maintenance
○ Installing, updating, and configuring UNIX/Linux operating systems.
○Applying security patches and system updates.
. User Account Management
○ Creating, modifying, and deleting user accounts.
○ Managing user groups, passwords, and permissions.
. File System Management
○ Monitoring disk usage and managing disk quotas.
○ Maintaining file systems and partitions.
. Process Management
○ Monitoring system processes using commands like ps, top, and kill.
○ Managing system performance and load balancing.
. System Security
○ Implementing user authentication and access control.
○ Configuring firewalls and monitoring security logs.
. Backup and Recovery
○ Setting up automated backups using tools like tar, rsync, or cron jobs.
○ Restoring system data in case of failures.
. Network Configuration
○ Managing network interfaces and troubleshooting connectivity issues.
○ Configuring services like SSH, FTP, and DNS.
. System Startup and Shutdown
○ Controlling system boot processes using init, systemd, or rc scripts.
○ Gracefully shutting down or rebooting the system using shutdown,
reboot, or halt.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻—
Starting and Shutting Down UNIX—>
. Starting UNIX System
○ The system starts with the boot loader (like GRUB).
○ The kernel initializes hardware and system processes.
○ The init/systemd process starts user services and login prompts.
. Shutting Down UNIX System
○ shutdown -h now → Immediately shuts down the system.
○ shutdown -r now → Reboots the system.
○ halt → Stops the system.
○ reboot → Restarts the system.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻—
User Account Management—>
UNIX user accounts control access to system resources. Admins manage users
using commands like useradd, passwd, and usermod.
. Username
○ Each user has a unique login name.
○ Stored in /etc/passwd.
. Password
○ Passwords are encrypted and stored in /etc/shadow.
○ Changed using the passwd command.
. Home Directory
○ Default directory assigned to a user (e.g., /home/username).
○ Created when the user account is added.
. Group ID (GID)
○ Users belong to groups for permission control.
○ Groups are managed in /etc/group.
. Disk Quota
○ Limits the amount of disk space a user can use.
○ Managed using quota commands.
. Terminal
○ Defines how a user interacts with the system (e.g., /dev/tty1).
○ Can be checked using tty command.
⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻⸻—