Linux - Reference Notes For Job Seekers & Students
Linux - Reference Notes For Job Seekers & Students
Notes
[Digital Copy]
Institute Director(s)
Institute Vision
Linux
• Linux is an open-source operating system kernel that serves as the foundation for
a wide range of Linux distributions, or "distros," each of which offers a complete
operating system built around the Linux kernel.
• Linux is a versatile, open-source operating system with a strong emphasis on
stability, security, and customization.
• Its modular architecture, vast software ecosystem, and active community support
make it a popular choice for a wide range of computing tasks, from personal
desktops to enterprise servers and embedded devices.
About Linux
2. Components
• Kernel: The Linux kernel is the core component of the operating system. It
manages hardware resources, provides essential services to higher-level
software, and facilitates communication between software and hardware
components.
• Utilities: Linux includes a vast array of utilities and software tools, many of
which are provided by the GNU Project, such as file management utilities,
text editors, compilers, and networking tools.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
3. Distributions (Distros)
• Variety: There are hundreds of Linux distributions, each with its own set of
features, package management systems, and target audiences.
• Examples: Some popular Linux distributions include Ubuntu, Debian,
Fedora, CentOS, Arch Linux, and Linux Mint.
6. Package Management
• Repositories: Linux distributions typically provide centralized software
repositories where users can download and install software packages.
• Package Managers: package managers like APT (Advanced Package Tool),
YUM (Yellowdog Updater Modified), Pacman, etc., are specialized software
tools used in Linux distributions to automate the process of installing,
updating, and managing software packages.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
7. Compatibility
• Cross-Platform Support: Linux supports a wide range of hardware
architectures, making it suitable for various devices, from smartphones to
supercomputers.
• Compatibility Layers: Tools like Wine allow Linux users to run some
Windows applications, and compatibility layers like WSL (Windows
Subsystem for Linux) enable Linux software to run on Windows.
8. Challenges
• Hardware Support: While Linux supports a broad range of hardware, some
proprietary hardware may lack official drivers or support.
• Software Compatibility: Although Linux offers alternatives to many
popular software applications, some users may encounter compatibility
issues with certain proprietary software.
• Learning Curve: Transitioning to Linux from other operating systems may
require users to learn new commands, workflows, and concepts.
9. Future Trends
• Containers and Virtualization: Linux is at the core of many
containerization and virtualization technologies, such as Docker and
Kubernetes, which are increasingly used for deploying and managing
applications.
• Cloud Computing: Linux is the dominant operating system in cloud
computing environments, powering a significant portion of servers and
services offered by major cloud providers.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• cd - Change directory
cd [directory]
Example: cd /var/www
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
Amazon EC2
• Amazon Elastic Compute Cloud (Amazon EC2) is a web service provided by
Amazon Web Services (AWS) that offers resizable compute capacity in the cloud.
• It allows users to rent virtual servers, called instances, and run applications on them.
• It is a foundational service in the AWS ecosystem, providing the compute
infrastructure needed to build and deploy applications in the cloud.
• Its flexibility, scalability, and reliability make it a popular choice for businesses of
all sizes.
1. Instances
• An instance is a virtual server in the cloud that you can use to run your
applications.
• Instances can be launched from pre-configured Amazon Machine Images
(AMIs), which are templates that contain the operating system and any
additional software required.
• You can choose from a variety of instance types with different compute,
memory, and storage capabilities to meet the needs of your application.
2. Features
• Elasticity: EC2 allows you to easily scale your compute capacity up or down
based on demand. You can add or remove instances as needed.
• Security: EC2 provides various security features, including security groups
and key pairs, to control access to instances and protect data.
• Flexibility: You have full control over your instances, including the ability to
choose the operating system, configure networking, and install software.
• Integration: EC2 integrates with other AWS services, such as Amazon S3 for
storage, Amazon RDS for databases, and Amazon VPC for networking.
3. Instance Types
• EC2 offers a wide range of instance types optimized for different use cases,
such as general-purpose computing, memory-intensive applications, and
high-performance computing.
• Instance types are categorized based on their compute, memory, storage,
and networking capabilities.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• Launch Instance
In the EC2 Dashboard, click on the "Launch Instance" button to start the instance
creation process.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• Add Storage
Specify the storage options for your instance. You can add one or more Elastic
Block Store (EBS) volumes to store your data. Configure the volume type, size, and
additional options such as encryption.
• Launch Instance
After selecting the key pair, click on the "Launch Instances" button to launch your
EC2 instance.
Now! You have successfully created an EC2 instance in AWS. You can now start using your
instance to deploy and run your applications in the cloud.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
If you are getting the below warning when trying to use aws instance:
Permissions for ‘YourKey.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "YourKey.pem": bad permissions
[email protected]: Permission denied
(publickey,gssapi-keyex,gssapi-with-mic).
The above warning message you're encountering indicates that the permissions on your
.pem file are too open, which makes it insecure for SSH connections. To resolve this issue,
you need to adjust the permissions on your .pem file so that it's only accessible to the
owner.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Best Training Institute
for Graduates
with
Live Online & Offline Classes Available
Amenities
▪ Digital Notes ▪ Working Experience
▪ Live Training Sessions ▪ Job Recommendations
▪ Project Assistance ▪ Professional Development
▪ Interview Preparation ▪ Digital Resume & Portfolio
Linux Commands
• To check the linux commands (in our case), you can either install Fedora or Red
Hat linux distribution in your laptop or using Oracle Virtual Box or any other virtual
machine.
• You can also create an AWS EC2-instance for Red Hat Enterprise Linux to execute
the commands.
Let’s start
1. pwd
• The pwd command in Linux stands for "print working directory."
• It's used to display the current directory you're in within the Linux file
system.
• When you type pwd and hit Enter in a terminal, it will print the absolute path
of the directory you're currently located in.
• This is useful for keeping track of your location within the file system,
especially when navigating between different directories or when scripting
tasks that require knowing the current directory.
Example: $ pwd
Output: /home/ec2-user
• To display a help message explaining how to use the pwd command and its
options use command
$ pwd --help
2. clear
• Once you execute clear, the terminal screen will be blank, and you'll have a
fresh command prompt at the top of the window.
• It's worth noting that clear only affects the display on your terminal window;
it doesn't modify any of your commands or output stored in the terminal's
history or buffer.
• It simply provides a clean interface for entering new commands or viewing
subsequent output.
Example: $ clear
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
3. whoami
• The whoami command in Linux is used to print the username of the current
user who is logged in to the terminal session.
• When you execute whoami in a terminal window, it simply outputs the
username associated with the current session.
• This command is helpful when you need to quickly determine the username
of the current user, especially in scripting or automation tasks where you
may need to perform actions specific to the current user.
Example: $ whoami
Output: ec2-user
4. date
The date command in Linux is used to display or set the current system date and
time. It offers a wide range of options to format and manipulate dates and times.
• Displaying Current Date and Time: When used without any options, the
date command simply displays the current date and time in the default
format.
Example: $ date
Output: Tue Jan 30 15:45:27 UTC 2024
• Date Formatting or Custom Date and Time Format: You can use the +
option followed by a format specifier to customize the output format.
Example: $ date +"%Y-%m-%d %H:%M:%S"
Output: 2024-01-30 15:45:27
• Setting System Date and Time: Superuser privileges (sudo) are required
to set the system date and time.
Syntax: $ sudo date MMDDhhmm[[CC]YY][.ss]
Example: $ sudo date 043015452024.30
Output: Tue Jan 30 3:45:30 PM UTC 2024
where MM relate with the month, DD with the day, hh with the hour, mm
with the minutes, [[CC]YY] with the optional century and year, and [.ss] with
the optional seconds.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
5. ls
• The ls command in Linux is used to list directory contents.
• It displays information about files and directories within the specified directory,
or if no directory is specified, it lists the contents of the current directory.
• With its various options, you can customize the output to display detailed
information, sort files, filter results, and more. Whether you need a simple list
of filenames or detailed information about files, ls provides the flexibility to
meet your needs efficiently.
• List Contents of Current Directory: When used without any options, the ls
command lists the contents of the current directory.
Example: $ ls
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
ls-l command
The ls -l command represents detailed information about files and
directories in a long listing format. Let's break it down:
• File Type
The first character indicates the type of file or directory.
Common file types include:
▪ - for a regular file
▪ d for a directory
▪ l for a symbolic link
▪ c for a character device file
▪ b for a block device file
▪ s for a socket
▪ p for a named pipe (FIFO)
• Permissions
The next nine characters represent file permissions.
Each set of three characters represents permissions for the
owner, group, and others, respectively.
The characters can be:
▪ r for read permission
▪ w for write permission
▪ x for execute permission
▪ - if the respective permission is not granted
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• Number of Links
Following the permissions, there is a number indicating the
count of hard links to the file or directory.
• Owner and Group
After the number of links, you'll see the owner of the file or
directory, followed by the group it belongs to.
• File Size (or Device ID for Special Files)
The next field represents the file size in bytes for regular files.
For special files (e.g., character devices, block devices), this
field represents the major and minor device numbers.
• Last Modified Date
The next field indicates the date and time when the file or
directory was last modified.
• File/Directory Name
Finally, the last field displays the name of the file or directory.
For Example
drwxr-xr-x. 3 user group 4096 Jan 30 10:00 directory_name
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
6. File Creation
There are several commands you can use to create a new file in a Linux terminal.
Here are some commonly used ones:
• touch: The touch command creates an empty file if it doesn't exist. If the
file already exists, it updates the file's access and modification timestamps.
Example: $ touch filename.txt
• echo: You can use echo to create a new file and write content into it
simultaneously. By redirecting echo's output (> or >>), you can create and
write content to the file.
Example:
echo "Hello, world!" > filename.txt # Create or overwrite content to a file
echo "Additional text" >> filename.txt # Append content to a file
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• cat: The cat command can be used to create a new file and write content
into it. You can use the output redirection operator (>) to create the file and
write content into it.
Example: $ cat > filename.txt
After executing the command, you can start typing the content you want to
write to the file. Press Ctrl + D when you're finished.
• nano: The nano command opens a simple text editor in the terminal,
allowing you to create and edit files interactively.
Example: $ nano filename.txt
Use the arrow keys to navigate, type your content, and press Ctrl + X to exit.
If you made any changes, it will prompt you to save them before exiting.
If the nano command is not found on your system, it means that the nano
text editor is not installed. You can install it using the package manager of
your Linux distribution.
You can use any of the following commands depending upon your platform
requirements:
Debian/Ubuntu:
sudo apt-get update
sudo apt-get install nano
CentOS/RHEL:
sudo yum install nano
Fedora:
sudo dnf install nano
• vim: The vim command is a powerful text editor that can be used to create
and edit files. You can open a new or existing file with vim.
Example: $ vim filename.txt
Press i to enter insert mode, type your content, and press Esc followed by
:wq to save and exit (:q! to quit without saving).
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
If the vim command is not found on your system, it means that the Vim text
editor is not installed. You can install it using the package manager of your
Linux distribution.
You can use any of the following commands depending upon your platform
requirements:
Debian/Ubuntu:
sudo apt-get update
sudo apt-get install vim
CentOS/RHEL:
sudo yum install vim-enhanced
Fedora:
sudo dnf install vim
sudo
• sudo stands for "superuser do."
• It's a command used in Unix-like operating systems, including Linux, to
allow a permitted user to execute commands as the superuser or another
user, as specified by the security policy.
• The superuser, often called "root," has unrestricted access to all files and
commands on the system.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• echo: The echo command is used to display a line of text. By redirecting its
output using > or >>, you can write content to a file.
Example:
echo "Hello, world!" > filename.txt # Write or overwrite content to a file
echo "Additional text" >> filename.txt # Append content to a file
• printf: The printf command allows more control over formatting compared
to echo. Similar to echo, you can redirect its output to a file.
Example:
printf "Hello, world" > filename.txt # Write or overwrite content to a file
printf "New line" >> filename.txt # Append content to a file
To insert multiple lines into a file using echo or printf commands in Linux,
you can use the newline character (\n) to separate each line. Here's how you
can do it:
Using echo:
echo -e "Line 1\nLine 2\nLine 3" > filename.txt
Using printf:
printf "Line 1\nLine 2\nLine 3\n" > filename.txt
• cat: The cat command can be used to concatenate files, but it's also
commonly used to create or append to a file.
Example: $ cat > filename.txt
After executing this command, you can start typing the content you want to
write to the file. Press Ctrl + D when you're finished. To append to an
existing file, use >> instead of >.
• touch: The touch command is primarily used to update the access and
modification timestamps of a file. However, if the specified file doesn't exist,
it will create an empty file.
Example: $ touch filename.txt
After executing this command, you can use any text editor (e.g., nano, vim,
emacs) to write content to the file.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• cat: The cat command is short for "concatenate" and is commonly used to
display the contents of one or more files. It prints the entire contents of the
file to the terminal.
Example: $ cat filename
• less: The less command is a pager that allows you to view the contents of a
file one screen at a time. It provides navigation options and can handle large
files more efficiently than cat.
Example: $ less filename
Once in the less viewer, you can navigate using the arrow keys, Page Up,
Page Down, Home, End, and other keys. Press "q" to exit.
• more: Similar to less, the more command is a pager that displays the
contents of a file one screen at a time. However, it is less feature-rich than
less.
Example: $ more filename
Navigation in more is generally limited to the space bar for advancing one
page and the "b" key for going back one page. Press "q" to exit.
• head: The head command displays the first few lines of a file. By default, it
shows the first 10 lines, but you can specify a different number with the -n
option.
Example: $ head filename
• tail: The tail command displays the last few lines of a file. By default, it shows
the last 10 lines, but you can specify a different number with the -n option.
Example: $ tail filename
The above commands provide different ways to view the contents of a file in the
terminal, each with its own features and use cases. Choose the one that best fits
your needs based on the size of the file, desired interactivity, and personal
preference.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
First, you need to copy some files from local machine to aws-ec2 instance using
command syntax
scp -i my-key.pem /path/to/local/file.txt [email protected]:/home/ec2-
user/
for example: suppose my file name is “syllabus new.txt” which exist inside “e” drive
of my local machine and I want to copy the same file to my aws-ec2 instance then
I will use the following command using command prompt:
scp -i "dataserver.pem" "e:/syllabus new.txt" [email protected]
south-1.compute.amazonaws.com:/home/ec2-user/important
But make sure that you must have your “.pem” available at same folder of your
local machine.
Now, Here are some commonly used commands along with explanations:
a) less
The less command is a terminal pager program on Unix-like operating
systems used to view (but not modify) the contents of a text file one screen
at a time. Here are some common commands you can use when viewing a
file with less:
• Navigation
o Spacebar or Page Down: Move forward one page.
o Enter or Arrow Down: Move forward one line.
o Arrow Up: Move backward one line.
o Page Up or B: Move backward one page.
o G: Go to the end of the file.
o 1G or g: Go to the beginning of the file.
o /search_term: Search for a specific term in the file. Press n to
go to the next occurrence, or N to go to the previous
occurrence.
o ?search_term: Search for a specific term in the file from last
• Exiting
o Q: Quit less.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• Miscellaneous
o H: Display help screen showing all available commands.
o :n: Show line numbers.
o v: Open the file in the default text editor (vi by default).
b) more
The more command is a basic pager in Linux used to display the contents
of a file one screen at a time. It is similar to less, but with fewer features.
Here are the main commands you can use while viewing a file with more:
• Navigation:
o Spacebar or Page Down: Move forward one page.
o Enter or Arrow Down: Move forward one line.
o Arrow Up: Move backward one line.
o Page Up or B: Move backward one page.
o /:pattern: Search forward for a pattern in the file. Press n to
find the next occurrence.
• Exiting:
o Q or q: Quit more.
• Miscellaneous
o H or h: Display help screen showing all available commands.
o :n: Show line numbers.
o :f: Display the filename and the current line number at the
bottom of the screen.
Unlike less, more does not support more advanced features like scrolling backward,
following file changes in real-time, or searching with regular expressions. It's a
simple pager primarily used for quickly viewing the contents of a file.
You can also copy files from aws-ec2 instance file to your local machine using the
below command syntax
scp -i /path/to/your/aws/key.pem ec2-user@ec2-instance-ip:/path/to/remote/file
/path/to/save/file
for example: suppose my file name is “data.txt” which exist inside “home/ec2-
user/important” drive of my local machine and I want to copy the same file to my
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
local computer location “e:/” then I will use the following command using
command prompt:
scp -i "dataserver.pem" [email protected]
1.compute.amazonaws.com:/home/ec2-user/important/data.txt "e:/"
Again make sure that you must have your “.pem” available at same folder of your
local machine.
10. Find
The find command in Linux is a powerful utility used for searching files and
directories in a directory hierarchy. It provides extensive options for specifying
search criteria such as filename, file type, size, permissions, and more.
Detailed overview of the find command with various use case examples & syntax:
find [path...] [expression]
[path...]: Specifies the directory or directories to start the search from. If not
specified, it defaults to the current directory.
[expression]: Specifies the search criteria.
d) Find Directories
find /path/to/search -type d
This command searches for directories instead of files in the specified
directory /path/to/search.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
11. locate
The locate command in Linux is used to quickly search for files and directories on
a system by using a pre-built database of filenames. It provides a fast way to locate
files based on their names without having to traverse the entire file system.
Detailed overview of the locate command with various use case examples and
syntax: locate [options] [pattern]
[options]: Optional flags to modify the behavior of the command.
[pattern]: The pattern to search for. It can be a filename or a part of it.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
12. GREP
A powerful command-line tool used for searching plain-text data for lines that
match a regular expression. GREP stands for "Global Regular Expression Print." It's
widely used in Unix-based operating systems, including Linux and macOS, as well
as in Windows environments through tools like Cygwin or Windows Subsystem for
Linux (WSL).
Syntax:
The basic syntax of the grep command is:
grep [options] pattern [file...]
pattern: The regular expression pattern you want to search for.
[file...]: Optional. Specifies the file(s) in which to search. If not provided, grep will
read from standard input.
Common Options:
• -i or --ignore-case: Ignores case distinctions.
• -v or --invert-match: Inverts the match, displaying lines that do not match
the pattern.
• -r or --recursive: Recursively searches subdirectories.
• -n or --line-number: Precedes each line of output with its line number.
• -l or --files-with-matches: Prints only the names of files with at least one
match.
• -c or --count: Displays only the count of matching lines.
• -w or --word-regexp: Matches only whole words.
• -A, -B, -C or --after-context, --before-context, --context: Prints lines of
context around the match.
• -e pattern or --regexp=pattern: Specifies multiple patterns.
b) Case-Insensitive Search
grep -i "pattern" file.txt
Ignores case distinctions while searching.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
c) Recursive Search
grep -r "pattern" directory/
Searches for the pattern recursively in all files under the specified
directory.
d) Invert Match
grep -v "pattern" file.txt
Displays lines that do not match the pattern.
j) Contextual Output
grep -A 2 -B 2 "pattern" file.txt
Prints lines of context around the match.
Note: if we pass "*pattern*" then this is known as wildcard pattern that matches any
filename containing the word "pattern".
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
While the basic grep command is powerful on its own, there are a few
related commands and options that can enhance its functionality or
complement its usage. Here are some of them:
c) zgrep
zgrep is used to search within gzip-compressed files without having
to first decompress them. It works like grep, but it automatically
handles gzipped files.
zgrep "pattern" file.txt.gz
d) grep -o
The -o option extracts only the matching part of the lines, instead
of printing the entire line.
grep -o "pattern" file.txt
e) grep -m
Limits the number of matches displayed to a specified number.
Useful when you want to stop searching after a certain number of
matches.
grep -m 5 "pattern" file.txt
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
f) grep -q
Suppresses output and returns exit status only. Useful for scripting
when you only need to know if a pattern exists in a file.
if grep -q "pattern" file.txt; then
echo "Pattern found."
else
echo "Pattern not found."
fi
g) grep --color=auto
Highlights the matching text in color, making it easier to spot in the
output.
grep --color=auto "pattern" file.txt
Syntax:
The syntax for using a pipe is:
command1 | command2
Here, command1 generates some output, which is then passed as input to
command2.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
b) Counting
You can count the number of lines, words, or characters in the
output of a command using wc.
cat file.txt | wc -l
c) Combining Commands
Pipes allow you to combine the output of multiple commands into
one coherent output. For example, you can use ls to list files and
directories, grep to filter specific files, and wc to count them.
ls -l | grep ".txt" | wc -l
d) Data Transformation
You can transform data using commands like sed (stream editor) or
awk. For instance, you can replace text patterns using sed.
cat file.txt | sed 's/pattern/replacement/g'
e) Pagination
Pipes can be used for paging output, allowing you to view large
amounts of data page by page using commands like less or more.
ls -l | less
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Best Training Institute
for Graduates
with
Live Online & Offline Classes Available
Amenities
▪ Digital Notes ▪ Working Experience
▪ Live Training Sessions ▪ Job Recommendations
▪ Project Assistance ▪ Professional Development
▪ Interview Preparation ▪ Digital Resume & Portfolio
Linux Wildcards
• Linux wildcards are special characters used to represent one or more characters
within a file name or a string of characters.
• They are particularly useful for searching, matching, and manipulating files and
directories within the Linux operating system.
• Wildcards are processed by the shell before being passed to commands. Therefore,
understanding how your shell interprets them is crucial for using them effectively.
• Wildcards offer flexibility and efficiency in performing various file operations on
the command line, making them indispensable for Linux users and system
administrators. Understanding how to effectively use wildcards can greatly
enhance productivity when working in the terminal.
Key Concepts
While wildcards are powerful for simple pattern matching, regular expressions offer more
advanced pattern matching capabilities. Regular expressions are often used in commands
like grep, sed, and awk for text processing.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• [ ] (Square brackets): Matches any one character within the specified range or set.
Example: ls file[123].txt lists files like file1.txt, file2.txt, file3.txt.
Example: ls file[1-3].txt lists files like file1.txt, file2.txt, file3.txt.
Example: ls file[!12].txt lists files except file1.txt and file2.txt.
Note: The above command will work for the current directory only, not for its sub-
directory
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• Batch Renaming: Wildcards are commonly used for renaming multiple files that
share a common pattern.
Example: To rename all files with a .jpeg extension to .jpg, you can use the rename
command: rename 's/\.jpeg$/\.jpg/' *.jpeg
• Bulk Deletion: Wildcards are handy for deleting multiple files that match a specific
pattern.
Example: To remove all backup files with names ending in .bak, you can use the rm
command: rm *.bak
• Searching for Files: Wildcards can be combined with commands like find for
searching files in a directory hierarchy.
Example: To find all text files in the current directory and its subdirectories:
find . -type f -name "*.txt"
• Copying or Moving Files: Wildcards can simplify copying or moving multiple files
matching a pattern.
Example: to move all JPEG files from one directory to another:
mv *.jpg destination_directory/
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
Additional Commands
In numeric mode, you specify the permissions using a three-digit number, where
each digit corresponds to a set of permissions (owner, group, others). The numbers
are calculated by adding up the values of the permissions:
4 for read (r)
2 for write (w)
1 for execute (x)
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
In the command tar -czvf backup.tar.gz *, the -czvf are options and parameters for
the tar command, used for creating an archive file.
So, altogether, tar -czvf backup.tar.gz * is creating a new compressed archive file
called backup.tar.gz, which contains all the files and directories in the current
directory (* represents all files and directories).
• Create an Archive: To create a new archive, you use the -c option followed
by the name of the archive file and the list of files or directories to include
in the archive.
Example: tar -cvf archive.tar file1 file2 directory
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• View Contents: To view the contents of an archive, you use the -t option.
Example: tar -tvf archive.tar
• Extract Files: To extract files from an archive, you use the -x option.
Example: tar -xvf archive.tar
• Extract to a Specific Directory: You can specify the directory where the
files should be extracted using the -C option.
Example: tar -xvf archive.tar -C /path/to/directory
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
where,
• pattern: This is a condition or expression that defines when the associated
action should be executed. If the pattern is omitted, the action is performed
for every input record.
• { action }: This is the action or set of actions to be performed when the
pattern is matched. If the action is omitted, awk prints the entire record by
default.
• filename: This is the name of the file(s) to be processed by awk. If no
filename is provided, awk reads from the standard input (often piped data).
awk is highly versatile and can be used for a wide range of text processing tasks.
Its power lies in its ability to handle text data in a concise and efficient manner,
making it a valuable tool for shell scripting and data manipulation.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
The sed command, short for "stream editor," is a powerful text manipulation tool
in Unix-like operating systems. It is designed to perform operations on text
streams, which could be either piped input or files.
• Search and Replace: sed can search for patterns in the input and replace
them with specified strings.
Example: To replace all occurrences of "old" with "new" in a file:
sed 's/old/new/g' filename.txt
• Insert and Append Text: sed can insert or append text before or after
specified lines.
Example: to insert a line of text before lines containing "insert":
sed '/insert/i\New line to insert' filename.txt
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• Selective Printing: sed can print specific lines or ranges of lines from the
input.
Example: To print lines 5 to 10 of a file:
sed -n '5,10p' filename.txt
Additional Examples
• Excluding Characters
ls file[!12].txt # Matches files except file1.txt and file2.txt
• Negating Patterns
ls file[^12].txt # Matches files except file1.txt and file2.txt
• Conditional Operations
for file in file*.txt; do
echo "Processing $file..."
done
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
Directory Structure
• In Linux, the directory structure is organized in a hierarchical manner, following the
Filesystem Hierarchy Standard (FHS).
• This standard defines the directory structure and directory contents in Unix-like
operating systems, including Linux.
• The directory structure provides a standardized way to organize files and
directories in Linux systems, making it easier for users and administrators to locate
and manage files.
• Additionally, it facilitates interoperability between different distributions and
ensures compatibility with various software packages.
• / (Root Directory)
The root directory is denoted by a forward slash (/) and is the top-level directory
in the Linux file system hierarchy.
It contains all other directories and files on the system.
• /boot
Contains files required for the boot process, including the Linux kernel, initial RAM
disk (initrd), and bootloader configuration.
• /dev (Devices)
Contains device files representing physical and virtual devices attached to the
system, such as hard drives, USB drives, terminals, etc.
• /home
Contains user home directories. Each user typically has a subdirectory here where
they can store their files and personal settings.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• /lib (Libraries)
This directory contains shared libraries required by programs in /bin and /sbin as
well as essential system libraries.
• /mnt (Mount)
Traditionally used as a mount point for temporarily mounting filesystems, such as
CD-ROMs, USB drives, and network shares.
• /opt (Optional)
Reserved for optional software packages. Some third-party applications may install
here to keep their files separate from the system directories.
• /srv (Service)
This directory contains data files for services provided by the system, such as
websites, FTP servers, and repositories.
• /tmp (Temporary)
A directory for temporary files created by system and user processes. Files in this
directory are typically deleted upon system reboot.
• /var (Variable)
Contains variable data files, such as log files, spool files, and temporary files that
are expected to grow in size during normal system operation.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• /root
This directory is the home directory for the root user (superuser). Unlike regular
user home directories in /home, /root is the home directory for the system
administrator.
• /run
Contains system runtime data. This directory is used by processes and services to
store temporary runtime information, such as process IDs (PIDs) and UNIX domain
sockets.
• /media
Traditionally used as a mount point for removable media devices, such as USB
drives, external hard drives, and optical discs. However, some Linux distributions
now use /mnt for this purpose.
• /lost+found
This directory is used by the fsck (file system check) utility to store recovered files
after a file system check operation. If the file system is found to be corrupt during
boot, fsck attempts to repair it and salvages any recoverable files into this directory.
• /usr/local
Similar to /opt, /usr/local is used for installing software locally on the system.
However, /usr/local is typically used for software installed from source code, while
/opt is often used for third-party software packages.
• Symbolic Links
Symbolic links (symlinks) are special files that point to another file or directory.
They are commonly used in Linux to create shortcuts or aliases to files and
directories located elsewhere in the file system.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• File Permissions
In Linux, file permissions control access to files and directories. Each file and
directory have permission settings for the owner, group, and others, determining
who can read, write, and execute them.
1. Hierarchy
• The Linux file system follows a hierarchical structure, starting from the root
directory / and branching out into subdirectories.
• This hierarchy is known as the Filesystem Hierarchy Standard (FHS) and
provides a standardized way to organize files and directories across
different Linux distributions.
2. Directory Structure
• Root Directory (/)
The top-level directory in the file system hierarchy.
• Common Subdirectories
o /bin: Essential binaries (executable programs).
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
3. File Types
• Regular Files: Standard files that contain data, such as text files, documents,
and executables.
• Directories: Containers for files and other directories.
• Symbolic Links (Symlinks): Pointers to other files or directories.
• Special Files: Represent devices or system resources.
• Named Pipes (FIFOs): Provides inter-process communication.
• Sockets: Facilitates communication between processes.
• Device Files: Represent physical or virtual devices attached to the system.
5. File Permissions
• Linux uses a permission system to control access to files and directories.
• Permissions are divided into read (r), write (w), and execute (x) permissions
for the owner, group, and others.
• Permissions can be viewed and modified using commands like chmod,
chown, and chgrp.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
6. Mount Points
• Mount points are locations within the file system where additional file
systems are attached.
• Common mount points include /mnt, /media, and directories within /mnt
for temporary mounts.
• The mount and umount commands are used to attach and detach file
systems.
8. Disk Partitioning
• Disk partitions are logical sections of a disk drive.
• Common partitioning schemes include Master Boot Record (MBR) and GUID
Partition Table (GPT).
• Tools like fdisk, parted, and gdisk are used for disk partitioning and
management.
9. Disk Quotas
• Disk quotas limit the amount of disk space a user or group can use.
• Quotas are managed using tools like quotaon, edquota, and repquota.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Best Training Institute
for Graduates
with
Live Online & Offline Classes Available
Amenities
▪ Digital Notes ▪ Working Experience
▪ Live Training Sessions ▪ Job Recommendations
▪ Project Assistance ▪ Professional Development
▪ Interview Preparation ▪ Digital Resume & Portfolio
1. Root Volume
• When you launch an EC2 instance, it typically comes with a root volume,
which is the primary storage device for the operating system and installed
applications.
• The root volume is often an Elastic Block Store (EBS) volume, which provides
persistent block-level storage.
• The file system on the root volume follows the standard Linux file system
hierarchy, including directories like /, /bin, /etc, /home, /var, etc.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• The file system on instance store volumes behaves similarly to any other
disk attached to a Linux server and can be formatted with a file system of
your choice.
• However, data stored on instance store volumes is ephemeral and will be
lost if the instance is stopped or terminated.
4. Mount Points
• Each volume attached to an EC2 instance is mounted at a specific mount
point within the file system hierarchy.
• You can configure the mount points for EBS volumes in the /etc/fstab file to
ensure they are automatically mounted when the instance boots.
6. Security Considerations
When managing the file system on an EC2 instance, it's essential to consider
security best practices, such as implementing appropriate file permissions,
encrypting sensitive data, and configuring network security groups and IAM
policies to control access to resources.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
1. Creating a User
To create a new user, you can use the useradd command followed by the
username.
For example:
sudo useradd learn2earnLabs
This creates a new user named " learn2earnLabs".
3. Listing Users
You can list all users on the system using the cat command with the /etc/passwd
file.
For example:
cat /etc/passwd
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
5. Switching User
You can switch to another user using the su command followed by the username.
For example:
su - learn2earnLabs
7. Deleting a User
To delete a user account, use the userdel command followed by the username.
For example:
sudo userdel learn2earnLabs
This removes the user account, but it does not remove the user's home directory
or files by default.
To permanently delete a user from your Linux machine or from an AWS EC2 Linux
instance, including their home directory, you can use the userdel command with
the -r option, which removes the user's home directory and mail spool.
For example:
sudo userdel -r learn2earnLabs
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• Terminate the process: Once you've identified the process(es), you can
terminate them using the kill command followed by the process ID.
For example:
sudo kill 1830
Replace 1830 with the actual process ID is you get other processes.
• Retry deleting the user: After ensuring that no processes are running under the
user john, you can attempt to delete the user again using the userdel command
: sudo userdel -r learn2earnLabs
If you're sure there are no processes running under the user john, but you're still
unable to delete the user, it's possible that there might be some system service or
process using files or resources associated with the user john.
• Check for any active SSH sessions: Make sure there are no active SSH sessions
using the user learn2earnLabs. If there are, log out of those sessions before
attempting to delete the user.
• To check for any active SSH sessions on your AWS EC2 Linux instance, you
can use the who or w command. These commands will list all users
currently logged in to the system, including those connected via SSH.
• Both commands provide similar information, including the
username, terminal, login time, and IP address (if applicable)
of each user currently logged in to the system.
• If you see any sessions associated with the user
learn2earnLabs, it means there's an active SSH session using
that user. You should log out of those sessions before
attempting to delete the user.
• If there are active SSH sessions that you need to terminate,
you can use the pkill command followed by the SSH process
name.
For example:
sudo pkill -u learn2earnLabs sshd
Replace learn2earnLabs with the username of the user whose
SSH session you want to terminate. This command will
terminate all SSH sessions associated with the specified user.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• Stop services associated with the user: Some services might be using files or
resources associated with the user learn2earnLabs. Check for any services that
might be running under this user and stop them. You can list services and their
associated users using the following command:
sudo systemctl list-units --type=service
Look for services that are running under the user learn2earnLabs and
stop them using systemctl.
• Check for any open files owned by the user: There might be files owned by
the user learn2earnLabs that are currently open. You can check for open files
using the lsof command.
For example:
sudo lsof -u learn2earnLabs
This command will list all open files owned by the user
learn2earnLabs. If there are any, you should close them or terminate
the processes that have them open.
• Forcefully delete the user: If you've ensured that there are no active processes
or services associated with the user learn2earnLabs and you still can't delete the
user, you can try forcefully deleting the user
For example:
sudo userdel -r -f learn2earnLabs
This command will forcefully delete the user learn2earnLabs along
with their home directory, even if there are files or processes
associated with the user.
After trying the above steps, you should be able to successfully delete the user
learn2earnLabs. However, be cautious when using the -f option with userdel as it
forcefully removes the user and their files without further confirmation.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
To add a user to a group, use the usermod command with the -aG option.
For example, to add the user " learn2earnLabs" to the "developers" group:
sudo usermod -aG developers learn2earnLabs
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
If the sudo group does not exist on your EC2 instance, it suggests that your instance might
be running a Linux distribution that uses a different group for granting sudo privileges, or
the sudo package might not be installed.
• Check if the sudo package is installed: Run the following command to check if
the sudo package is installed on your EC2 instance:
sudo -v
If the sudo package is installed, this command should execute without errors. If it's
not installed, you'll likely get an error message indicating that the sudo command
is not found or not installed.
• Create the sudo group (if needed): If your Linux distribution typically uses the
sudo group for granting sudo privileges, but it's missing, you can create it
manually. Run the following command to create the sudo group:
sudo groupadd sudo
This command will create the sudo group on your EC2 instance.
• Add the new user to the sudoers file (if needed): Alternatively, if your Linux
distribution does not use the sudo group for granting sudo privileges, you can
directly add the new user to the sudoers file. Run the following command to edit
the sudoers file using vim editor:
sudo visudo
Add the following line to the sudoers file to grant sudo privileges to the new user
(newuser):
learn2earnLabs ALL=(ALL) NOPASSWD:ALL
Replace learn2earnLabs with the username of the new user you created earlier.
Once you've ensured that the appropriate configuration is in place, you should be able to
grant sudo privileges to the new user and proceed with the SSH connection using the
same PEM file.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
getent command
• The getent command is used to query entries from databases supported by the
system's Name Service Switch (NSS) configuration, such as passwd, group, hosts,
etc.
• This allows you to retrieve information from various sources, including local files
like /etc/passwd and /etc/group, as well as network services like LDAP.
• To list all groups using the getent command, you can specify the group database.
For example:
getent group
This command will list all groups configured on the system. Each line in the output
represents a group entry, typically in the format:
group_name:x:group_id:user_list
where,
• group_name is the name of the group.
• x is a placeholder for the group password, which is stored in /etc/gshadow.
• group_id is the numerical group ID.
• user_list is a comma-separated list of users who are members of the group.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• SSH into your EC2 instance: Use SSH to connect to your EC2 instance using the
key pair you used to launch it.
ssh -i your-key.pem ec2-user@your-instance-public-ip
• Create a new user: Create a new user account with the adduser command.
sudo adduser newusername
• Grant sudo privileges: To grant sudo privileges to the newly created user, you
need to add the user to the sudo group. In some Linux distributions like Ubuntu,
this group is named sudo, while in others like Amazon Linux, it's named wheel. You
can check your system's sudo group configuration.
For Ubuntu:
sudo usermod -aG sudo newusername
For Amazon Linux:
sudo usermod -aG wheel newusername
• Verify sudo access: You can verify that the user has sudo access by switching to
the new user and trying to execute a command with sudo.
su - newusername
sudo ls /root
It should prompt for the password of the new user and then execute the command.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• Log out and log back in (if necessary): After adding the user to the sudo group
or modifying the sudoers file, it's a good practice to log out and log back in to
apply the changes.
By following the above steps, you should be able to create a new user and grant
them sudo privileges on your AWS EC2 Linux instance.
Still receiving the message something like : newusername is not in the sudoers file.
This incident will be reported.
If you're still receiving the message that the user is not in the sudoers file after adding
them to the appropriate group, there might be a few reasons for this:
• Incorrect Group Name: Ensure that you're adding the user to the correct group.
On some systems like Ubuntu, it's the sudo group, while on others like Amazon
Linux, it's the wheel group.
• Sudoers File Configuration: If the user is correctly added to the sudo group, but
still facing issues, it's possible that there's a configuration issue in the sudoers file.
You can try modifying the sudoers file again to explicitly grant sudo privileges to
the user.To edit the sudoers file, use the visudo command:
sudo visudo
Then, add the following line to grant sudo access to the new user:
newusername ALL=(ALL) ALL
Make sure to replace newusername with the actual username of the new user.
• Permissions Issue: Ensure that the sudoers file has the correct permissions. It
should typically be owned by root and have permissions set to 0440.
sudo chmod 0440 /etc/sudoers
• Syntax Error in sudoers file: Make sure there are no syntax errors in the sudoers
file. A single syntax error can cause sudo to fail. visudo checks the syntax before
saving changes.
After making these changes, try logging out and logging back in as the new user, and
then attempt to run a command with sudo to verify that the user has sudo privileges. If
you're still encountering issues, double-check each step for accuracy and completeness.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
Managing permissions
Managing permissions in Linux involves controlling access to files, directories, and
resources to ensure security and proper operation of your system.
1. File Permissions
File permissions in Linux are governed by three sets of permissions: read, write, and
execute. These permissions are assigned to three different categories of users:
owner, group, and others. You can manage file permissions using the chmod
command.
• Read (r): Allows reading the contents of a file or viewing the contents of a directory.
• Write (w): Allows modifying or deleting the file, or adding/removing files from a
directory.
• Execute (x): Allows executing a file or accessing files within a directory.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
0: No permissions
1: Execute
2: Write
3: Write and execute
4: Read
5: Read and execute
6: Read and write
7: Read, write, and execute
For example, to give the owner read, write, and execute permissions, and
only read permissions to the group and others:
chmod 755 filename
u: Owner
g: Group
o: Others
a: All (equivalent to ugo)
+: Add permission
-: Remove permission
=: Set exact permissions
For example,
To give the owner write permissions:
chmod u+w filename
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• Recursive Mode
You can use the -R option to apply the permission changes recursively
to all files and directories within a directory.
For example, to give read and execute permissions to all files and
directories within a directory:
chmod -R u+rx directory
2. Ownership
Each file and directory in Linux has an owner and a group associated with it. The
owner is the user who created the file or directory, while the group is a collection
of users with similar permissions.
You can use the chown command to change the owner of a file or directory:
sudo chown newowner filename
You can use the chgrp command to change the group associated with a file or
directory:
sudo chgrp newgroup filename
3. Special Permissions
In addition to the basic read, write, and execute permissions, there are also special
permissions such as setuid, setgid, and sticky bit.
• Setuid (s): When set on an executable file, allows the file to be executed
with the permissions of the owner of the file.
• Setgid (s): When set on a directory, forces all files created within the
directory to inherit the group ownership of the directory.
• Sticky bit (t): When set on a directory, only the file owner, directory
owner, or root can delete or rename the files within the directory.
You can set these special permissions using chmod with the numeric mode or
symbolic mode.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• Sticky Bit
The sticky bit is primarily used on directories to restrict
deletion of files within that directory to only the file owner,
the directory owner, or the root user.
This is commonly used on directories where multiple users
have write access, such as temporary directories.
To set the sticky bit on a directory, you can use the chmod
command:
chmod +t directory
4. AWS IAM (Identity and Access Management) – In case of aws ec2 instance
While the above permissions are specific to the Linux operating system, AWS IAM
provides centralized control over access to AWS services and resources.
With IAM, you can create and manage AWS users and groups, and attach policies
to control their permissions.
IAM allows you to grant permissions to users and groups to perform specific
actions on specific resources.
For example, you can grant permission to start or stop EC2 instances, create S3
buckets, or manage RDS databases.
5. Security Groups
In AWS, security groups act as virtual firewalls for your EC2 instances, controlling
inbound and outbound traffic. You can specify which traffic is allowed to reach
your instance based on IP addresses, ports, and protocols.
By configuring security groups, you can manage network-level permissions to and
from your EC2 instances.
6. Network ACLs
Network Access Control Lists (ACLs) are another layer of security for controlling
traffic in and out of your subnets in AWS. While security groups are associated with
instances, network ACLs are associated with subnets. You can use network ACLs to
control which traffic is allowed or denied to/from subnets.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Best Training Institute
for Graduates
with
Live Online & Offline Classes Available
Amenities
▪ Digital Notes ▪ Working Experience
▪ Live Training Sessions ▪ Job Recommendations
▪ Project Assistance ▪ Professional Development
▪ Interview Preparation ▪ Digital Resume & Portfolio
Process Management
• Managing processes in Linux on an AWS EC2 instance involves monitoring,
controlling, and optimizing the execution of programs and services.
• By using commands like ps, top, etc. you can monitor process activity and resource
usage.
• With tools like systemctl, kill, and ulimit, you can start, stop, prioritize, and
terminate processes as needed to ensure optimal system performance and
resource utilization.
1. Process Monitoring
You can monitor processes running on your EC2 instance using various tools and
commands:
• ps: The ps command displays information about active processes. By
default, it shows only the processes associated with the current shell session,
but you can use options like -e or -aux to display all processes.
ps aux
• top: The top command provides a dynamic real-time view of system
processes. It continuously updates the display to show resource usage, CPU,
memory, and process information.
top
2. Process Control
You can control processes by starting, stopping, pausing, and restarting them as
needed:
• start: Use the appropriate command or service manager to start a process.
For example, you can use systemctl to start a systemd service:
sudo systemctl start servicename
• stop: Similarly, use systemctl to stop a systemd service:
sudo systemctl stop servicename
• restart: To restart a service, you can use the restart option with systemctl:
sudo systemctl restart servicename
• pause/resume: Some processes support pausing and resuming.
For example, you can pause a process using the kill command with the
SIGSTOP signal and resume it with SIGCONT:
kill -SIGSTOP pid
kill -SIGCONT pid
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
Explanation
The kill command is typically used to send signals to processes in
Linux. These signals can be used to control the behavior of processes,
such as terminating them (SIGTERM) or asking them to reload their
configuration (SIGHUP).
3. Process Management
You can manage processes by prioritizing, limiting resources, and scheduling tasks:
• nice/renice: Use the nice command to set the priority of a process. Lower
values indicate higher priority. You can also use renice to change the priority
of an already running process.
nice -n value command
renice priority pid
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• ulimit: The ulimit command sets or displays resource limits for the current
shell session or for specific users or groups. You can use it to limit the
resources available to processes, such as CPU time, memory, and file
descriptors.
ulimit -a
4. Process Termination
You can terminate processes that are no longer needed or are consuming excessive
resources:
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
Managing Software
• Managing software on an AWS EC2 Linux instance involves tasks such as installing,
updating, removing, and monitoring software packages.
• The process typically involves using package management tools like YUM
(Yellowdog Updater Modified) for CentOS/RHEL-based systems or APT (Advanced
Package Tool) for Debian/Ubuntu-based systems.
2. Install Software
To install new software packages, you can use the package manager's install
command along with the package name.
For CentOS/RHEL-based systems
sudo yum install package_name
For Debian/Ubuntu-based systems
sudo apt install package_name
Replace package_name with the name of the software package you want to install.
3. Remove Software
If you want to remove a software package, you can use the package manager's
remove or purge command. The remove command removes the package but
leaves its configuration files intact, while the purge command removes both the
package and its configuration files.
For CentOS/RHEL-based systems
sudo yum remove package_name
For Debian/Ubuntu-based systems
sudo apt remove package_name
or sudo apt purge package_name
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
5. Upgrade Software
To upgrade installed packages to their latest versions, you can use the upgrade
command.
For CentOS/RHEL-based systems
sudo yum upgrade
For Debian/Ubuntu-based systems
sudo apt upgrade
rpm -qa: This command queries the RPM database to list all installed
packages on the system. The -q option stands for query, and the -a option
specifies that it should query all installed packages.
when you run rpm -qa | grep package_name, it will list all installed packages
on your system, and then filter the results to display only the lines
containing the package_name you specified. This is useful for quickly
checking if a particular package is installed on your system and for finding
its exact name if you're unsure.
For Debian/Ubuntu-based systems
dpkg -l | grep package_name
Replace package_name with the name of the software package you want to check.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
dpkg -l: This command lists all installed packages on the system using the
Debian package manager (dpkg). The -l option stands for "list" and it tells
dpkg to list all installed packages.
when you run dpkg -l | grep package_name, it will list all installed packages
on your system using dpkg, and then filter the results to display only the
lines containing the package_name you specified. This command is useful
for quickly checking if a particular package is installed on your system and
for finding its exact name if you're unsure.
7. Monitoring Software
To monitor software services running on your EC2 instance, you can use tools like
systemd, systemctl, or third-party monitoring solutions.
For example, to check the status of a service:
sudo systemctl status service_name
Replace service_name with the name of the service you want to check.
By following the above steps and using the appropriate commands, you can effectively
manage software on your AWS EC2 Linux instance.
1. Installing Nano
For Debian/Ubuntu-based systems
sudo apt update
sudo apt install nano
For CentOS/RHEL-based systems
sudo yum update
sudo yum install nano
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
3. Upgrading Nano
For Debian/Ubuntu-based systems
sudo apt upgrade nano
For CentOS/RHEL-based systems
sudo yum update nano
4. Removing Nano
For Debian/Ubuntu-based systems
sudo apt remove nano
For CentOS/RHEL-based systems
sudo yum remove nano
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
Links
In Linux, a "link" is a pointer or reference to a file or directory.
• Hard links:
▪ These are direct pointers to the inode (data structure that stores
information about a file or directory) of a file.
▪ Hard links essentially share the same data blocks as the original file
and have the same permissions, ownership, and content.
▪ Deleting the original file does not affect hard links to it, as they point
directly to the inode.
for example,
ln data/files/index.html data/myhardlink
To create a symbolic link, you can use the -s option with the ln command:
ln -s /path/to/original_file /path/to/symlink
For example,
ln -s data/files/index.html data/mysoftlink
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
Tar
• "Tar" stands for Tape Archive.
• It is a command-line utility used for archiving files and directories into a
single file, often called a "tarball."
• Tar preserves file system information such as permissions, ownership, and
timestamps.
• Tarballs are commonly used for backups, distribution, and transferring
multiple files or directories as a single unit.
To create a tarball, you use the tar command with various options:
• Creating a tarball
tar -cvf archive.tar file1 file2 directory
where,
-c: Create a new archive.
-v: Verbose mode (display progress).
-f: Specify the filename of the archive.
These commands are used extensively for managing files and directories in Linux
environments, including AWS EC2 instances. They offer flexibility and efficiency in
handling file operations, backups, and data transfer.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
Check Other Log Files: Look for similar log files in the /var/log/ directory or its
subdirectories. Common alternatives include /var/log/messages, /var/log/syslog-ng, or
/var/log/syslogd. Use the ls command to list the contents of the /var/log/ directory and
its subdirectories.
ls /var/log/
some common log files and commands used to interact with them:
1. System Logs
System logs contain information about system-level events, services, and
components. These logs are essential for monitoring system health and diagnosing
issues.
• /var/log/syslog: Contains general system messages, including kernel
messages, daemon messages, and system events.
tail -n 100 /var/log/syslog # View the last 100 lines of syslog
if you do not have sufficient permissions to read the log then you can take below
options to resolve this issue
• Use sudo: If you have administrative privileges (sudo access), you can
prepend the sudo command to your tail command to run it with elevated
privileges. This will allow you to bypass permission restrictions.
sudo tail -n 100 /var/log/logname
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
• Check User Permissions: Ensure that the user executing the tail command
has the necessary permissions to read the /var/log/secure file. You can use
the ls command with the -l option to view the file permissions and
ownership.
ls -l /var/log/secure
If the file permissions are restricted, you may need to modify the
permissions or ownership of the file using the chmod or chown command,
respectively. However, changing permissions or ownership should be done
cautiously, especially for system log files.
2. Authentication Logs
Authentication logs record user authentication attempts, login successes, and
failures.
• /var/log/auth.log: Contains authentication-related logs, including SSH
login attempts, on Debian/Ubuntu-based systems.
tail -n 100 /var/log/auth.log # View the last 100 lines of auth.log
• /var/log/secure: Similar to auth.log, contains authentication-related logs
on Red Hat-based systems.
tail -n 100 /var/log/secure # View the last 100 lines of secure
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
3. Kernel Logs
Kernel logs provide information about the Linux kernel's activities, errors, and
warnings.
• /var/log/kern.log: Contains kernel-related logs, including hardware errors,
kernel module loading, and unhandled exceptions.
tail -n 100 /var/log/kern.log # View the last 100 lines of kern.log
In Red Hat Enterprise Linux (RHEL), the default location for kernel logs is typically
/var/log/messages instead of /var/log/kern.log. The /var/log/kern.log file is more
commonly found on Debian-based distributions such as Ubuntu.
To view kernel logs on RHEL, you can use the following command:
sudo tail -n 100 /var/log/messages
This command will display the last 100 lines of messages, which include kernel
messages among other system-related logs.
If you specifically need to monitor kernel messages in real-time, you can use the
dmesg command instead:
sudo dmesg | tail -n 100
This command will display the last 100 lines of kernel messages from the kernel
ring buffer.
4. Application Logs
Application logs contain information specific to applications running on the
system, such as web servers, databases, and custom applications.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
If you are using RHEL based system and apache is not installed then you need to
follow the below steps:
a) Check if Apache is Installed
You can use the httpd command to check if Apache is installed and running
on your EC2 instance:
sudo systemctl status httpd
If Apache is installed and running, you will see its status and other
information. If it's not installed, you'll get a message indicating that the unit
is not found.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability
If you're encountering the error "tail: cannot open '/var/log/syslog' for reading: No
such file or directory" on a RHEL machine, it's likely because the /var/log/syslog file
does not exist.
To view system logs on a RHEL machine, you can use the following command to
view the system messages log file:
sudo tail -n 100 /var/log/messages
This command will display the last 100 lines of messages from the system log file.
6. Searching Logs
You can use tools like grep to search for specific patterns or keywords within log
files.
grep "ERROR" /var/log/syslog # Search for "ERROR" in syslog
In RHEL, as mentioned earlier, the /var/log/syslog file is not a standard location for
system logs. Instead, RHEL typically uses /var/log/messages for system-wide
logging.
If you're trying to search for a specific pattern within the system logs, you can use
the grep command with the appropriate log file.
For example, to search for occurrences of a specific keyword in the
/var/log/messages file:
sudo grep "keyword" /var/log/messages
Replace "keyword" with the specific pattern or keyword you're searching for.
Get 5 LPA Or 8 LPA Guaranteed Package | Live Online Classes | for more information, visit – www.learntoearnlabs.com
Best Training Institute
for Graduates
with
Live Online & Offline Classes Available
Amenities
▪ Digital Notes ▪ Working Experience
▪ Live Training Sessions ▪ Job Recommendations
▪ Project Assistance ▪ Professional Development
▪ Interview Preparation ▪ Digital Resume & Portfolio
Website : www.LearntoearnLabs.com