0% found this document useful (0 votes)
17 views

Linux - Reference Notes For Job Seekers & Students

Uploaded by

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

Linux - Reference Notes For Job Seekers & Students

Uploaded by

abidmohd253
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 85

Reference

Notes
[Digital Copy]

Linux ( Like Unix )


Command Line

Join us for Better Career and Job Guarantee

[ Live Online & Offline Classes Available ]

LEARN-2-EARN LABS TRAINING INSTITUTE, AGRA


Guiding Careers with
Visionary Support

Institute Director(s)

Mr. Mohit Singh is a professional full-stack trainer, project


consultant and startup mentor. He is holding expertise in Java,
Application Design, MERN Stack, DevOps, Design Thinking and
User Experience Design.
He has trained thousands of students & hundreds of employed
professionals. He completed his trainings in Google, Gurugram
and short term projects in IIT Delhi, IIT BHU & IIT Jodhpur.
He is also recognized as Mentor with startup India, Punjab
Startup, startup Uttarakhand, Mumbai State Innovation Society,
Atal Innovation Mission, etc. in the area of education & utility
services.
Mr. Mohit Singh
M.Tech, B.Tech (C.S.E) https://www.linkedin.com/in/mohit9pages/

Dr. Shubhendra Gupta is an experienced digital marketer,


Business Consultant and startup mentor with a demonstrated
history of working in the education and services industry.
He use to train students & working professionals for getting
better job opportunities and train business owners in
generating profits or leads. His areas of interest are Digital
Marketing, Business Development, Data Analysis, Strategic
Planning, Market Research & Reality, User Testing, Website
design, etc.
He is also recognized as Mentor with Startup Hubs &
Innovation Labs in the area of education, brand building &
Dr. Shubhendra Gupta business consultation.
Phd, B.Ed, M.Sc (Physics)
https://www.linkedin.com/in/dmshubhendra/

Institute Vision

To be an institute that provides a transformative learning to produce


highly skilled & competent professionals and to create leaders and
innovators for society and industry.

LEARN-2-EARN LABS TRAINING INSTITUTE, AGRA


Learn-2-Earn Labs - Best Institute for job opportunities, & career stability

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

1. Origins and Development


• Linus Torvalds: Linux was created in 1991 by Finnish-American software
engineer Linus Torvalds, who released the first version of the Linux kernel
as open-source software.
• Open Source Nature: Unlike proprietary operating systems like Windows
or macOS, Linux is open-source, meaning its source code is freely available
for anyone to use, modify, and distribute.

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.

• Shell: Linux systems typically use a command-line interface (CLI) called a


shell. The shell interprets user commands and executes programs.

• 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.

• Desktop Environment: Linux can also include graphical user interfaces


(GUIs) provided by desktop environments like GNOME, KDE, XFCE, 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

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.

4. Features and Advantages


• Stability and Reliability: Linux systems are known for their stability and
reliability, often running for months or even years without needing a reboot.
• Security: Linux is inherently more secure than some other operating
systems due to its Unix-like architecture and strong user permission system.
• Customization: Users can customize nearly every aspect of a Linux system,
from the kernel to the desktop environment, to suit their specific needs and
preferences.
• Cost: Linux is free to use, which significantly reduces the cost of deploying
and maintaining large-scale systems.
• Community Support: The Linux community is vast and active, providing
support, documentation, and software development resources.

5. Common Use Cases


• Servers: Linux is widely used as a server operating system due to its stability,
security, and scalability.
• Desktops and Laptops: Many users opt for Linux as their primary operating
system on personal computers, especially those who value customization
and privacy.
• Embedded Systems: Linux is commonly used in embedded systems, such
as routers, smart TVs, and IoT devices, due to its flexibility and small
footprint.

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

Basic Linux Commands


• ls - List directory contents
ls [options] [file/directory]
Example: ls -l /home/user/Documents

• cd - Change directory
cd [directory]
Example: cd /var/www

• pwd - Print working directory


pwd
Example: pwd

• mkdir - Make directory


mkdir [directory_name]
Example: mkdir new_folder

• rm - Remove files or directories


rm [options] [file/directory]
Example: rm file.txt

• cp - Copy files or directories


cp [options] [source] [destination]
Example: cp file.txt /tmp

• mv - Move or rename files or directories


mv [options] [source] [destination]
Example: mv file.txt new_file.txt

• touch - Create an empty file


touch [filename]
Example: touch new_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

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.

Overview of Amazon EC2

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

• Some popular instance types include:


o General Purpose: Provides a balance of compute, memory, and
networking resources (e.g., t3.micro, m5.large).
o Compute Optimized: Designed for compute-intensive applications
(e.g., c5.large, c5n.xlarge).
o Memory Optimized: Designed for memory-intensive applications
(e.g., r5.large, x1e.xlarge).
o Storage Optimized: Designed for storage-intensive applications (e.g.,
i3.large, d2.xlarge).
4. Pricing
• EC2 pricing is based on the instance type, region, usage duration, and
additional features (e.g., EBS volumes, data transfer).
• Pricing options include On-Demand Instances, Reserved Instances, and Spot
Instances.
• On-Demand Instances are charged by the hour with no long-term
commitments.
• Reserved Instances offer discounted pricing in exchange for a one- or three-
year commitment.
• Spot Instances allow you to bid for unused EC2 capacity, offering potential
cost savings but with the risk of interruption.
5. Use Cases
• EC2 can be used for a wide range of use cases, including web hosting,
application development, testing, data processing, and machine learning.
• It provides the flexibility and scalability needed to support both small-scale
and large-scale workloads.
• EC2 instances can be deployed in various configurations, such as standalone
instances, auto-scaling groups, and load-balanced fleets, to meet specific
requirements.
6. Management
• EC2 instances can be managed through the AWS Management Console,
Command Line Interface (CLI), or SDKs.
• You can monitor and manage instances using Amazon CloudWatch, which
provides metrics, logs, and alarms for monitoring performance and health.
• AWS provides various tools and services for managing instances at scale,
including AWS Systems Manager for automation and AWS OpsWorks for
configuration management.

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

Creating EC2 Instance

Here are the steps to create an EC2 instance in AWS:

• Sign in to the AWS Management Console


