Home  >  Article  >  Computer Tutorials  >  Eight of the most commonly used Linux commands in DevOps

Eight of the most commonly used Linux commands in DevOps

王林
王林forward
2024-02-19 15:42:021230browse

Eight of the most commonly used Linux commands in DevOps

DevOps engineers often rely on the Linux operating system. Proficiency in basic Linux commands is essential for efficient system management. This article will introduce the basic commands for using Linux in DevOps practice.

1 List files and directories: 'ls' command

You can use the ls command to list files and directories in the current working directory.

picture

As you can see, you can use the command ls to display all directories and files in the current directory.

To display detailed information about a file, use the -l option:

picture

When you use ls -l, you will see detailed information about each file and directory, such as permissions, owner, group, size, and modification date.

2 Change directory: cd command

The cd command is used to navigate between directories. To move to a specific directory, use:

cd /path/to/directory

To move up one level: cd ..

So, the cd command (short for "change directory") is a command line instruction that switches to a different directory in order to explore and interact with the files and subdirectories within that specific directory.

3 Reading files: less, more, tail and head commands

The less and more commands are used to view the contents of a file in Linux without having to fully open the file. They are used to view parts of a file one by one, making it easier for developers to read large files.

  • less: Files can be scrolled using the arrow keys and exited at any time.
  • more: Similar to less, it also only displays one screen of text. You can go to the next screen by pressing the space bar and exit when done.

These two commands are useful when you want to quickly check the contents of a file without reading the entire content at once.

You can try it yourself: get a file and enter: less filename or more filename

There are also two commands available for reading large files. The head command is used to view the beginning of the file, while the tail command displays the end of the file. These two commands are useful when working with large files and you only need to view the beginning or end. head and tail are just like reading the first or last page of a book without reading the whole book.

4 Create and edit files: touch and nano commands

The touch command only performs one task - you create an empty file. Nano, on the other hand, is more like a text editor. It not only creates files but also supports writing and editing file contents there. Thus, touch can provide an empty file, and nano further allows text to be added and modified in that file.

picture

nano editor

In the nano text editor, you can use commands to perform various tasks. To save changes, click Ctrl O, confirm the file name, and press Enter. Exiting nano is as simple as clicking Ctrl X and if there are unsaved changes, you will be prompted to save before leaving. Use the arrow keys to navigate in the editor. To cut, copy, and paste text, use commands such as Ctrl K, Alt ^, and Ctrl U. Finding text can be done with Ctrl W, while replacing text can be done with Ctrl \. If you need to go to a specific line, press Ctrl _ and enter the line number. These commands make nano a user-friendly text editor, allowing developers to perform basic operations easily.

5 Create directory

Use the mkdir command to create a directory: mkdir directory_name will create a directory named directory_name (the developer can choose any name)

6 Delete files and directories

Use the rm command to delete files. To delete a directory, the -r option is required:

rm filenamedelete file

rm -r directory_name delete directory (use rm -r with caution as it will recursively delete the directory and its contents.)

7 File and search commands

The file command determines the file type: file filename It will display the type of file.

find command searches files and directories: find /path/to/search -name “filename”

8 Search keywords/patterns with grep command

grep is a powerful tool that helps search for specific words or patterns in files. When a developer is looking for a specific keyword in a file, they simply type grep, followed by the keyword to search for and the file name. grep will display all lines in the file that contain the keyword you are looking for. It works like a text detective - it finds and highlights the required information in a file, making it a useful command for text exploration and analysis.

grep "keyword" filename

To search directories recursively:

grep -r "keyword" /path/to/search

The above is the detailed content of Eight of the most commonly used Linux commands in DevOps. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:mryunwei.com. If there is any infringement, please contact admin@php.cn delete