Linux commands for Cloud & DevOps Engineers
#90 Days of DevOps Challenge - Day 3
Table of contents
No headings in the article.
Useful Commands*:*
▶ Pwd: Command to print the directory location, the current working directory.
▶Sudo: Command to execute actions with a superuser privilege.
▶Ls: Command used to list the contents of a directory. If you run "ls -lthr", it will list the files or directories in the same table format above, but with another column representing the size of each file/directory, sorted by last modified date in descending order (biggest to smallest) and reverse the sorting order.
Note that sizes are listed in bytes (B), megabytes (MB), gigabytes (GB), or terabytes (TB) when the file or directory's size is larger than 1024 bytes.
▶Cat: Command used to display and concatenate files on the terminal. It can also be used to modify existing ones. Below are other options for the use of the cat command:
cat -b: Adding line numbers to non-blank lines
cat -n: Adding line numbers to all lines
cat -s: Squeezing blank lines into one line
cat –E: Displaying $ at the end of the line
▶Grep: Command for searching specific strings/words in a text file.
This would print all of the lines in <file> that contain the word “Dev".
▶Vim: The mostly text editor used in Linux. Usually used in 3 different modes:
Normal mode: The default mode in which Vim starts. In this mode, you can use various commands to navigate and edit the text.
Insert mode: In this 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 this mode, you can enter commands to perform various actions, such as saving the file or quitting Vim. To enter command mode, press the ":" key, and to save press ":wq!".
▶Tail: Command to print the last N number of data of the given input. By default, it prints 10 lines, and even we can specify the number of lines we want to display.
▶Sort: Command used to sort the results of the search either alphabetically or numerically. It also sorts files and directories. There are other options for the use of the sort command:
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.
▶Ifconfig: Command used to configure the network interfaces.
▶*Ps:* Command used to list the currently running processes and their PIDs along with some other information depending on different options.
There are other options to list the processes:
View process by process ID.
Syntax :ps p process_id
ps -p process_id
ps --pid process_id
You can view multiple processes by specifying multiple process IDs separated by blank or comma –
▶Sed: Command used to perform basic text transformations on an input file.
▶Diff: Command used to find the difference between two files.
▶Chmod: Command used to change the permissions of files and directories.
▶Chown: Command used to change the file Owner or group.
▶History: Command used to verify the previously executed commands.
If you need to check the last 10 executed commands, use the "history 10" command:
▶Free: Command to display 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.
You can use the "free -mhwl"command to display the amount of memory in megabytes, shows all output columns automatically scaled to the shortest three-digit unit and display the units also of the printout, showing the detailed low and high memory statistics, and the cache memory.
▶ Find: Command used to find files and directories.
▶Df: Command used to check the available disk space, used by the file system.
If you use the "df -Th"command, it will show the disk space in a print file system type and in human-readable print sizes in 1024kb.
▶Top: Command used to monitor the system resources and processes.
You can sort processes using different columns, press one of the following keys:
M. Sort by the %MEM column.
N. Sort by PID column.
T. Sort by the TIME+ column.
P. Sort by the %CPU column.
Press Ctrl+C to exit.