đŸ’»Linux Commands for DevOps Engineer🚀 #Day_3

đŸ’»Linux Commands for DevOps Engineer🚀 #Day_3

(Commands used in day to day activities)

Mostly used Commands:

  1. whoami: This command outputs current logged-in user.

  2. ls: This command list the all files and directory in current directory.

The ls -l command lists files and directories with detailed information like permissions, owner, size, and modification date.

  1. pwd: This command prints the current working directory path.

  2. cat: This command in Linux is used to display the contents of a file.

  3. touch: This command is used to create an empty file or update the timestamp of an existing file.

  4. echo: This command in Linux prints text or variables to the terminal.

  5. uname: This command in Linux displays system information such as the kernel name and version.

  6. date: This command is used to display or set the date and time

  7. file: This command determines and displays the type of a file based on its content.

  8. mkdir: This command is used to creates a new directory.

  9. rm: This command in Linux removes (deletes) files or directories.

  10. cp: This command in Linux copies files or directories from one location to another.

  11. mv: This command in Linux moves or renames files and directories.

  12. cd: This command changes current working directory to specified working directory.

  13. rmdir: This command in Linux removes empty directories.

  14. Grep: This command searches for a particular string/ word in a text file. This is similar to “Ctrl+F” but executed via a CLI.

This would print would print all of the lines in “file1” that contain the word “DevOps".

  1. nano: This command in Linux opens the Nano text editor, allowing you to create and edit text files.

In Nano, the most commonly used modes and keybindings include:

  1. Edit Mode: The default mode for editing text. You can type, delete, and modify text directly.

  2. Navigation:

    • Arrow Keys: Move the cursor around the text.

    • Ctrl + A: Move the cursor to the beginning of the line.

    • Ctrl + E: Move the cursor to the end of the line.

    • Ctrl + Y: Move up one page.

    • Ctrl + V: Move down one page.

  3. Saving and Exiting:

    • Ctrl + O: Save the current file.

    • Ctrl + X: Exit Nano (prompts to save if changes are made).

  4. Cutting and Pasting:

    • Ctrl + K: Cut (or delete) the current line or selected text.

    • Ctrl + U: Paste the cut text.

  5. Searching:

    • Ctrl + W: Search for text within the file.
  6. Help:

    • Ctrl + G: Display the help menu.

These key bindings help streamline the editing process and make navigation and file management in Nano more efficient.

  1. vim: is a text editor used in Linux for creating and editing text files, offering various modes for efficient text manipulation.

Modes in vim:

  • Normal Mode: Used for navigation and text manipulation. You start in this mode.

    • Example: Use dd to delete a line.
  • Insert Mode: Used for inserting text.

    • Example: Press i to start typing text.
  • Visual Mode: Used for selecting text.

    • Example: Press v to select text character by character.
  • Command-Line Mode: Used for executing commands like saving and quitting.

    • Example: Press esc then : and then type wq to save and quit.
  1. ping: This command in Linux checks the network connectivity between your system and a specified host by sending ICMP echo requests and measuring the response time.

  2. lsof: This command in Linux lists open files and the processes that opened them.

  3. sudo: This command executes only that command with superuser privileges.

  4. su: command in Linux switches the current user to another user account, typically used to switch to the superuser (root).

  5. awk: This command is a powerful text-processing tool in Linux. It allows you to perform a variety of operations on text files, such as pattern scanning, data extraction, and reporting.

awk '{print $1}' filename.txt : Used to print 1st column of your file.

awk '/myapp/' filename.txt: Used to print lines containing myapp

  1. sed: This command is a stream editor in Linux. It is commonly used for searching, finding and replacing, inserting, or deleting specific lines in text files.

sed ‘s/MyApp/newApp/g’ file1: Replace all the occurrences of ‘MyApp’ with ‘newApp’ in each line.

