Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the practical skills in Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the practical skills in Linux what the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you read this Linux in the practical skills of what articles will have a harvest, let's take a look.

An interactive mode for finding the history of commands

‎ you are probably familiar with the ‎‎ history ‎‎ command ‎‎, which reads bash history and outputs it to standard output (stdout) as a numbered list. However, if you look for a specific URL in the ocean of ‎‎ curl ‎‎ commands, the list is not always easy to read. ‎

‎ you have another option. Linux has an interactive reverse search that can help you solve this problem. You can start interactive mode with the shortcut key ‎‎ ctrl+r ‎‎, and then enter an interactive prompt that will search backward for bash history based on the string you provide, you can search backward for older commands by pressing ctrl+r again, or press ‎‎ ctrl+s ‎‎ to search forward. ‎

‎ notes that ‎‎ ctrl+s ‎‎ sometimes conflicts with XON/XOFF flow control, that is, XON/XOFF flow control also uses this shortcut key. You can disable this shortcut by running the ‎‎ stty-ixon ‎‎ command. This is usually useful on your PC, but before you disable it, make sure you don't need XON/XOFF.

Cron is not the only way to schedule tasks

The ‎ Cron task is very useful for system administrators at any level, from inexperienced beginners to experienced experts. However, if you need to schedule an one-time task, the at command provides you with a quick way to create a task so that you don't need to contact crontab.

The at command runs immediately after the time you want to run the task. Time is flexible because it supports many time formats. Examples include the following:

At 12:00 PM September 30 2017at now + 1 hourat 9:00 AM tomorrow

‎ when you enter the at command with arguments, it will prompt you that the command will run on your Linux system. This could be a backup ‎‎ script ‎‎, a set of maintenance tasks, or even a normal bash command. If you want to finish the task, press ctrl+d. ‎

‎ in addition, you can use the atq command to view all the tasks of the current user, or use sudo atq to view all the tasks of the user. It will show all scheduled tasks, each accompanied by an ID. If you want to cancel a scheduled task, you can use the atrm command and take the task ID as an argument. ‎

You can search for commands by function, not just by name

It is very difficult to remember the names of commands, especially for beginners. Fortunately, Linux comes with a tool to search man pages by name and description. Next time, if you don't remember the name of the tool you want to use, try using the apropos command plus a description of what you want to do. For example, apropos build filesystem will return a series of tools with names and descriptions including the words "build" and "filesystem".

The apropos command takes one or more strings as arguments, but it also has other parameters, such as you can use the-r parameter to search through regular expressions.

An alternative system that allows you to manage the system version

‎ if you have done software development, you will understand the importance of cross-project management of support for different versions of the language. Many Linux distributions have tools to handle different built-in versions.

‎ executables such as java are often symbolically linked to the directory / etc/alternatives. In turn, the directory stores symbolic links as binaries and provides an interface to manage them. Java is probably the most commonly managed language for alternative systems, but with some configuration, it can also be used as an alternative to other applications, such as NVM and RVM (NVM and RVM are version managers for NodeJS and Ruby, respectively).

‎ on Debian-based systems, you can use the update-alternatives command to create and manage these links. In ‎‎ CentOS ‎‎, this tool is called alternatives. By changing the links in your alternatives file, you can install multiple versions of a language and use different binaries in different situations. This alternative system also provides support for any program you may run on the command line.

The shred command is a more secure way to delete files

‎ We always use the rm command to delete files most of the time. But where did the file go? The truth is that what the rm command does is not what you might think, it just removes the hard links between the file system and the data on the hard disk. The data on the hard disk still exists until it is overwritten by another application. For very sensitive data, this will bring a great security risk. ‎

The ‎ shred command is an updated version of the rm command. When you delete a file using the shred command, the data in the file is randomly overwritten multiple times. There is even an option to zero all data after random overrides. ‎

If you want to safely delete a file and overwrite it with zero, you can use the following command:

Shred-u-z [file name]

At the same time, you can also use the-n option and a number as parameters to specify how many iterations to iterate over the data at random.

Avoid entering long invalid file paths by automatic correction

How many times have you entered the absolute path of a file, only to see the message "there is no such file or directory"? Anyone can understand the pain of entering a long string. Fortunately, there is a very simple solution.

The built-in shopt command allows you to set different options to change the behavior of shell. Setting the cdspell option is an easy way to avoid the headache of entering a letter wrong when entering a file path. You can enable this option by running the shopt-s cdspell command. When this option is enabled, when you want to switch directories, it will be automatically corrected to the most matching directory.

The Shell option is a good way to save time (not to mention reduce hassle), and there are many other options. If you want to see a complete list of all the options on your system, you can run the shopt command without arguments. It is important to note that this is a feature of bash and may not be available if you run zsh or other optional shell.

Return to the current directory through the child shell

If you have ever configured a more complex system, you may find that you need to change directories frequently, making it difficult to track your location. Wouldn't it be nice to automatically return to the current location after running a command?

The Linux system actually provides a solution to this problem, and it is very simple. If you want to cd into another directory to complete some tasks, and then return to the current working directory, then you can put the command in parentheses. You can try this command on your Linux system. Remember your current working directory and run:

(cd / etc & & ls-a)

This command outputs the contents of the / etc directory. Now, check your current working directory. It is the same directory as before the command was executed, not the / etc directory. How does it work? Running a command in parentheses creates a child shell or a replica of the current shell process. The child shell can access all the parent variables, and vice versa. So remember, you are running a very complex one-line command. Sub-shell is often used in parallel processing, but it can also give you the same power on the command line, making it easier for you to browse the file system.

This is the end of the article on "what are the practical skills in Linux?" Thank you for reading! I believe you all have a certain understanding of the knowledge of "what are the practical skills in Linux". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report