Go to the AWS Management Console (https://aws.amazon.com/console) and sign
in to your AWS account.

• Navigate to EC2 Dashboard


Once logged in, navigate to the EC2 service by either typing "EC2" in the search
bar or selecting it from the list of available services.

• Launch Instance
In the EC2 Dashboard, click on the "Launch Instance" button to start the instance
creation process.

• Choose an Amazon Machine Image (AMI)


Select an AMI from the list provided. An AMI is a pre-configured template that
contains the operating system, software, and configuration settings for your
instance. You can choose from AWS-provided AMIs or your custom AMIs.

• Choose an Instance Type


Select an instance type based on your application requirements. Each instance type
offers different combinations of CPU, memory, storage, and networking capacity.
You can compare instance types and choose the one that best fits your needs.

• Configure Instance Details


Configure additional settings for your instance, such as the number of instances to
launch, network settings, IAM role, and user data (optional). You can also enable
features like auto-assign public IP and termination protection.

• Select Key Pair


Select an existing key pair or create a new one. A key pair is used to securely
connect to your instance via SSH. If you're creating a new key pair, make sure to
download the private key file (.pem) and store it in a secure location.

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.

• Add Tags (Optional)


Add tags to your instance to organize and identify it. Tags are key-value pairs that
you can use to categorize resources for billing, management, and automation
purposes.

• Configure Security Group


Configure the security group for your instance. A security group acts as a virtual
firewall that controls inbound and outbound traffic to your instance. Define the
rules to allow specific types of traffic (e.g., SSH, HTTP) from specific sources (e.g.,
IP addresses, other security groups).

• Review and Launch


Review the configuration settings for your instance to ensure everything is correct.
You can make any necessary changes by clicking on the "Edit" button for each
section.
Once you're satisfied with the configuration, click on the "Launch" button to
proceed.

• Launch Instance
After selecting the key pair, click on the "Launch Instances" button to launch your
EC2 instance.

• Access Your Instance


Once the instance is launched, you can access it using SSH (for Linux instances) or
Remote Desktop Protocol (RDP) (for Windows instances) using the public IP
address or DNS name provided.

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

Connecting the instance using SSH

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.

Steps to solve the issue


• Open PowerShell or Command Prompt.
Navigate to the directory where your .pem file is located using the cd command.
For example:
cd C:\Users\YourUsername\Downloads
• Once you're in the directory containing your .pem file, you can use the icacls
command to modify the permissions. Replace YourKey.pem with the name of your
.pem file. Run the following command:
icacls YourKey.pem /inheritance:r /grant:r "%USERNAME%":R
This command removes inherited permissions and grants read-only access to the
file for the current user.
• After running the command, you can confirm that the permissions have been set
correctly by running:
icacls YourKey.pem
Ensure that the output indicates that only the current user has read permissions.
• Now, you can try connecting to your AWS instance again using the ssh command
with your .pem file. The command should be similar to:
ssh -i YourKey.pem ec2-user@YourPublicIpAddress
or like
ssh -i "YourKey.pem" [email protected]
1.compute.amazonaws.com
Replace YourKey.pem and YourPublicIpAddress with your actual file name and
instance details.

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

Join us for Better Career and Job Guarantee

Full Stack Web Development


Top Edge (MERN Stack) HTML, CSS, JavaScript, ES,
Git, ReactJS, Node, Express, MySQL & MongoDB

Training Full Stack Engineer


Java, JavaScript, ReactJS, Spring, SpringBoot
Hibernate, Linux, AWS, Git, DevOps & Jira

Programs Digital Marketing


Social Media, Website Design, SEO,
Google Ads, Freelancing & Many More

Guaranteed Package (In Writing)


▪ 3-5 Lakhs (With 6 Months Training Programs)
▪ 6-8 Lakhs (With 12 Months Training Programs)
▪ 10 Lakhs+ (With 2 Years Training Programs)

Amenities
▪ Digital Notes ▪ Working Experience
▪ Live Training Sessions ▪ Job Recommendations
▪ Project Assistance ▪ Professional Development
▪ Interview Preparation ▪ Digital Resume & Portfolio

LEARN-2-EARN LABS TRAINING INSTITUTE


Anna Icon Complex, near Kargil Petrol Pump, Sikandra-Bodla Road, Sikandra, Agra
Website : www.LearntoearnLabs.com
Call : 91-9548868337 / +91-9837705705
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability

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

Note: If you are using aws-ec2 instance then ec2-user@ip-172-31-13-230 means


that ec2-user is the username and ip-172-31-13-230 is the hostname.
& if you are using linux distribution locally then admin@redhat01 means that
admin is the username and redhat01 is the hostname.

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

• Relative Date/Time Calculation: You can use the -d option to specify a


relative date or time
Example 1: $ date -d "3 days ago"
Output: Sat Jan 27 3:46:26 PM UTC 2024

Example 2: $ date -d "+3 days"


Output: Fri Feb 2 3:47:17 PM UTC 2024
• Display Date/Time in a Specific Timezone: Use the TZ environment
variable to set the timezone.
Example: TZ='America/New_York' date
Output: Tue Apr 30 11:36:33 AM EDT 2024

Use Cases – date command


• Logging: Date and time stamps are frequently used in log files to track
when events occur.
• Backup Scripts: Timestamps are useful for naming backup files or
directories.
• Automated Tasks: When scripting automated tasks, date helps generate
dynamic filenames, schedule tasks, etc.
• Monitoring and Reporting: For monitoring systems or generating reports,
precise timestamps are essential.
• Time Synchronization: In conjunction with other utilities (ntpdate,
timedatectl), date helps synchronize the system clock with network time
servers.

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

• Listing Files and Directories


▪ List Specific Directory: You can specify the directory whose
contents you want to list.
Syntax: ls /path/to/directory
Example: $ ls student/data

• Displaying Additional Information


▪ Long Format (-l): Use the -l option to display detailed information
about files, including permissions, ownership, size, and modification
time.
Example: $ ls -l
▪ Human-Readable File Sizes (-h): With the -h option, file sizes are
displayed in a human-readable format (e.g., KB, MB, GB).
Example: $ ls -lh

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

The above statement represents a directory (d) with permissions


rwxr-xr-x.
▪ It has 3 hard links.
▪ It is owned by the user user and belongs to the group group.
▪ Its size is 4096 bytes.
▪ It was last modified on Jan 30 at 10:00.
▪ Its name is directory_name.
Understanding the format is crucial for interpreting the output of the
ls -l command, especially when managing files and directories in
Linux.

• Sorting and Filtering


▪ Sort by Modification Time (-t): Files are sorted by modification
time, with the newest first.
Example: $ ls -lt
▪ Reverse Order (-r): Reverse the order of sorting (e.g., reverse
alphabetical order or reverse modification time).
Example: $ ls -lr

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 Type Indicators


▪ List All Files (-a): Display hidden files (those starting with a dot).
Example: $ ls -a
▪ File Type Indicators (-F): Append indicators to entries to indicate
the file type (e.g., / for directories, * for executables).
Example: $ ls -F

• Colorized Output (--color=auto): Enable colorized output to distinguish


file types and permissions.
Example: $ ls --color=auto

• Recursive Listing (-R): List the contents of directories recursively


Example: $ ls -R

Use Cases – ls command


• Viewing Directory Contents: To see what files and directories are present
in a directory.
• Detailed Information: For obtaining detailed information about files, such
as permissions, ownership, and file sizes.
• Sorting and Filtering: To sort files by various criteria or filter the list to show
only specific types of files.
• Scripting: In scripts to process files or directories.
• Managing Files: When managing files or directories, such as copying,
moving, or deleting them.

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.

How sudo works:


• Authorization: Users who are members of the sudo group or who are listed
in the sudoers file are permitted to execute commands using sudo. Typically,
these users are administrators or users with elevated privileges.
• Command Execution: When a user executes a command with sudo, they
are prompted to enter their own password to verify their identity. If
authentication is successful and the user is authorized, the command is
executed with elevated privileges.
• Logging: sudo logs all commands executed with elevated privileges,
providing an audit trail of administrative actions 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

7. write content into a file


To write content into a file in a Linux terminal, you have several options. Some
commonly used commands to write content into a file are as follows:

• 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

8. Display the file content


To display the contents of a file in the terminal, there are several commands you
can use in Linux:

• 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

9. Search & View the file content


In Linux, there are several ways to search for and view the content of files.

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.

Use Case Examples:


a) Find Files by Name
find /path/to/search -name "filename"
This command searches for files with the exact name "filename" in the
specified directory /path/to/search.

