In their day-to-day work, DevOps Engineers often need to execute numerous Linux commands, and remembering each command can be challenging. Below is a curated list of essential Linux commands covering various topics frequently used by DevOps Engineers:
- VI & Nano Editor Shortcuts
- Common DevOps Tasks
- Linux Networking Commands
- Connectivity Testing Commands
- IP Address Configuration Commands
- Useful Networking Tools
- Commands Related to ACL, ARP, Route Tables, and Namespace Operations
h
: Move cursor left
j
: Move cursor dow
k
: Move cursor up
l
: Move cursor right
i
: Insert mode (start inserting before the cursor)
a
: Append mode (start inserting after the cursor)
x
: Delete character at the cursor
dd
: Delete the current line
yy
: Yank (copy) the current line
p
: Paste the yanked or deleted text
h
: Move cursor left
j
: Move cursor dow
k
: Move cursor up
l
: Move cursor right
SAVE AND QUIT
h
: Move cursor left
j
: Move cursor dow
k
: Move cursor up
l
: Move cursor right
/pattern: Search for 'pattern'
:s/old/new/g` : Replace 'old' with 'new' in the entire file
u
: Undo
Ctrl + r
: Redo
v
: Enter Visual mode
V
: Enter Visual Line mode
y
: Yank selected text
0
: Move to the beginning of the line
$
: Move to the end of the line
:n
: Move to line number 'n'
0
: Move to the beginning of the line
$
: Move to the end of the line
:n
: Move to line number 'n'
:e filename
: Open a file
:w filename
: Save as a different filename
:q!
: Quit without saving changes
Alt + A
: Mark text for copying
Ctrl + K
: Cut marked text
Ctrl + U
: Paste cut text
Ctrl + k
: Cut (delete) the current line
Ctrl + u
: Paste the cut text
Ctrl + o
: Write changes to the file
Ctrl + x
: Exit nano
Ctrl + w
: Search for text
Ctrl + \
: Replace text
Ctrl + f
: Move forward one page
Ctrl + b
: Move backward one page
Ctrl + arrow keys
: Move cursor by word
Ctrl + k
: Cut (delete) the current line
Ctrl + u
: Paste the cut text
Ctrl + o
: Write changes to the file
Ctrl + x
: Exit nano
Alt + ,` : Go to line number
HELP
Ctrl + X
: Close nano (it will ask to save changes)
- ls - List Files and Directories: List the contents of a directory.
ls -l
- cd - Change Directory: Navigate to a different directory.
bash cd /home/user/documents
- pwd - Print Working Directory: Display the current directory's full path.
pwd
- mkdir - Make Directory: Create a new directory.
mkdir new_folder
- rm - Remove: Delete files or directories.
rm file.txt
- cat - Concatenate and Display: View the content of a file.
cat file.txt
- nano - Text Editor: Open a text file for editing.
nano file.txt
- grep - Search Text: Search for text patterns in files.
grep "pattern" file.txt
- find - Search Files and Directories: Search for files and directories.
find /path/to/search -name "file_name"
- chmod - Change File Permissions: Modify file permissions.
chmod 755 file.sh
- chown - Change Ownership: Change the owner and group of a file or directory.
chown user:group file.txt
- ps - Process Status: Display running processes.
ps aux
- top - Monitor System Activity: Monitor system processes in real-time.
top
- kill - Terminate Processes: Terminate a process using its ID.
kill PID
- wget - Download Files: Download files from the internet.
wget https://example.com/file.zip
- curl - Transfer Data with URLs: Transfer data to or from a server.
curl -O https://example.com/file.txt
- tar - Archive and Extract: Create or extract compressed archive files.
tar -czvf archive.tar.gz folder
- ssh - Secure Shell: Connect to a remote server securely.
ssh user@remote_host
- scp - Securely Copy Files: Copy files between local and remote systems using SSH.
scp file.txt user@remote_host:/path
- rsync - Remote Sync: Synchronize files and directories between systems.
rsync -avz local_folder/ user@remote_host:remote_folder/
- df - Disk Free Space: Display disk space usage.
df -h
- du - Disk Usage: Show the size of files and directories.
du -sh /path/to/directory
- ifconfig - Network Configuration: Display or configure network interfaces (deprecated, use ip).
ifconfig
- ip - IP Configuration: Manage IP addresses and network settings.
ip addr show
- netstat - Network Statistics: Display network connections and statistics (deprecated, use ss).
netstat -tuln
- systemctl - System Control: Manage system services using systemd.
systemctl start service_name
- journalctl - Systemd Journal: View system logs using systemd's journal.
journalctl -u service_name
- cron - Schedule Tasks: Manage scheduled tasks.
crontab -e
- at - Execute Commands Later: Run commands at a specified time.
echo "command" | at 15:30
- ping - Network Connectivity: Check network connectivity to a host.
ping google.com
- traceroute - Trace Route: Trace the route packets take to reach a host.
traceroute google.com
- curl - Check Website Connectivity: Check if a website is up.
curl -Is https://example.com | head -n 1
- dig - Domain Information Groper: Retrieve DNS information for a domain.
dig example.com
- hostname - Display or Set Hostname: Display or change the system's hostname.
hostname
- who - Display Users: Display currently logged-in users.
who
- useradd - Add User: Create a new user account.
useradd newuser
- usermod - Modify User: Modify user account properties.
usermod -aG groupname username
- passwd - Change Password: Change user password.
passwd username
- lsof - List Open Files: List open files and processes using them.
lsof -i :port
- nc - Netcat: Networking utility to read and write data across network connections.
echo "Hello" | nc host port
- scp - Secure Copy Between Hosts: Copy files securely between hosts.
scp file.txt user@remote_host:/path
- sed - Stream Editor: Text manipulation using regex.
sed 's/old/new/g' file.txt
- awk - Text Processing: Pattern scanning and text processing.
awk '{print $2}' file.txt
- cut - Text Column Extraction: Extract specific columns from text.
cut -d"," -f2 file.csv
Purpose: Query DNS to obtain domain-related information. Example:
nslookup example.com
Explanation: Useful for troubleshooting DNS issues, checking domain information, and resolving IP addresses.
Purpose: A versatile DNS tool for querying DNS servers. Example:
dig example.com
Explanation: Provides detailed DNS information, useful for debugging and obtaining specific record types.
Purpose: Connect to a remote server to test network connectivity. Example:
telnet example.com 80
Explanation: Useful for checking if a specific port on a remote server is reachable.
Purpose: Trace the route packets take to reach a destination. Example:
traceroute example.com
Explanation: Helps identify network issues and understand the path packets take through the internet.
Purpose: Display and configure network interfaces. Example:
ifconfig
Explanation: View current network interface configurations and assign IP addresses.
Purpose: A versatile command for network configuration. Example:
ip addr show
Explanation: Provides more detailed information than ifconfig and allows advanced network configuration.
Purpose: Establish TCP/UDP connections, making it a versatile networking tool. Example:
nc -zv example.com 80
Explanation: Useful for checking if a port is open and for simple network testing.
Purpose: Display network statistics and connections. Example:
netstat -tulpn
Explanation: Helps monitor active network connections, ports, and routing tables.
Purpose: Capture and analyze network traffic. Example:
tcpdump -i eth0
Explanation: Useful for debugging network issues, analyzing packets, and monitoring network activity.
Purpose: Download files from the internet. Example:
wget https://example.com/file.txt
Explanation: Simplifies downloading files, and is useful for fetching resources from the web.
Purpose: Transfer data from or to a server. Example:
curl https://example.com/api
Explanation: Supports a variety of protocols and is handy for testing APIs and fetching web content.
Purpose: Set permissions on files or directories. Example:
setfacl -m u:jane:rw file.txt
Explanation: Allows fine-grained control over file and directory permissions.
Purpose: Display or manipulate the ARP cache. Example:
bash `arp -a
Explanation: Shows a mapping between IP addresses and MAC addresses on the local network. .
Purpose: Display or manipulate the IP routing table. Example:
route -n
Explanation: Helps monitor active network connections, ports, and routing tables.
sudo ip link add 'myns-1-eth0' type veth peer name 'myns-2-eth0'
sudo ip link set 'myns-1-eth0' netns 'mynamespace-1'
sudo ip link set 'myns-2-eth0' netns 'mynamespace-2'
sudo ip netns exec 'mynamespace-1' ip addr add 192.168.1.1/24 dev eth0
sudo ip link set 'myns-1-eth0' netns 'mynamespace-1'
sudo ip link set 'myns-2-eth0' netns 'mynamespace-2'
sudo ip netns exec 'mynamespace-1' ip link set 'lo' up
sudo ip netns exec 'mynamespace-1' ip link set 'eth0' up