DEV Community

Cover image for Essential Linux Commands for DevOps Beginners
Esther Nnolum
Esther Nnolum

Posted on

Essential Linux Commands for DevOps Beginners

Linux, a widely used operating system, serves as the backbone for many renowned platforms. Renowned for its flexibility and efficiency, Linux stands out as a powerful operating system extensively employed in the DevOps landscape. The majority of DevOps tools necessitate a Linux environment and It is a prevalent practice that many DevOps tools undergo development and testing primarily on Linux systems before being adapted for use on Windows platforms.

For DevOps beginners, acquiring proficiency in essential Linux commands is very vital for DevOps tasks such as server management, issue troubleshooting, DevOps tool setup, task automation, e.t.c. In the following sections, we will delve into fundamental Linux commands that are essential for any DevOps enthusiast to grasp.

  1. Navigating the File System:
  • cd: Change directory.
  • mkdir: Create a new directory in the current directory.
  • pwd: Print the current working directory.
  • touch: create a new, empty file.
  • ls: List files and directories.
  • cp: Copy files or directories.
  • mv: Move or rename files or directories.
  • rm: Remove files or directories.
mkdir linux-devops
cd /home/ennolum/linux-devops/
touch file1 file2
pwd
ls
cp file1 /home/ennolum/.
mv file2 file3
rm file1
Enter fullscreen mode Exit fullscreen mode

Image description

  1. Managing Processes:
  • ps: Display information about processes.
  • top: Monitor system processes in real-time.
  • kill: Send signals to linux process (SIGKILL/-9 is the signal to terminate a process).
  • nice: Used to manipulate the priority of a process. Processes with higher priority receive more CPU time compared to those with lower priority
ps aux
top
kill -9 <process_id>
nice -n <value> <process name>
Enter fullscreen mode Exit fullscreen mode
  1. User and Permissions:
  • useradd: Create a new user.
  • passwd: Change user password.
  • chmod: Change file permissions. Note the following
    r (read): 4
    w (write): 2
    x (execute): 1

  • chown: change file owner

useradd <newuser>
passwd <newuser>
chmod 755 file1.sh #7=4+2+1=rwx 5=4+1=rx
Enter fullscreen mode Exit fullscreen mode
  1. Text Processing:
  • cat: Display the content of a file.
  • grep: Search for a pattern in files.
  • sort: Sort lines of text files
  • uniq: Remove duplicate lines from texts in stdin or files
  • sed: Stream editor for text manipulation.
  • head & tail: Display the first few lines and the last few lines of a file respectively
cat file1.txt
grep <pattern> file.log
sort file.txt # use -r to sort in reverse
sort file.txt | uniq
sed 's/old/new/' file.txt #replace <old> with <new> in file.txt
head file.txt ; tail file.txt
Enter fullscreen mode Exit fullscreen mode
  1. Network Commands:
  • ping: Check network connectivity.
  • ifconfig or ip: Display network configuration.
  • netstat: Display network status information.
  • dig: Used to query the DNS name server.
  • hostname: Used to view and set the hostname of a system
ping google.com
ifconfig
netstat -an
dig <domainName>
Enter fullscreen mode Exit fullscreen mode
  1. Package Management:

apt (Debian/Ubuntu) or yum (RHEL/CentOS): Install, update, or remove packages.

sudo apt-get update
sudo apt-get install <package_name>
sudo yum update
sudo yum install <package-name>
Enter fullscreen mode Exit fullscreen mode
  1. File Compression and Archiving:
  • tar: Create, view, or extract tar archives.
  • gzip and gunzip: Compress and decompress files.
  • zip: Creates a zip archive from one or more files or directories
tar -cvf archive.tar files/ # Combine tar and compression commands
gzip file.txt
Enter fullscreen mode Exit fullscreen mode
  1. SSH and Remote Access:
  • ssh: Securely connect to a remote server.
  • scp: Copy files securely between local and remote systems or between 2 remote systems.
ssh <user@remote_host>
scp local_file.txt user@remote_host:/path/to/destination/
Enter fullscreen mode Exit fullscreen mode
  1. System Information:
  • uname: Display system information.
  • df and du: Show disk space usage (df — filesystem and du disk usage).
  • uptime: Displays duration the system has been operational and the average system load.
  • free -m: Provides details on the utilization of the system’s memory
uname -a
df -h
du -sh /path/to/directory
Enter fullscreen mode Exit fullscreen mode
  1. Shell Scripting Basics: Shell scripting plays a vital role in automating processes on Linux systems. By creating a script — a file containing a series of commands — you can execute tasks without repeatedly typing commands. This approach enhances efficiency in performing routine tasks, enabling streamlined daily operations and the possibility of scheduling automated executions.
  • echo: Display a message.
  • chmod +x script.sh and ./script.sh: Make a script executable and run it respectively.
echo "Hello, DevOps"
Enter fullscreen mode Exit fullscreen mode

Conclusion:
Mastering these fundamental Linux commands will provide a solid foundation for DevOps beginners. As you become more comfortable with these commands, you’ll be better equipped to navigate, manage, and automate tasks within a Linux environment.

Top comments (4)

Collapse
 
odoth4kz profile image
ODOT!

Great read. Go Linux!

Collapse
 
msc2020 profile image
msc2020

Very good!

Collapse
 
jonrandy profile image
Jon Randy 🎖️

The touch command is actually for updating the access and modification times of the specified file. The fact that a new file is created if it doesn't already exist is merely a useful side effect.

Collapse
 
cynthy profile image
Cynthia Tochukwu

Great!