0% found this document useful (0 votes)
7 views12 pages

The IT Professional's Linux Handbook - Commands, Concepts

Linux is a free and open-source operating system known for its security, stability, and flexibility, supporting multiple users and multitasking. It has various distributions like RedHat and Ubuntu, and features a hierarchical file system. The document outlines key components such as the kernel, shell, commands, and user management, along with essential commands for system, hardware, file, and network operations.

Uploaded by

samreenss2414
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)
7 views12 pages

The IT Professional's Linux Handbook - Commands, Concepts

Linux is a free and open-source operating system known for its security, stability, and flexibility, supporting multiple users and multitasking. It has various distributions like RedHat and Ubuntu, and features a hierarchical file system. The document outlines key components such as the kernel, shell, commands, and user management, along with essential commands for system, hardware, file, and network operations.

Uploaded by

samreenss2414
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/ 12

LINUX

Operating System (OS):

An Operating System is system software that serves as an interface between computer


hardware and the end user. It manages hardware resources and provides a platform for
applications such as web browsers, office suites, text editors, and games to function.
Every computing device requires at least one operating system to operate efficiently and
run application software.

Linux:

Linux is a free and open-source operating system known for its robust security, stability,
and flexibility. It is a multi-user, multitasking system primarily operated through a
command-line interface, although graphical interfaces are also available.

Key Features of Linux:

• Open-Source Model: The source code of Linux is freely available for use,
modification, and distribution.
• Multi-User Capability: Multiple users can access system resources such as
memory and processing power simultaneously without interfering with each
other.
• Multitasking: Linux can run multiple applications or processes concurrently.
• Enhanced Security: Built-in user permissions, encryption, and firewall features
provide a secure operating environment.
• Versatile Usage: Widely used in servers, embedded systems, supercomputers,
mobile devices, and cloud infrastructure.

Linux OS Distributions:

Many of the users taken the Linux OS and modified according to their requirements and
released into the market with different names called Linux distributions.
• RedHat
• Ubuntu
• Debian
• Centos
• Fedora
• OpenSUSE
• Kali Linux
• Amazon Linux
• Rocky Linux
History:

On Sep 17th 1991, Linus Torvalds a student at the university of Helsinki, Finland, He
released the first version of Linux Kernel, Known as Linux 0.01, as an open-source
software.

• The Linux Kernel is written in C language


• He wrote this program specially for his own pc
• Firstly, he wanted to name it as 'Freax' but later it became 'Linux'
• Today, Supercomputers, smartphones, desktop, web servers, tablets, laptops,
and home appliances like washing machines, DVD players, routers, modems,
cars, refrigerators, etc. Use Linux OS.

KERNEL:

It is the core or the heart of the Operating system. It is the central part that manages
and facilitates communication between the computer's hardware and software.

SHELL:

A shell that allows users to interact with the OS.

• Command Line Interface (CLI): Executes the command provided by user and
display the output in terminal.
• Executes the process provided by the user in graphical way and output is
displayed in the graphical windows.
COMMAND:

• It is an instruction/request given to the OS by a user.


• It tells computer to perform a particular task.

TERMINAL:

• It is a text-based interface that allows you to interact with the operating system
by typing commands.
• It is a way for you to communicate with the Linux machines

Linux File System Hierarchy

• / – Root directory
• /home – User directories
• /etc – Configuration files
• /bin – Essential binaries
• /var – Log files
• /tmp – Temporary files
• /dev – Device files
• /proc – Kernel and process info

If you are using AWS EC2 instances - By default, we are in ec2-user, but if we want to
perform any action, we should be in root user because, root is the ultimate king of
Linux, root has full permissions, so that we can run any command anywhere.

To login as root user: sudo -i

Here sudo: super user do

to logout from root user and go back to ec2-user: exit

In Linux we have different types of commands

• SYSTEM COMMANDS
• HARDWARE COMMANDS
• FILE COMMANDS
• FOLDER COMMANDS
• PERMISSION COMMANDS
• USER COMMANDS
• GROUP COMMANDS
• OWNER COMMANDS
• SEARCH COMMANDS
• NETWORKING COMMANDS

System Commands:

Command Description

uname Used to get type of OS


uname -r Used to get kernel version of our OS
uname -a Used to get full info about OS

clear or ctrl+l Used to clear screen

uptime Used to get since how long our system is in running state
uptime -p Used to get only screen up time

hostname Used to get private dns name of our system


hostname -l used to get private ip of our system
hostnamectl set-hostname "Suresh" Used to change hostname

ip addr or ip route or ifconfig Used to get Private IP

Used to see how many users have been login to our


who system
whoami Used to get the current user
ps Used to see the running processes in system
kill -9 PID Used to kill a process

sudo timedatectl set-timezone