sed -n '3p' file1: Print only 3rd line.

  1. ifconfig: This command in Linux is used to configure, control, and query the network interfaces on a system.

  2. ip: This command in Unix/Linux is part of the iproute2 package and is a more modern and powerful alternative to the older ifconfig command. It is used for managing and displaying network interfaces, routing, IP addresses, and more.

  3. hostname: This command is used to display or set the system's hostname in Linux.

  4. ps: command in Unix/Linux is used to display information about active processes running on the system.

a: Displays information about processes from all users.

u: Gives detail info about each process like cpu, memory usuage, process ID and start time.

x: Include process that are not connected to a terminal.

  1. find: This command in Linux is used to search for files and directories in a directory hierarchy based on various criteria such as name, type, size, modification time, and more.

  2. head: This command is used to print first 10 lines of yours file.

  3. tail: This command is used to print last 10 lines of yours file.

  4. du -h: This command in Unix/Linux displays the disk usage of files and directories in a human-readable format (e.g., KB, MB, GB).

  5. df -h: This command in Unix/Linux displays the available disk space on all mounted filesystems in a human-readable format (e.g., KB, MB, GB).

  6. free: This command in Unix/Linux displays the amount of free and used memory (RAM and swap) in the system.

  7. fuser: This command in Linux identifies processes using files, directories, or sockets.

  8. top: This command in Unix/Linux displays real-time information about system processes, including CPU and memory usage, making it useful for monitoring system performance.

  9. uptime: This command in Linux shows how long the system has been running, along with the current time, the number of users logged in, and the system's load averages for the past 1, 5, and 15 minutes.

  10. which: This command in Linux displays the full path of the executable file for a given command.

  11. sort: This command Linux displays the full path of the executable file for a given command.

  12. history: This command in Linux displays the list of previously executed commands in the terminal session.

  13. man: This command in Linux displays the manual (help) pages for other commands, providing detailed information on usage, options, and examples.

  14. chmod: This command Linux changes the permissions of files or directories.

  15. chown: This command Linux changes the ownership of files or directories, allowing you to specify a new owner and optionally a new group.

  16. getfacl: This command in Linux displays the file access control list (ACL) for a specified file or directory, showing detailed permissions for users and groups beyond the basic owner/group/others model.

  17. setfacl: This command in Unix/Linux is used to set or modify file access control lists (ACLs) for files and directories, allowing for more granular permission settings.

  18. wc: This command in Linux is used to count the number of lines, words, and characters in a file or input.

  19. cut: This command is used to extract specific fields or columns from a file or standard input.

  20. nslookup: This command in Linux is used to query DNS servers to obtain domain name or IP address mapping information.

  21. diff: This command is used to find the difference between two files.

50) ssh user@host: connect to the host as a user.

ssh-keygen: This command is used to generate a public/private authentication key pair.

  1. apt-get: This command in Linux is used to handle packages and install, update, or remove software on Debian-based distributions.

apt-get update: Fetches the latest package lists from the repositories to ensure you’re getting the latest versions and updates.

apt-get upgrade: Upgrades all installed packages to their latest versions based on the updated package list.

apt-get install <package_name>: Installs a new package specified by <package_name> from the repository.

apt-get remove <package_name>: Completely removes the specified package along with its configuration files.

apt-get clean: Removes downloaded package files from the cache to free up disk space.

apt-get purge <package_name>: Searches for packages in the repository that match the <package_name> keyword.

  1. echo $?: command in Linux prints the exit status of the last executed command. An exit status of 0 typically indicates that the command was successful, while any non-zero value indicates an error or issue.

Conclusion

In conclusion, mastering Linux commands is essential for any DevOps engineer. These commands form the backbone of daily operations, enabling efficient system management, automation, and troubleshooting. From basic file manipulation to advanced network configuration and process monitoring, a solid understanding of these commands enhances productivity and ensures smooth system performance. By continually practicing and expanding your command-line skills, you can streamline workflows, improve system reliability, and contribute more effectively to your DevOps team.

Â