b) Find Files by Pattern


find /path/to/search -name "*.txt"
This command searches for files with names ending in ".txt" in the
specified directory /path/to/search.

c) Find Files Ignoring Case


find /path/to/search -iname "filename"
Similar to -name, but case-insensitive.

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

e) Find Files Based on Modification Time


find /path/to/search -mtime -7
This command searches for files modified within the last 7 days in the
specified directory /path/to/search.

f) Find Files Based on Access Time


find /path/to/search -atime +30
This command searches for files accessed more than 30 days ago in the
specified directory /path/to/search.

g) Find Files Based on Size


find /path/to/search -size +1M
This command searches for files larger than 1 megabyte in the specified
directory /path/to/search.

h) Find Files Based on Permissions


find /path/to/search -perm 644
This command searches for files with specific permissions (in octal
notation) in the specified directory /path/to/search.

i) Find Files by User or Group Ownership


find /path/to/search -user username

find /path/to/search -group groupname


These commands search for files owned by a specific user or group in
the specified directory /path/to/search.

j) Find Files by Combining Criteria


find /path/to/search -name "*.txt" -size +1M
This command searches for files with names ending in ".txt" and larger
than 1 megabyte in the specified directory /path/to/search.

k) Perform Actions on Found Files


find /path/to/search -name "*.log" -exec rm {} \;
This command finds files with names ending in ".log" in the specified
directory /path/to/search and executes the rm command on each found
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

l) Search in Subdirectories Recursively


find /path/to/search -name "*.txt" -type f -exec grep "pattern" {} +
This command searches for files with names ending in ".txt" in the
specified directory /path/to/search and its subdirectories. It then
executes the grep command to search for a specific pattern within each
found file.

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.

Use Case Examples:


a) Find Files by Name
locate filename
This command searches for files or directories containing the specified
filename anywhere in their names.

b) Find Files by Partial Name


locate partialname
This command searches for files or directories containing the specified
partialname anywhere in their names. It's useful for finding files when
you're not sure about the exact name.

c) Find Files in a Specific Directory


locate -r '/path/to/directory/*'
The -r option allows you to specify a regular expression pattern to limit
the search to a specific directory or file path.

d) Find Files by Case Insensitive Search


locate -i filename
The -i option performs a case-insensitive search for the specified
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

e) Find Files Matching Multiple Patterns


locate pattern1 pattern2
You can specify multiple patterns as arguments, and locate will find files
matching any of the patterns.

f) Update the Database


sudo updatedb
The updatedb command updates the locate database, which is typically
done periodically through a cron job. Running this command manually
ensures that the database is up-to-date with the latest file system
changes.

g) Display Number of Matches


locate -c filename
The -c option counts the number of matches for the specified filename
pattern without displaying the actual filenames.

h) Limit Number of Matches


locate -l 5 filename
The -l option limits the number of matches displayed to the specified
number. In this example, only the first 5 matches for filename will be
displayed.

i) Exclude Specific Paths from Search


locate -e '/path/to/exclude/*' filename
The -e option allows you to exclude specific paths or directories from
the search by providing a regular expression pattern.

j) Display Filenames Only


locate -b filename
The -b option displays only the filenames without showing the full paths.

k) Display Path to Located Files


locate -p filename
The -p option displays the full paths to the located files, which can be
useful when you need to know the exact locations.

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.

Use Cases Examples:


a) Simple Search
grep "pattern" file.txt
This command searches for occurrences of "pattern" in file.txt.

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.

e) Print Line Numbers


grep -n "pattern" file.txt
Displays line numbers along with matching lines.

f) Print Only File Names


grep -l "pattern" file1.txt file2.txt
Prints only the names of files containing matches.

g) Count Matching Lines


grep -c "pattern" file.txt
Prints only the count of matching lines.

h) Search for Whole Words


grep -w "pattern" file.txt
Matches only whole words.

i) Using Regular Expressions


grep -e "pattern1" -e "pattern2" file.txt
Searches for multiple patterns simultaneously.

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:

a) egrep (or grep -E)


egrep is an extended version of grep that supports extended
regular expressions (regex). It's the same as using grep -E. With
egrep, you can use more complex regex patterns without escaping
special characters.
egrep "pattern" file.txt
# or
grep -E "pattern" file.txt

b) fgrep (or grep -F)


fgrep is a fixed-string version of grep, meaning it treats the pattern
as a literal string rather than a regular expression. This is useful
when you want to search for a specific string without worrying
about regex interpretation.
fgrep "literal_string" file.txt
# or
grep -F "literal_string" file.txt

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

13. Pipe (Piping in Linux)


In Linux, a pipe (|) is a mechanism that allows the output of one command to be
used as the input for another command. This feature enables powerful and efficient
data processing by chaining together multiple commands to perform complex
tasks. Pipes are a fundamental concept in Unix-like operating systems and are
widely used in command-line interfaces.