Asia/kolkata Used to change the timezone to IST
timedatectl Used to check the available timezones

date Shows system date and timestamp


date+"%d" Prints day of the month(01-31)
date+"%m" Prints the month of the year 01-12
date+"%y" prints only the last two digits of year
date+"%H" Prints the hour 00-23
date+"%M" Prints the Minute of the hour 00-59
date+"%S" Prints the current seconds count in the minute 00-60
date+"%D" Prints date in MM/DD/YY
date+"%F" Prints only the Full date as YYYY-MM-DD
date+"%A" Prints the day of the week Saturday-Sunday
date+"%B" Prints the month between Jan-Dec
Hardware Commands:

Command Description
lscpu Displays information about the CPU architecture
Lists the information about all the block devices attached to
lsblk -a the system
free Displays system memory(RAM) details in kb
free -m Displays system memory(RAM) details in mb
Report files system disk space usage in human readable
df -h languages

File Commands:

Command Description

touch filename Used to create a file


touch file1 file2 file3 Used to create multiple files
touch file{1..5} Used to create multiple files in order
rm file1 Used to remove file with permissions
rm -f file2 Used to remove file without permission (-f means forcefully)
rm -f file1 file2 file3 Used to remove multiple files
rm -f file{1..5} Used to remove multiple files
rm -f* Used to remove all files
rm -f*.txt used to delete all files with .txt extension
rm -f a* Used to delete files which are started with "a" letter

Folder Commands:

Command Description

mkdir foldername Used to create a folder


mkdir folder1 folder2 Used to create multiple folders
mkdir folder{1..5} Used to create multiple folders in order
rmdir foldername Used to delete empty folder
rmdir folder1 folder2 Used to delete multiple folders
rmdir folder{1..5} Used to delete multiple folders
rmdir * Used to delete all empty folders
Used to remove all the files & folders - also it is used to remove
rm -rf* non empty folders
mkdir folder1/folder2 Used to create folder2 inside folder1
ll folder1 Used to get list of files/folders which are present in folder1
touch folder/file.txt used to create file inside folder
mkdir -p folder1/folder2/folder3 Used to create parenting folder(folder inside folder) automatically

List the files

used to get list of files with full info about files/folders in order(A-
ll Z)
ls used to get list of files with only file/folder names
ll -t Used to see list of files based on modification/creation time
ll -r Used to see the files in reverse order(Z-A)
ll -a Used to see all files including hidden

Change Directory

Command Description

cd foldername Used to change directory


cd - Used to go to previous folder
cd ../ Used to go to one folder back
cd ../../ Used to go to two folders back

Copy Command:

Syntax: cp source destination

Command: cp file1 file2

• By using above command, the data from file1 copies into file2. But the problem
is it will overwrite the data present in file2
• To overcome this issue, we will use cat command.

Syntax: cat source_file >> destination_file

Move Command:

Syntax: mv source destination

Command: mv file1 file2

• This is also called renaming a file.


Cat Commands:

Cat command is used to read the data from a file, it is also used to append the data in a
file.

• Cat filename: Used to read data from file


• Cat > filename : Used to overwrite the data
• Cat >> filename: Used to append the data
• cat -n filename : prints the data with line numbers
• head filename : used to print top 10 lines
• tail filename: used to print last 10 lines
• head -n 12 filename: used to print first 12 lines of file
• sed -n ’15,30p’ filename: used to print 15-30 lines of file

Note: Cat command is used to append the data, but here the problem is, it is not
possible to modify the data. To avoid this issue we can use editor in Linux.

There are 2 types of editors in Linux

1. Vim editor
2. Nano editor

Vim editor:

It has 3 modes,

1. Command mode
2. Insert mode
3. Save & quit mode

To open any file in vim editor: vim filename or vi filename

Command Mode:

It is the default mode in vim editor, it is used to perform some actions like copy the
data, delete the data and we can undo and redo the changes as well.

Command Description

gg Used to go to 1st line of the file


G Used to go to last line of the file
M Used to go to middle of the file
4gg Used to go to 4th line of the file
:25 Used to go to 25th line of the file
:set number Used to set numbers to lines in the file
yy Used to copy the line
4yy Used to copy 4 lines starting from cursor position
p Paste the copied content
10p Used to paste copied content 10 times
dd Used to delete the line
3dd Used to delete the 3 lines from the cursor
u Used to undo the changes
ctrl+r Used to redo the changes
:%s/old/new/ Used to replace
/word Used to search for a word in file
?word Used to search for a word in file

Insert mode:

This mode is used to insert the data or make any modifications to the file

• To go to insert mmode: i
• To go back to command mode: esc
• To go to the ending of the line: A
• To go to the starting of this line: I
• To create a new line above the cursor: O
• To create a new line below the cursor: o

Save &quit mode:

