As a Cloud or DevOps engineer, it is essential to be familiar with a wide range of Linux commands to effectively manage and troubleshoot your systems. In this article, we will cover 50 of the most commonly used Linux commands that every Cloud or DevOps engineer should know.
ls
- This command is used to list the files and directories in a given directory. For example,ls -l
will list the files and directories in a long format, displaying permissions, ownership, and file size.cd
- This command is used to change the current working directory.For example,
cd /var/log
will change the current working directory to the /var/log directory.mkdir
- This command is used to create a new directory.For example,
mkdir mydir
will create a new directory called "mydir" in the current working directory.rm
- This command is used to remove files or directories.For example,
rm myfile.txt
will remove the file "myfile.txt" from the current working directory. It's important to be careful with this command since it can't be undone.cp
- This command is used to copy files or directories.For example,
cp myfile.txt myfile_copy.txt
will create a copy of the file "myfile.txt" called "myfile_copy.txt" in the current working directorymv
- This command is used to move or rename files or directories.For example,
mv myfile.txt mydir/
will move the file "myfile.txt" to the "mydir" directory.cat
- This command is used to display the contents of a file.For example,
cat myfile.txt
will display the contents of the file "myfile.txt" in the terminal.grep
- This command is used to search for patterns in text.For example,
grep "error" logfile.txt
will search for the word "error" in the file "logfile.txt" and return any lines that contain it.top
- This command is used to display the processes running on a system and their resource usage.For example,
top
will display all the running processes, their process ID, and their resource usage in real time.ping
- This command is used to test the reachability of a network host.For example,
ping google.com
will send an echo request to the host "google.com" and return the results of the ping test.ps
- This command is used to display information about the currently running processes.For example,
ps -ef
will show all the running processes with their process ID, parent process ID, and the command that started them.kill
- This command is used to stop a running process.For example,
kill -9 1234
will stop the process with ID 1234.df
- This command is used to display information about the disk space usage of file systems.For example,
df -h
will show disk space usage in a human-readable format.du
- This command is used to display the amount of disk space used by a file or directory.For example,
du -sh /var/log
will show the total disk space used by the /var/log directory in human-readable formatchmod
- This command is used to change the permissions of a file or directory. For example,chmod 755 myfile.txt
will give read, write and execute permissions to the owner and read and execute permissions to others for the file "myfile.txt".chown
- This command is used to change the ownership of a file or directory.For example,
chown user:group myfile.txt
will change the ownership of the file "myfile.txt" to the user "user" and the group "group".netstat
- This command is used to display information about the network connections on a system.For example,
netstat -an
will show all the active network connections and their status.iptables
- This command is used to configure the firewall on a Linux system.For example,
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
will add a rule to the firewall to allow incoming SSH connections.route
- This command is used to display the routing table on a system.For example,
route -n
will show the routing table with IP addresses instead of hostnames.ifconfig
- This command is used to configure network interfaces on a Linux system.For example,
ifconfig eth0 up
will bring the eth0 interface up.tar
- This command is used to create and extract tar archives.For example,
tar -cvf archive.tar /mydir
will create an archive of the directory /mydir called archive.targzip
- This command is used to compress or decompress files.For example,
gzip myfile.txt
will compress the file "myfile.txt" and create a file called "myfile.txt.gz".find
- This command is used to search for files in a directory hierarchy.For example,
find / -name myfile.txt
will search for the file "myfile.txt" starting from the root directory.sed
- This command is used to perform basic text transformations on an input stream.For example,
sed 's/oldstring/newstring/g' myfile.txt
will search for the string "oldstring" in the file "myfile.txt" and replace it with "newstring".awk
- This command is used to perform operations on columns of data in a text file.For example,
awk '{print $1}' myfile.txt
will print the first column of the file "myfile.txt"date
- This command is used to display the current date and time.For example,
date +%Y-%m-%d
will display the current date in the format "YYYY-MM-DD".uname
- This command is used to display information about the system.For example,
uname -a
will show the system name, version, and other information.uptime
- This command is used to display the uptime of a system.For example,
uptime
will show the current uptime of the system, the number of users logged in, and the system load averages for the last 1, 5, and 15 minutes.w
- This command is used to display information about the users currently logged into the system.For example,
w
will show the username, terminal, login time, and the command that the user is currently running.free
- This command is used to display the amount of free and used memory on a system.For example,
free -m
will show the memory usage in megabytes.lsof
- This command is used to display information about open files on a system.For example,
lsof -i :80
will show all the processes that have a network connection open on port 80.dd
- This command is used to perform low-level operations on files or devices. For example,dd if=/dev/sda of=backup.img
will create an image of the sda device and save it as "backup.img".chkconfig
- This command is used to configure services to start automatically at boot time on Red Hat-based systems.For example,
chkconfig --list
will show the current status of all the services and their runlevels.systemctl
- This command is used to manage services and daemons on systems that use systemd.For example,
systemctl start apache2
will start the Apache web server.nmap
- This command is used to scan a network for hosts and services.For example,
nmap -sS 192.168.1.0/24
will perform a stealth syn scan on the network range 192.168.1.0/24.tcpdump
- This command is used to capture and analyze network traffic.For example,
tcpdump -i eth0
will capture all the traffic on the eth0 interface.rsync
- This command is used to synchronize files and directories between different systems.For example,
rsync -avz /data/ myserver:/data/
will synchronize the local directory "/data" with the remote directory "/data" on the server "myserver".ssh
- This command is used to log in to a remote system securely.For example,
ssh user@example.com
will log in to the remote system "example.com" as the user "user".scp
- This command is used to securely copy files between systems.For example,
scp myfile.txt user@example.com:/data/
will copy the file "myfile.txt" to the remote directory "/data" on the server "example.com" as the user "user".nohup
- This command is used to run a command that will continue running even after the user has logged out.For example,
nohup mycommand &
will run the command "mycommand" in the background and ignore any SIGHUP signals.curl
- This command is used to transfer data from or to a server.For example,
curl http://example.com
will retrieve the contents of the website "http://example.com" and display it in the terminal.wget
- This command is used to download files from the internet.For example,
wget http://example.com/myfile.txt
will download the file "myfile.txt" from the website "http://example.com".htop
- This command is an interactive process viewer that is similar to the "top" command but with a more user-friendly interface.at
- This command is used to schedule a command to be executed at a specific time in the future.For example,
at now + 1 hour
will schedule a command to be executed in 1 hour from the current time.cron
- This command is used to schedule repetitive tasks to be executed automatically.For example,
cron 0 0 * * * /usr/bin/backup.sh
will schedule a script called "backup.sh" to be executed every day at midnight.screen
- This command allows you to create and manage multiple terminal sessions within a single window.For example,
screen -S mysession
will create a new session called "mysession" and attach to it.tail
- This command is used to display the last few lines of a log file.For example,
tail -f /var/log/syslog
will display the last few lines of the syslog file and keep updating as new lines are added.traceroute
- This command is used to display the route that a packet takes to reach a specific host.For example,
traceroute google.com
will show the route that a packet takes to reach the host "google.com".vi
- This command is a text editor that is commonly used in Linux systems.For example,
vi myfile.txt
will open the file "myfile.txt" in the vi editor for editing.history
- This command is used to display the command history of the current user.For example,
history
will show all the commands that have been executed by the current user in the current session.
These are just a few examples of some of the most commonly used Linux commands for Cloud or DevOps engineers. By mastering these commands, you will be able to more effectively manage and troubleshoot your systems, and be a more efficient and effective engineer.
Happy Learning :)