Syntax:
The syntax for using a pipe is:
command1 | command2
Here, command1 generates some output, which is then passed as input to
command2.

Use Cases Examples


a) Filtering
Pipes are commonly used to filter data by passing it through
various commands. For instance, you can use grep to filter lines
containing a specific pattern and sort to sort the output
alphabetically.
cat file.txt | grep "pattern" | sort

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

f) Communication Between Processes


Pipes facilitate communication between processes. For example,
you can use echo to send data to another command through a
pipe.
echo "Hello, World!" | grep "Hello"

g) Advanced Data Processing


Pipes are essential for more advanced data processing tasks, such
as analyzing log files, extracting specific information, and
generating reports.
cat access.log | awk '{print $1}' | sort | uniq -c | sort -nr
In this example, we're counting the number of occurrences of each
unique IP address in an Apache access log 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

h) Extracting Specific Columns


You can use cut to extract specific columns from tabular data.
cat data.csv | cut -d ',' -f 1,3
This command extracts the first and third columns from a CSV file.

i) Calculating the Sum of Numbers


You can use awk to calculate the sum of numbers in a file.
cat numbers.txt | awk '{sum+=$1} END {print sum}'

j) Finding Files Modified Today


You can use find and grep to find files modified today.
find . -type f -mtime -1 | grep -v '^./\.'

k) Compressing Files on-the-fly


You can compress files on-the-fly using tar and gzip.
tar cf - directory | gzip > archive.tar.gz

l) Checking Disk Usage


You can use du to check disk usage and sort to sort the output.
du -h | sort -rh | head -n 10

m) Monitoring Log Files in Real-time


You can use tail to monitor log files in real-time and grep to filter
specific lines.
tail -f access.log | grep "404"

n) Extracting Unique Lines


You can use sort and uniq to extract unique lines from a file.
cat file.txt | sort | uniq

o) Converting Text to Uppercase


You can use tr to convert text to uppercase.
echo "hello world" | tr '[:lower:]' '[:upper:]'

p) Counting Word Frequency


You can use tr, sort, and uniq to count word frequency.
cat document.txt | tr -s ' ' '\n' | sort | uniq -c | sort -nr

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

q) Generating Random Passwords


You can use tr, head, and /dev/urandom to generate random
passwords.
head /dev/urandom | tr -dc 'A-Za-z0-9' | head -c 12;
echo

r) Fetching External IP Address


You can use curl to fetch external IP address from a web service.
curl -s ifconfig.me

s) Deleting All Files with a Specific Extension


You can use find and rm to delete all files with a specific extension.
find . -type f -name "*.tmp" -exec rm -f {} +

t) Listing Running Processes


You can use ps to list running processes and grep to filter specific
processes.
ps aux | grep "nginx"

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

Join us for Better Career and Job Guarantee

Full Stack Web Development


Top Edge (MERN Stack) HTML, CSS, JavaScript, ES,
Git, ReactJS, Node, Express, MySQL & MongoDB

Training Full Stack Engineer


Java, JavaScript, ReactJS, Spring, SpringBoot
Hibernate, Linux, AWS, Git, DevOps & Jira

Programs Digital Marketing


Social Media, Website Design, SEO,
Google Ads, Freelancing & Many More

Guaranteed Package (In Writing)


▪ 3-5 Lakhs (With 6 Months Training Programs)
▪ 6-8 Lakhs (With 12 Months Training Programs)
▪ 10 Lakhs+ (With 2 Years Training Programs)

Amenities
▪ Digital Notes ▪ Working Experience
▪ Live Training Sessions ▪ Job Recommendations
▪ Project Assistance ▪ Professional Development
▪ Interview Preparation ▪ Digital Resume & Portfolio

LEARN-2-EARN LABS TRAINING INSTITUTE


Anna Icon Complex, near Kargil Petrol Pump, Sikandra-Bodla Road, Sikandra, Agra
Website : www.LearntoearnLabs.com
Call : 91-9548868337 / +91-9837705705
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability

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

• Globbing: Wildcards are also referred to as "globbing" patterns. Globbing is the


process of expanding wildcard characters into a list of file paths or names that
match the specified pattern.
• Shell Expansion: Wildcards are processed by the shell (such as Bash) before
commands are executed. The shell expands wildcards into a list of matching
filenames or paths, which are then passed as arguments to the command.

Regular Expressions vs. Wildcards

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.

Commands demonstrating the usage of wildcards

• ls: Lists directory contents.


• cp: Copies files or directories.
• mv: Moves (renames) files or directories.
• rm: Removes files or directories.
• find: Searches for files in a directory hierarchy.
• grep: Searches for patterns in files.

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

Linux wildcards along with relevant commands and examples

• *(Asterisk): Matches any sequence of characters (including no characters).


Example: ls *.txt lists all files with a .txt extension in the current directory.
Example: rm *.txt removes all files with a .txt extension in the current directory.

• ? (Question mark): Matches any single character.


Example: ls file?.txt lists files like file1.txt, fileA.txt, but not file12.txt.
Example: rm file?.txt removes files like file1.txt, fileA.txt, but not file12.txt.

• [ ] (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.

• { } (Braces): Expands to multiple patterns separated by commas.


Example: ls file{1,2}.txt lists files like file1.txt, file2.txt.
Example: cp file{1..3}.txt destination/ copies file1.txt, file2.txt, file3.txt to the
destination/ directory.

• ^ (Caret): Used within square brackets to negate a character set.


Example: ls file[^12].txt lists files except file1.txt and file2.txt.

• ! (Exclamation mark): Represents the logical NOT operator when used in


combination with other wildcards.
Example: ls !(*.txt) lists all files except those with a .txt extension.
The above command will not work properly so you need to enable the extended
globbing using command : shopt -s extglob

Now use the command ls !(*.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

Use Cases: Linux Wildcards

• 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"

• Conditional Operations: Wildcards can be used in conditional statements or loops


to perform actions based on file names.
Example: To process all CSV files in a directory using a loop:
for file in *.csv; do
# Process each CSV file
echo "Processing $file..."
done

• Pattern Matching: Wildcards can match specific patterns within filenames.


Example: to list all files starting with "image" followed by a number and ending
with .png: ls image[0-9]*.png

• 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/

• Creating Backups: Wildcards can be used to create backups of files or directories


with specific criteria.
Example: To create a backup of all Python scripts in a directory:
cp *.py backup_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

1. grep: Searches for patterns in files.


Example: Search for lines containing the word "error" in all .log files in the current
directory: grep "error" *.log

2. chmod: Changes file permissions.


Example: Give execute permission to all shell scripts in the current directory:
chmod +x *.sh
The chmod command in Unix-like operating systems (including Linux) is used to
change the permissions (read, write, execute) of files and directories. It stands for
"change mode". The chmod command can be used both in symbolic mode and in
numeric mode.
In symbolic mode, you specify the permissions you want to add or remove using
letters and symbols.
Example: chmod +x file.txt
This command adds the execute permission to the file file.txt.
Example : chmod u=rw file.txt
This command sets the file file.txt so that the owner (u) has read and write
permissions.

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)

Example: chmod 644 file.txt


This command sets the permissions of file.txt so that the owner has read and write
permissions (6), and the group and others have only read permissions (4).
Example: chmod 755 script.sh
This command sets the permissions of script.sh so that the owner has read, write,
and execute permissions (7), and the group and others have read and execute
permissions (5).
In both modes, chmod can be used recursively with the -R option to apply the
permissions changes to all files and directories 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

3. tar: Archives files into a tarball.


Example: Create a tarball (backup.tar.gz) containing all files and directories in the
current directory: tar -czvf backup.tar.gz *

In the command tar -czvf backup.tar.gz *, the -czvf are options and parameters for
the tar command, used for creating an archive file.

Here's what each option does:


• -c : This option stands for "create". It tells tar to create a new archive.
• -z : This option tells tar to compress the archive using gzip compression.
• -v : This option stands for "verbose". It instructs tar to list the files being
processed as it archives them.
• -f : This option is used to specify the name of the archive file. In this case,
backup.tar.gz is the name of the archive file being created.

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).

