Mostly Used Linux Commands in DevOps:-

Mostly Used Linux Commands in DevOps:-

¡

6 min read

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

  2. 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.

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.

No alt text provided for this image

5. vim: This is a text editor used in Linux. It stands for “Vi Improved”.

No alt text provided for this image

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.

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

No alt text provided for this image

This would print all of the lines in “chxtan.txt” that contain the word “This".

7. sort: This command is used to sort the results of search either alphabetically or numerically. It also sorts files and directories.

No alt text provided for this image

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.

No alt text provided for this image

9. 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.

No alt text provided for this image

10. chown: This command is used to change the file Owner or group.

Here, below the ownership of “Chetan.txt” file got changed to root.

No alt text provided for this image

  1. ping – This command will ping a host and check if it is responding.

No alt text provided for this image

12. isof: It is used to display a list of all the open files on a Linux system.

No alt text provided for this image

13. ifconfig: This is used to configure the kernel-resident network interfaces.

No alt text provided for this image

14. 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>

No alt text provided for this image

15. 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.

No alt text provided for this image

16. 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.

No alt text provided for this image

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

No alt text provided for this image

18. history: This command is used to view the previously executed command.

No alt text provided for this image

“History 10” – Will give you the last 10 executed commands.

No alt text provided for this image

19. 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.

No alt text provided for this image

20. 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.

No alt text provided for this image

21. ssh user@host – connect to the host as a user.

22. 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).

No alt text provided for this image

23. 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.

No alt text provided for this image

24. 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>

No alt text provided for this image

-o: It will save downloaded file on the local machine with the name provided in parameters.

No alt text provided for this image

25. Tr: Tr stands for translation. This command is for translating or deleting characters.

No alt text provided for this image

26. apt-get: This command is used to install, update, and remove packages, as well as to manage the package repository sources.

Here are some common apt-get commands:

  • apt-get update: This updates the package index files from the package repositories listed in the /etc/apt/sources.list file. This is usually the first command you should run after adding a new repository or package to your system.

  • apt-get upgrade: This installs newer versions of packages that are already installed on the system. It will also remove any packages that are no longer required.

  • apt-get install: This installs one or more packages. For example, to install the nano text editor, you would run apt-get install nano.

  • apt-get remove: This removes one or more packages, but it does not remove the configuration files for the package.

  • apt-get purge: This removes one or more packages and their configuration files.

  • apt-get autoremove: This removes packages that were installed as dependencies but are no longer needed.

27. 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.

No alt text provided for this image

No alt text provided for this image

28. htop: This command is used to monitor the system’s resources and processes that are running in real time.

No alt text provided for this image

29. 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

No alt text provided for this image

30. kill: This command is used to terminate processes manually. This command basically, will send a signal that terminates it.

No alt text provided for this image

31. TNC: This is “Test Network Connection” command. Mostly used command while troubleshooting. It displays diagnostic information for a connection.

Command: tnc <server_name> -port <port>

Â