Linux: 10 commands save time for the system administrator
Although the Linux desktop has undergone significant changes over the past two decades (for example, the Ubuntu Unity Interface), the command line operation mode is always a measure of the capabilities of a system development or maintenance personnel, most of the Linux masters we understand are operating in command line mode, so most of the following 10 tips are about Bash shell. 1. Using a command to create and enter the Directory Creation and then entering a new directory is a very common task. It seems that there are shortcuts to executing both commands in shell. Although there are no shortcuts, you can add the following functions to your. bashrc file: C code mkcd () {mkdir-p $1 cd $1} and then run the source. bashrc to read the changes in the memory and use the mkcd command to complete two services: C code tektea @ ubuntu :~ $ Mkcd catogory/articles tektea @ ubuntu :~ /Catogory/articles $2. back to the previous directory when you need to transfer from a complicated directory and want to return to the initial directory, you can pass the previous path to the cd command, but the little-known cd Command makes this thing trivial. This sequence shows the behavior: C code tektea @ ubuntu-laptop :~ /Documents/techtarget_articles/ten_command_line_tricks/test2 $ cd tektea @ ubuntu-laptop :~ $ Cd -~ /Documents/techtarget_articles/ten_command_line_tricks/test2 $ tektea @ ubuntu-laptop :~ /Documents/techtarget_articles/ten_command_line_tricks/test2 $3. create directory bookmarks to continue following the topics of directory interaction, and you will inevitably return to some directories again and again. You can add the path to the $ CDPATH shell variant (in your. in the bashrc file) to create bookmarks that allow you to quickly navigate to these directories: C code CDPATH = '. :/home/tektea/books. Once added, you can directly navigate to the bookmarks directory from any location in the operating system path. You only need to execute the following command: C code $ cd books 4. how many times have you edited and executed a series of slightly different commands in a dull manner? For example, when I am busy creating PDF versions of different book chapters from the Markdown source, I usually execute the following command: C code $ pandoc-o html/chapter06.html chapters/chapter06.md-template = templates/html. in order to create the chapter04.md source file, the command line beginners will soon get tired of using the up arrow to search in history before executing the (previous) command, then, use the left arrow until all chapter06.md instances are replaced with chapter04.md. There are many more efficient ways to execute this task. First, consider using the Bash command line to edit keyboard shortcuts (two modes are supported: Emacs and vi). This allows you to quickly navigate to the desired location: Ctrl +: go to the first line Ctrl + e: Go to the last line Alt + f: move forward a word Alt + B: Move back a word. The second and more effective method is to use command line replacement. The following command replaces 06 found in the previous command with 04: C code $ pandoc-o html/chapter06.html chapters/chapter06.md-template = templates/html. template $ !!: Gs/06/04 pandoc-o html/chapter04.html chapters/chapter04.md-template = templates/html. if you are accidentally using the GNOME terminal, the Meta (Alt) key does not work as described, because the gno me terminal has been bound with the Alt key to the toolbar command. You can also use Shift + Alt as the meta key, but this is a bit clumsy. On the contrary, if you do not need toolbar command shortcuts, you can choose Edit> keyboard shortcut to close them... You can also disable the Enable menu access key option. 5. Save the long command for later use. When operating by a system administrator, you can enter a specific long command and realize that one step in the sequence is omitted before executing it. You can save the command to history, instead of adding the # to the start of the command: C code $ # this is some ridiculously long command that I want to save after pressing Enter, use the Up Arrow, you will see the save command. To execute this command, you only need to remove the well number key from the beginning of the line before execution. 6. Using the command alias to save the long list format (ls-l) of the input ls command can be used frequently, but the hyphen makes it a little impractical for a large number of input. You can use the alias command in. bashrc to create a command alias for long commands. In this example, the command alias dir is a replacement of ls-l. C code alias dir = 'LS-l' 7. by ignoring input errors, you can save more input files that are in the terminal area. You can copy, update, and remove files from a directory to the next one. Or you are not in the terminal area, because your fingers are faster than the brain, or even the keyboard response time can be processed, this leads you to constantly return and correct your input errors. In your. bashrc file, shell automatically fixes all input errors when identifying the file or path name. C code shopt-s cdspell 8. Open the application in the background when you patrol the command line, you may need to perform another task, such as responding to an email. Of course, you can open the GUI application from the terminal by executing other commands. You only need to call their names. In this example, open Gimp: C code $ gimp but this effectively ends your terminal session because the application will open on the front end. If you are opening a specific program from the command line, consider. modify the default call in the bashrc file: C code gimp () {command gimp "$ @" &} reload your. the bashrc file (see the source command), you will be able to call the Gimp application, transfer together with any image file name you want to open, and retain additional benefits of terminal control. 9. Use less for more and more commands to quickly read text files. Once the file is loaded to the page, you can use/to search for the file. The problem is that once you find the desired row, you can navigate up and check that the content that appears higher than the row is not possible. Fewer commands are not inferior. They allow you to scroll up and down the text. The more commands you call in the same way: C code $ less sometextfile.txt 10. history command can easily be one of the most powerful tools at your disposal. However, a time-saving command is particularly worth mentioning: $ HISTIGNORE shell variable. Your history list will become very long over time. Use the $ HISTIGNORE variable to excrete records that you think are irrelevant: C code $ export $ HISTIGNORE = "&: cd: exit: "ls" will cause all copied commands, cd, exit, and ls commands to be omitted from historical commands. Speed is the key to managing command lines, and these 10 tips seem to be tricky, but the critical moments (such as interview) should help you.