About tar command

• The tar command in Unix-like operating systems (such as Linux) is used to


create, view, or extract files from an archive file.
• The name "tar" stands for "tape archive," as it was originally designed for
tape backup operations, although it's commonly used for various archival
and file manipulation tasks.
• The command is highly versatile and offers many more options for
manipulating archive files.

Use cases : tar command

• 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

• Compression: tar can also compress archives using various compression


algorithms like gzip (-z option) or bzip2 (-j option).
Example: tar -czvf archive.tar.gz file1 file2 directory
This creates a gzip-compressed archive named archive.tar.gz.

• Verbose Output: The -v option can be used to display verbose output,


showing the progress of the archive operation.

In the context of command-line tools like tar, "verbose" refers to a


mode of operation where the tool provides more detailed or
descriptive output about what it's doing.
When you enable verbose output, the tool will often display
additional information beyond just the essential output, such as
filenames being processed, progress indicators, or diagnostic
messages.

• 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

4. awk: Processes and analyzes text files.


Example: Print the second column of all .csv files in the current directory:
awk -F',' '{print $2}' *.csv

The awk command in Unix-like operating systems is a powerful text processing


tool that operates on data files, extracting and manipulating information. It's
particularly useful for processing structured text data, such as tables or logs, and is
often used in shell scripting.

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 basic syntax of an awk command is:


awk 'pattern { action }' filename

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).

Use Cases : awk command

• Extracting Columns: awk can be used to extract specific columns from a


file.
Example: To extract the second column from a CSV file:
awk -F',' '{print $2}' filename.csv

• Filtering Rows: awk can filter rows based on certain conditions.


Example: To print lines where the third column contains the word "error":
awk '$3 == "error" {print}' logfile.txt

• Performing Arithmetic Operations: awk can perform arithmetic


operations on data.
Example: To calculate the total of the second column in a file:
awk '{total += $2} END {print total}' filename.txt

• Formatting Output: awk can format output in various ways.


Example: To print only lines longer than 80 characters:
awk 'length > 80' filename.txt

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

5. sed: Stream editor for text manipulation.


Example: Replace all occurrences of "oldword" with "newword" in all .txt files:
sed -i 's/oldword/newword/g' *.txt

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.

The basic syntax of the sed command is:


sed options 'commands' filename
where,
• options: These are optional flags that modify the behavior of sed. Common
options include -e to specify multiple commands and -i to edit files in-place.
• 'commands': This is a sequence of editing commands to be applied to each
line of the input. These commands can include search and replace
operations, deletion, insertion, and more.
• filename: This is the name of the file(s) to be processed by sed. If no filename
is provided, sed reads from the standard input (often piped data).

Use Cases : sed command

• 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

• Delete Lines: sed can delete lines based on specified conditions.


Example : To delete all lines containing the word "delete":
sed '/delete/d' 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

• Substitution with Regular Expressions: sed supports powerful regular


expressions for pattern matching and substitution. This allows for complex
text transformations.
Example: To replace all occurrences of digits with "X":
sed 's/[0-9]/X/g' filename.txt

Additional Examples

• Matching Specific Characters


ls file[123].txt # Matches file1.txt, file2.txt, file3.txt

• Matching Ranges of Characters


ls file[1-3].txt # Matches file1.txt, file2.txt, file3.txt

• Excluding Characters
ls file[!12].txt # Matches files except file1.txt and file2.txt

• Expanding to Multiple Patterns


cp file{1..3}.txt destination/ # Copies file1.txt, file2.txt, file3.txt to destination/

• Negating Patterns
ls file[^12].txt # Matches files except file1.txt and file2.txt

• Using Brace Expansion


touch {file1,file2,file3}.txt # Creates file1.txt, file2.txt, file3.txt

• Conditional Operations
for file in file*.txt; do
echo "Processing $file..."
done

• Searching for Files Recursively


find . -type f -name "*.txt" # Finds all text files in the current directory and its
subdirectories

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.

Key directories and their purposes

