Linux commands for DevOps (Commands used in day-to-day activities).

Table of contents

WHAT IS LINUX - Linux is an os it is open source and it is multitasking and multiuser with PowerShell and multiple flavours. Flavours like ubuntu, centos,redhat, fedora,kalilinux etc.
LINUX FILE SYSTEM HIERARCHY - in Linux everything is represented as a file including a hardware program the files are stored in a directory and every directory contains a file with a tree structure that is called file system hierarchy.
1./ (Root): Primary hierarchy root and root directory of the entire file system hierarchy. Every single file and directory starts from the root directory The only root user has the right to write under this directory
2. /bin: Essential command binaries that need to be available in single-user mode; for all users, e.g., cat, ls, cp. Contains binary executables Commands used by all the users of the system are located here e.g. ps, ls, ping, grep, cp
3. /boot: Boot loader files, e.g., kernels
4. /dev: Essential device files, e.g., /dev/null. These include terminal devices, USB, or any device attached to the system.
5. /etc: Host-specific system-wide configuration files.
6. /home: Users’ home directories, containing saved files, personal settings, etc.Home directories for all users to store their files.
7. /lib: Libraries essential for the binaries in /bin/ and /sbin/.
8. /media: Temporary mount directory for removable devices.
9. /mnt: Temporarily mounted filesystems.
10. /opt Optional application software packages.
11. /sbin : Essential system binaries, e.g., fsck, init, route. Just like /bin, /sbin also contains binary executables. Example: iptables, reboot, fdisk, ifconfig, swapon
12. /tmp: Temporary files. Often not preserved between system reboots, and may be severely size restricted. The directory that contains temporary files created by the system and users. Files under this directory are deleted when the system is rebooted.
13. /usr: Secondary hierarchy for read-only user data; contains the majority of (multi-)user utilities and applications. /usr/bin contains binary files for user programs. If you can’t find a user binary under /bin, look under /usr/bin. For example: at, awk, cc, less, scp.
Linux Basics Command
ls - The most frequently used command in Linux to list directories
pwd - Print working directory command in Linux
cd - Linux command to navigate through directories
mkdir - Command used to create directories in Linux
mv - Move or rename files in Linux
cp - Similar usage as mv but for copying files in Linux
rm - Delete files or directories
man - Access manual pages for all Linux commands
uname - Linux command to get basic information about the OS
whoami - Get the active username
tar - Command to extract and compress files in Linux
grep - Search for a string within an output
head - Return the specified number of lines from the top
tail - Return the specified number of lines from the bottom
diff - Find the difference between two files
export - Export environment variables in Linux
zip - Zip files in Linux
unzip - Unzip files in Linux
wget - Direct download files from the internet
top - View active processes live with their system usage
Example:-
- Ls: This command is used to list the contents of a directory.
if you run ls -l, it will show the permissions, owner, size, and last modified date for each file in the directory.
2. Sudo: This command executes only that command with superuser privileges.
3. Pwd: This command will print your directory location, where you currently working.
4. Cat: This is used to concatenate and display files on the terminal. It can also be used to modify existing ones.
cat -b: This adds line numbers to non-blank lines
cat -n: This adds line numbers to all lines
cat -s: This squeezes blank lines into one line
cat –E: This shows $ at the end of the line
5. Sort: This command is used to sort the results of search either alphabetically or numerically. It also sorts files and directories.
sort -r: the flag returns the results in reverse order.
sort -f: the flag does case-insensitive sorting.
sort -n: the flag returns the results as per numerical order.
8. Tail: This command prints the last N number of data of the given input. By default, it prints 10 lines.
We can specify the number of lines, that we want to display.
6. Chmod: This command is used to change the access permissions of files and directories.
For example: Following “chmod” command will give the user permission to read, write and execute a file.
7. Chown: This command is used to change the file Owner or group.
Here, below the ownership of “Chetan.txt” file got changed to root.
- Ping – This command will ping a host and check if it is responding.
9. Lsof: It is used to display a list of all the open files on a Linux system.
10. Ifconfig: This is used to configure the kernel-resident network interfaces.
- ID: This is used to find out user and group names and numeric ID’s (UID or group ID) of the current user or any other user in the server.
Syntax: id <option> <user_name>
12. Cut: This command is used to extract specific fields or columns from a file or standard input.
It is often combined with other commands, such as sort, uniq, and grep, to perform more complex text-processing tasks.
13. Sed: This is used to perform basic text transformations on an input file. It stands for "stream editor" and is a powerful tool for editing text files or streams in a Linux environment.
14. Diff: This command is used to find the difference between two files.
15. History: This command is used to view the previously executed command.
“History 10” – Will give you the last 10 executed commands.
16. Find: This is used to find files and directories and perform subsequent operations on them.
In the below command, It will search in the present working directory and its subdirectories, and print the name of the file that have “.txt” file extension.
17. Free: This command displays the total amount of free space available along with the amount of memory used and swap memory in the system, and also the buffers used by the kernel.
18. ssh user@host – connect to the host as a user.
19. Ssh-keygen: This command is used to generate a public/private authentication key pair.
This process of authentication allows the user to connect remote server without providing a password.
(This authentication method we will use to authenticate the server with Jenkins while deploying CI/CD pipelines).
20. Nslookup: This stands for “Name server Lookup”. This is a tool for checking DNS hostname to Ip or Ip to Hostname. This is very helpful while troubleshooting.
21. Curl: Curl is a tool used for transferring data to or from a server, using various protocols, such as HTTP, HTTPS, FTP, and more. Basic example:
Syntax: curl <url>
-o: It will save downloaded file on the local machine with the name provided in parameters.
22. Tr: Tr stands for translation. This command is for translating or deleting characters.
22. Df, du:
Df (disk free) command will have an account of available disk space, used by file system.
Du (disk usage) command reports the size of directory tree including all the content.
24. Htop: This command is used to monitor the system’s resources and processes that are running in real time.
25. Ps: We use ps command to check the unique id behind every process.
a = show processes for all users
u = display the process’s user/owner
x = also show processes not attached to a terminal
26. Kill: This command is used to terminate processes manually. This command basically, will send a signal that terminates it.
27. Vim: This is a text editor used in Linux. It stands for “Vi Improved”.
Mostly used modes in VIM:
Normal mode: This is the default mode in which vim starts. In normal mode, you can use various commands to navigate and edit the text.
Insert mode: In insert mode, you can type text into the file. To enter insert mode, press the "i" key. To exit insert mode and return to normal mode, press the "Esc" key.
Command mode: In command mode, you can enter commands to perform various actions, such as saving the file or quitting vim. To enter command mode, press the ":" key.
Happy Learning
Keep Updated
Md Rashid Salim
- #linux #devops #Subham Londhe##90daysofdevops #devospchallenges #futureindevops
Subscribe to my newsletter
Read articles from Rashid Salim directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