This is used to save the data and quit from vim editor

• To save the data - :w


• To quit from vi editor - :q
• To quit forcefully - :q!
• To save & quit at a time - :wq
• To save & quit forcefully at a time - :wq!

User commands:

Cat/etc/passwd: Used to get list of users

Useradd username: Used to add user

NOTE:

• whenever we add any user, then folder will gets created in /home directory
• Whenever we add any user, then group also created automatically
Userdel username: used to delete user

NOTE:

• Whenever we delete any user, then folder will not gets deleed in /home
directory
• Whenever we delete any user, then group will gets deleted

Userdel -r username: used to remove the user along with folder

Useradd -M username: used to create a user without folder

Su -username: used to switch to another user

Passwd username: used to set a password to user

Group commands:

Cat/etc/group: used to get list of groups

Groupadd group_name: used to add a group

Groupdel group_name: used to delete group

Usermod -a -G group user: used to add a user in a group

GREP (Global Regular Expresion Print):

It is used to search for a word in a file

Syntax: grep “word” filename

• Grep “word” filename: used to search for a word in a file


• Grep -n “word” filename: used to print the data along with line numbers
• Grep -c “word” filename: used to print no of occurances of a word
• Grep -I “word” filename: used to search for a case-sensitive

Owner Commands:

• Chown user filename: Used to change the user of a file


• Chgrp group file: used to change group of a file
• Chown user:group filename: used to change user and group at a time
• Chown user:group file1 file2 file3: used to change user and group to multiple
files
• Chown user:group folder: used to change owner to folder only
• Chown user:group folder/*: Used to change owners to files only in folder
• Chown -R user:group folder: used to change owners to file and folder at a time

Permission Commands:

• Chmod 745 filename: Used to change the permission of a file


• Chmod 777 file1 file2 fie3: used to change permissions to multiple files
• Chmod 654 folder: used to change permissions to folder only
• Chmod 567 folder/*: used to change permissions t files only in folder
• Chmod -R 123 folder: used to change permissions to file and folder at a time

Search commands:

It is used to search for file, there are 2 types

1. Find command
2. Locate command

Find Command:

Syntax: find path -name file_name

• Find . -name file: used to find a file in current directory


• Find /proc/ -name filename: Used to find a file in proc directory
• Find . -type d -name folder: Used to find a folder in current directory
• Find . -type f -name <file1.txt>: used to find a file in current directory
• Find . -type f -perm 777: finds all the files whose permissions are 777 in the
current directory.
• Find . -type f! -perm 777: finds all the files whose permissions are NOT 777 in the
current directory.
• Find / -user <username>: finds all the files specific user owned in /directory
• Find / -group groupname: finds all the files specifc group owned in /directory

Locate Command:

Syntax: locate filename

Note: If you are using locate command, we have to update the db of linux before
performing locate command.
Find vs locate: Find commands will search as per the path that we mentioned in
command, but locate command will search for a file on entire database.

Network Commands:

Command Description
Basic Network Configuration

ip a or ip addr Show IP addresses of all interfaces


ip link Show network interfaces
ip route Show routing table
ifconfig Legacy tool to view/set IP addresses
ip link set eth0 up/down Enable or disable interface
hostname Show or set system hostname
hostname -I Show IP addresses assigned to the host
nmcli Manage NetworkManager (used in many distros)

Network Connectivity

ping <host> Send ICMP echo requests


traceroute <host> Show route packets take to a host
mtr <host> Dynamic network diagnostic tool (ping + traceroute)
curl <url> Fetch data from a URL
wget <url> Download files from the web
telnet <host> <port> Check connectivity to a specific port
nc <host> <port> Netcat, for testing TCP/UDP connections

DNS Tools

nslookup <domain> Query DNS records


dig <domain> Detailed DNS query
host <domain> Simple DNS lookup

Port and Socket Analysis

ss -tuln Show listening ports and associated services


netstat -tuln Legacy tool to view open ports
lsof -i List open files related to network connections
ss -s Summary of current socket usage
Network Management

ip link add <name> type


bridge Create a new bridge interface
ip link delete <name> Delete a network interface
ethtool <interface> Display or change Ethernet device settings
iwconfig Configure wireless interfaces (deprecated, use 'iw')
nmcli device status Show status of network interfaces

Network Monitoring

iftop Real-time bandwidth usage per connection


nload Visual interface for traffic monitoring
vnstat Network traffic monitor
ip -s link Show interface stats
tcpdump Capture and analyze network packets
wireshark GUI tool for packet analysis

Firewall & Security

iptables -L List firewall rules (legacy)


ufw status Show UFW firewall status (Ubuntu)
firewalld-cmd --list-all Show Firewalld rules (RHEL/CentOS)
nmap <host> Scan open ports on a host

You might also like