• / (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.

• /bin (Binary Binaries)


This directory contains essential executable binaries (programs) that are required
by the system for basic operations, such as ls, cp, mv, etc.

• /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.

• /etc (Editable Text Configuration)


Stores system-wide configuration files. This directory contains various
configuration files for the system and installed applications.

• /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.

• /proc (Process Information)


A virtual file system that provides information about running processes and system
resources as files. It's commonly used for debugging and monitoring.

• /sbin (System Binaries)


Contains essential system administration binaries. These executables are typically
used by the system administrator for system maintenance and configuration.

• /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.

• /usr (Unix System Resources)


Contains user binaries, libraries, documentation, and other resources not required
for the system's basic operation. It's further divided into subdirectories like
/usr/bin, /usr/lib, /usr/include, etc.

• /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.

• /sys (System Information)


A virtual file system that provides information about the system's hardware and
kernel configuration. It exposes kernel data structures as files, allowing
administrators and applications to interact with the kernel.

• /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.

• /mnt vs. /media


Historically, /mnt was used as a generic mount point for temporarily mounting file
systems. However, many distributions now use /media for mounting removable
media devices, while /mnt is often used for manually mounting other file systems.

• 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.

• Hidden Files and Directories


Files and directories whose names start with a dot (.) are considered hidden in
Linux. These files are often configuration files or directories containing application-
specific settings.

Linux File System


• The Linux file system is the method by which files are organized and stored on a
Linux-based operating system. It encompasses the structure, organization, and
management of files and directories within the system.
• Understanding the Linux file system is crucial for managing files, configuring the
system, and ensuring efficient operation.
• Understanding the Linux file system is essential for system administration, file
management, and troubleshooting. With knowledge of the file system hierarchy,
file types, permissions, and maintenance procedures, administrators can effectively
manage and maintain Linux-based systems.

Key Point : Linux File System

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

o /boot: Boot loader files and the Linux kernel.


o /etc: System-wide configuration files.
o /home: User home directories.
o /lib or /lib64: Shared libraries.
o /mnt or /media: Mount points for external devices.
o /usr: User-related programs and data.
o /var: Variable data such as logs and spools.

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.

4. File System Types


• Ext4: The default and most commonly used file system on Linux systems.
• XFS: Known for scalability and performance, often used in enterprise
environments.
• Btrfs: Supports features like snapshots, subvolumes, and checksums.
• ZFS: Offers advanced features like data integrity, RAID-Z, and snapshots
(not commonly used on Linux due to licensing issues).
• NTFS: Often used for compatibility with Windows systems.
• FAT32/exFAT: Commonly used for removable media due to cross-platform
compatibility.

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.

7. File System Maintenance


• File System Check (fsck): Checks and repairs file system integrity.
• File System Resize (resize2fs): Expands or shrinks the size of an ext2/3/4
file system.
• File System Defragmentation: Not commonly needed on Linux due to file
system design.

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.

10. Virtual File Systems


Virtual file systems provide an interface to kernel data structures and system
information.
Examples include /proc, /sys, and /dev.

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

Join us for Better Career and Job Guarantee

Full Stack Web Development


Top Edge (MERN Stack) HTML, CSS, JavaScript, ES,
Git, ReactJS, Node, Express, MySQL & MongoDB

Training Full Stack Engineer


Java, JavaScript, ReactJS, Spring, SpringBoot
Hibernate, Linux, AWS, Git, DevOps & Jira

Programs Digital Marketing


Social Media, Website Design, SEO,
Google Ads, Freelancing & Many More

Guaranteed Package (In Writing)


▪ 3-5 Lakhs (With 6 Months Training Programs)
▪ 6-8 Lakhs (With 12 Months Training Programs)
▪ 10 Lakhs+ (With 2 Years Training Programs)

Amenities
▪ Digital Notes ▪ Working Experience
▪ Live Training Sessions ▪ Job Recommendations
▪ Project Assistance ▪ Professional Development
▪ Interview Preparation ▪ Digital Resume & Portfolio

LEARN-2-EARN LABS TRAINING INSTITUTE


Anna Icon Complex, near Kargil Petrol Pump, Sikandra-Bodla Road, Sikandra, Agra
Website : www.LearntoearnLabs.com
Call : 91-9548868337 / +91-9837705705
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability

AWS EC2 Instance File System


• The file system on an Amazon Elastic Compute Cloud (EC2) instance running Linux
is essentially the same as the file system structure on any other Linux server.
• The file system on an EC2 instance running Linux consists of the root volume,
additional EBS volumes if attached, and potentially instance store volumes.
• These volumes are formatted with a Linux file system and mounted at specific
mount points within the file system hierarchy, allowing for persistent storage and
data management.
• Additionally, services like EFS can be used to create shared file systems for use with
multiple EC2 instances.

Key aspects specific to EC2 instances

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.

2. Additional EBS Volumes


• You can attach additional EBS volumes to an EC2 instance for data storage
or other purposes.
• These EBS volumes are also formatted with a Linux file system (such as Ext4
or XFS) and mounted at specific mount points within the file system.
• EBS volumes provide persistent storage that persists independently of the
instance's lifecycle.

3. Instance Store Volumes (if applicable)


• Some EC2 instance types come with instance store volumes (ephemeral
storage) in addition to the root volume.
• Instance store volumes are physically attached to the host server and
provide temporary block-level storage.

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.

5. Network File System (NFS)


• You can use Amazon Elastic File System (EFS), a scalable and fully managed
NFS-based file storage service, to create shared file systems accessible by
multiple EC2 instances.
• EFS volumes are mounted on EC2 instances like any other file system,
allowing multiple instances to read and write data to the same shared
storage.

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

User Management in Linux


• User management in Linux involves creating, modifying, and deleting user
accounts, as well as managing user permissions and groups.
• User management in Linux is crucial for maintaining system security and
controlling access to resources.

Exercises: User Management

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".

2. Setting Password for the User


After creating the user, you should set a password for the user using the passwd
command.
For example:
sudo passwd learn2earnLabs
You will be prompted to enter and confirm the password for the user.
If you will get “authentication token manipulation errors” then try running the
passwd command with sudo and the -i option to simulate initial login.
For example:
sudo -i passwd 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

4. Viewing User Information


To view detailed information about a user, you can use the id command or the
getent command.
For example:
id 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

5. Switching User
You can switch to another user using the su command followed by the username.
For example:
su - learn2earnLabs

6. Reset Password Manually


If the login issue persists, you can try resetting the password manually using the
passwd command with the --stdin option.
For example:
echo "new_password" | sudo passwd --stdin learn2earnLabs
Replace "new_password" with the desired password.

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

If you're receiving the message "userdel: user learn2earnLabs is currently used by


process 1830," it means that there is a process running under the user
learn2earnLabs. Before you can delete the user, you should ensure that no
processes are running under that user.
To resolve this issue, you need to follow the below steps:
• Identify the process: The number 1830 is the process ID (PID) of the process
running under the user john. You can use the ps command to list the processes
and find out what process is running under that user.
For example:
ps -u learn2earnLabs
This command will list all processes owned by the user
learn2earnLabs. Note the process IDs and the commands associated
with them.

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

Still finding difficulty in deleting the user?

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.

To resolve the issue, you need to follow the below steps:

• 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

Once all SSH sessions are terminated, you should be able to


delete the user without any issues.

• 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.

8. Modifying User Attributes


You can modify user attributes using the usermod command.
For example, to change the user's home directory:
sudo usermod -d /home/new_home_dir 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

9. Managing User Groups


Users can belong to one or more groups. To create a new group, use the groupadd
command.
For example:
sudo groupadd developers

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

10. Listing Users and Groups


As you already know that you can list all users on the system using the cat
command with the /etc/passwd file.
For example:
cat /etc/passwd
To list all groups, you can use the cat command with the /etc/group file.
For example:
cat /etc/group

11. Granting Sudo Privileges


To grant a user sudo privileges, you can add the user to the sudo or wheel group.
For example:
sudo usermod -aG sudo learn2earnLabs
This allows the user to execute commands with superuser privileges using sudo.

12. Revoking Sudo Privileges


To revoke sudo privileges for a user, remove the user from the sudo or wheel
group.
For example:
sudo deluser learn2earnLabs sudo

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


Or
usermod: group 'sudo' does not exist

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.

To resolve this, you need to follow the below steps:

• 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.

Using getent is advantageous because it provides a consistent interface for querying


system databases, regardless of their actual source (local files, LDAP, etc.). This makes it a
versatile tool for system administration tasks.

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

Grant sudo privileges to the newly created user


To grant sudo privileges to a newly created user on an AWS EC2 Linux instance, you
typically follow these steps:

• 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.

• Modify sudoers file (not recommended unless necessary): If you need to


customize sudo privileges extensively, you can modify the sudoers file using the
visudo command.
However, it's important to be extremely careful when editing this file to avoid
inadvertently locking yourself out of sudo access.
sudo visudo
Then, you can add specific configurations for your new user. For example:
newusername ALL=(ALL) ALL

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:

• Delayed Group Membership: Sometimes, group membership changes may not


take effect immediately. Try logging out and logging back in as the new user to
ensure that the group membership has been updated.

• 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.

How permissions are managed?

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.

You can use ls -l command to view file permissions:


ls -l filename
To modify file permissions, you can use the chmod command followed by the
permission settings:
chmod permissions filename

Use-Cases : chmod permissions filename

The chmod command in Linux is used to change the permissions of a file or


directory. It allows you to modify the read, write, and execute permissions for the
owner, group, and others.

How to use chmod

• Using Numeric Representation


You can represent file permissions numerically using a three-digit code,
where each digit represents the permissions for the owner, group, and
others, respectively.
Each digit is calculated by adding the values for read (4), write (2), and
execute (1) permissions.

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

• Using Symbolic Representation


You can also use symbolic representation to specify permissions.
The symbolic representation consists of three parts:
▪ who the permission applies to (owner, group, others),
▪ the operation to perform (add, remove, set), and
▪ the permission type (read, write, execute).

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

To remove execute permission from the group:


chmod g-x filename

To set exact permissions for owner, group, and others:


chmod u=rw,g=r,o=r 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

• Combining Symbolic Representation


You can also combine multiple operations and permissions in a single
chmod command.
For example, to give the owner read and write permissions, and remove
execute permission for the group:
chmod u+rw,g-x filename

• 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

Working with Special Permissions


Special permissions in Linux, such as setuid, setgid, and sticky bit, can be
managed in the following manner:

• Setuid (Set User ID)


When the setuid permission is set on an executable file,
the file will be executed with the permissions of the file's
owner instead of the user who is running it.
This is commonly used for executable files that need to be
run with elevated privileges.

To set the setuid permission on a file, you can use the


chmod command with the numeric mode or symbolic
mode:
chmod u+s filename

For example, to set the setuid permission on an executable


file named myprogram:
chmod u+s myprogram

• Setgid (Set Group ID)


When the setgid permission is set on a directory, all files
created within that directory will inherit the group
ownership of the directory instead of the group ownership
of the user who created the file.
This is useful for directories that need to be shared among
multiple users who belong to the same group.

To set the setgid permission on a directory, you can use


the chmod command:
chmod g+s directory

For example, to set the setgid permission on a directory


named shared:
chmod g+s shared

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

For example, to set the sticky bit on a directory named


temp:
chmod +t temp

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

Join us for Better Career and Job Guarantee

Full Stack Web Development


Top Edge (MERN Stack) HTML, CSS, JavaScript, ES,
Git, ReactJS, Node, Express, MySQL & MongoDB

Training Full Stack Engineer


Java, JavaScript, ReactJS, Spring, SpringBoot
Hibernate, Linux, AWS, Git, DevOps & Jira

Programs Digital Marketing


Social Media, Website Design, SEO,
Google Ads, Freelancing & Many More

Guaranteed Package (In Writing)


▪ 3-5 Lakhs (With 6 Months Training Programs)
▪ 6-8 Lakhs (With 12 Months Training Programs)
▪ 10 Lakhs+ (With 2 Years Training Programs)

Amenities
▪ Digital Notes ▪ Working Experience
▪ Live Training Sessions ▪ Job Recommendations
▪ Project Assistance ▪ Professional Development
▪ Interview Preparation ▪ Digital Resume & Portfolio

LEARN-2-EARN LABS TRAINING INSTITUTE


Anna Icon Complex, near Kargil Petrol Pump, Sikandra-Bodla Road, Sikandra, Agra
Website : www.LearntoearnLabs.com
Call : 91-9548868337 / +91-9837705705
Learn-2-Earn Labs - Best Institute for job opportunities, & career stability

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.

How you can manage processes

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).

▪ kill -SIGSTOP pid


This command sends the SIGSTOP signal to the process
identified by the specified process ID (pid).
The SIGSTOP signal instructs the operating system to pause
the execution of the process.
When a process receives this signal, it is suspended and will
not execute until it receives a SIGCONT signal.
▪ kill -SIGCONT pid
This command sends the SIGCONT signal to the process
identified by the specified process ID (pid).
The SIGCONT signal instructs the operating system to resume
the execution of the previously stopped process.
When a process receives this signal, it continues execution if
it was previously stopped by a SIGSTOP signal.

These signals are commonly used for process management, such as


pausing and resuming background processes or controlling the
execution flow of certain tasks.

For example, you might use SIGSTOP to temporarily halt a process to


perform debugging or troubleshooting, and then use SIGCONT to
resume its execution once the debugging is complete.

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:

• kill: The kill command sends a signal to a process, requesting it to terminate.


The default signal is SIGTERM, but you can also use SIGKILL to force
termination.
kill pid
• pkill: The pkill command allows you to kill processes by name or other
attributes.
pkill processname

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.

Commands and examples

1. Update Package Lists


Before installing new software or updating existing packages, it's essential to
update the package lists to get the latest information about available packages.
Use the following commands:
For CentOS/RHEL-based systems
sudo yum update
For Debian/Ubuntu-based systems
sudo apt update

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

4. Search for Software


You can search for available software packages using the package manager's
search command.
For CentOS/RHEL-based systems
yum search keyword
For Debian/Ubuntu-based systems
apt search keyword
Replace keyword with the term you want to search for.

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

6. Check Installed Software


You can check the installed software packages and their versions using various
commands such as rpm, yum, dpkg, apt, etc., depending on the package manager
used by your Linux distribution.
For CentOS/RHEL-based systems
rpm -qa | grep package_name

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.

For example, let's use the text editor "Nano".

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

2. Searching for Nano


For Debian/Ubuntu-based systems
apt search nano
For CentOS/RHEL-based systems
yum search 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

5. Checking Installed Software


For Debian/Ubuntu-based systems
dpkg -l | grep nano
For CentOS/RHEL-based systems
rpm -qa | grep nano

6. Monitoring Nano (Optional)


You can monitor Nano using process monitoring tools like top. However, Nano
doesn't usually run as a background process, so monitoring may not be necessary
in this case.
Since Nano is a text editor and not a running service, monitoring isn't typically
necessary.

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 & Tar


"Links" and "Tar" refer to two different concepts related to file management and
compression.

Links
In Linux, a "link" is a pointer or reference to a file or directory.

There are two main types of links:

• 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.

To create a hard link, you can use the ln command:


ln /path/to/original_file /path/to/hard_link

for example,
ln data/files/index.html data/myhardlink

• Symbolic links (symlinks)


▪ Also known as soft links, these are references to the filename of a
target file.
▪ Symbolic links are like shortcuts or aliases to the original file.
▪ If you delete the original file, the symbolic link will point to nothing
(a broken link).

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.

• Extracting files from a tarball


tar -xvf archive.tar
where,
-x: Extract files from an archive.

• Compressing a tarball (optional)


tar -czvf archive.tar.gz file1 file2 directory
where,
-z: Compress the tarball using gzip compression.

• Extracting files from a compressed tarball


tar -xzvf archive.tar.gz
where,
-x: Extract files from an archive.
-z: Use gzip compression.

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

Logs in Linux Systems


• Logs in Linux systems are textual records of system events, processes, and activities.
• They provide valuable information for troubleshooting, monitoring system health,
and detecting security issues.
• Linux maintains various log files located in different directories, each serving a
specific purpose.
• By regularly monitoring log files, you can detect and address issues promptly,
ensuring the stability and security of your Linux system.

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

• /var/log/messages: Similar to syslog, contains general system messages,


but it's typically used on Red Hat-based systems.
tail -n 100 /var/log/messages # View the last 100 lines of messages

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.

• Verify SELinux Context: If SELinux (Security-Enhanced Linux) is enabled on


your system, it may enforce additional security policies that restrict file
access. Check the SELinux context of the /var/log/secure file using the ls
command with the -Z option.
ls -Z /var/log/secure
If the SELinux context is causing the permission denied error, you may need
to adjust the SELinux context or policies accordingly.

• Check Filesystem Integrity: Ensure that the filesystem containing the


/var/log/secure file is not mounted as read-only or experiencing other
filesystem issues. You can use the mount command to check the filesystem
status.
mount
If the filesystem is mounted as read-only or has errors, you may need to
remount it with the proper permissions or repair any filesystem issues.

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.

Additionally, if you want to configure the system to log kernel messages to a


separate file such as /var/log/kern.log, you may need to adjust the logging
configuration in the /etc/rsyslog.conf file. However, keep in mind that modifying
system logging configuration files should be done carefully to avoid disrupting
system logging functionality.

4. Application Logs
Application logs contain information specific to applications running on the
system, such as web servers, databases, and custom applications.

• Apache Web Server Logs


▪ Access Log (access.log): Records HTTP requests made to the web
server.
tail -n 100 /var/log/apache2/access.log # View the last 100
lines of access log

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

▪ Error Log (error.log): Records errors and warnings encountered by


the web server.
tail -n 100 /var/log/apache2/error.log # View the last 100
lines of error log

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.

b) Installing Apache (If Not Installed)


If Apache is not installed on your EC2 instance and you want to use it, you
can install it using the following command:
sudo yum install httpd
After installation, you can start the Apache service and enable it to start
automatically on boot:
sudo systemctl start httpd
sudo systemctl enable httpd
Once Apache is installed and running, you can follow the steps mentioned
earlier to view its log files.

c) Viewing Apache Log Files


Assuming Apache is installed and running, you can view its log files to
monitor server activity and troubleshoot issues. Common Apache log files
include:
Access Log: Records all requests made to the server, including IP
addresses, requested URLs, status codes, etc.
sudo tail -n 100 /var/log/httpd/access_log
Error Log: Records errors and warnings encountered by the server.
sudo tail -n 100 /var/log/httpd/error_log

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. Viewing Logs in Real-Time


You can use the tail command with the -f option to view logs in real-time as they
are being written to.
tail -f /var/log/syslog # View syslog in real-time

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.

If you need to troubleshoot specific components or services, you may need to


check other log files located in /var/log/.
For example, Apache web server logs are typically located in /var/log/httpd/, and
other services may have their own log files in different locations.

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

Join us for Better Career and Job Guarantee

Full Stack Web Development


Top Edge (MERN Stack) HTML, CSS, JavaScript, ES,
Git, ReactJS, Node, Express, MySQL & MongoDB

Training Full Stack Engineer


Java, JavaScript, ReactJS, Spring, SpringBoot
Hibernate, Linux, AWS, Git, DevOps & Jira

Programs Digital Marketing


Social Media, Website Design, SEO,
Google Ads, Freelancing & Many More

Guaranteed Package (In Writing)


▪ 3-5 Lakhs (With 6 Months Training Programs)
▪ 6-8 Lakhs (With 12 Months Training Programs)
▪ 10 Lakhs+ (With 2 Years Training Programs)

Amenities
▪ Digital Notes ▪ Working Experience
▪ Live Training Sessions ▪ Job Recommendations
▪ Project Assistance ▪ Professional Development
▪ Interview Preparation ▪ Digital Resume & Portfolio

LEARN-2-EARN LABS TRAINING INSTITUTE


Anna Icon Complex, near Kargil Petrol Pump, Sikandra-Bodla Road, Sikandra, Agra
Website : www.LearntoearnLabs.com
Call : 91-9548868337 / +91-9837705705
LEARN-2-EARN LABS TRAINING INSTITUTE
F-4, First Floor, Anna Icon Complex,
near Kargil Petrol Pump, Sikandra-Bodla Road,
Sikandra, Agra, Uttar Pradesh, India

Website : www.LearntoearnLabs.com

Call : 91-9548868337 / +91-9837705705

You might also like