Seven things you have to know about Linux tips

Source: Internet
Author: User

One of the coolest things about using Linux is that as time goes on, you can keep getting new knowledge. Every day, you may encounter a new utility, or just a less familiar artifice, but very useful. These fragmentary things are not always able to change life, but they are the basis of professional knowledge.

Even an expert can never know everything. No matter how much experience you have, there may always be more things for you to learn. So, here I've listed seven things you might not know about Linux.
650) this.width=650; "class=" AlignCenter size-full wp-image-31507 "src=" Uploads/2016/09/linux_kernel_48.jpg "alt=" Seven pieces of Linux tips you have to know seven pieces of Linux tips you have to know "width=" 533 "height=" "title=" Seven things you have to know about Linux tips seven pieces you have to know about Linux tips "style=" vertical-align:middle;height:auto;margin:10px auto; "/>

An interactive mode for finding command history

You may be familiar with the history command, which reads bash histories and then outputs to standard output (stdout) as a numbered list. However, if you look for a specific link (URL) in the ocean of the Curl command, the list is not always easy to read.

You can also have another option, and Linux has an interactive reverse search that can help you solve this problem. You can start the interaction mode with the shortcut key ctrl+r and then go to an interactive prompt that will search the bash history backwards based on the string you provided, and you can search for older commands by pressing ctrl+r backwards, or by pressing ctrl+s Search forward.

Note thatctrl+s sometimes conflicts with the Xon/xoff flow control, which is also used by the Xon/xoff flow control. You can disable the shortcut by running the stty-ixon command. This is usually useful on your PC, but before disabling, make sure you don't need to xon/xoff.

Cron is not the only way to schedule a task

Cron tasks are very useful for any level of system administrator, whether inexperienced beginners or experienced experts. However, if you need to schedule a one-time task, the AT command gives you a quick way to create tasks so you don't have to touch crontab.

The AT command runs at the back of the run time that you want to run the task. Time is flexible because it supports many time formats. Include the following examples:

At 10:00am September 2017at now + 1 Hourat 9:00am tomorrow

When you enter the AT command in a parametric manner, you will be prompted to run the command 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 end a task, you can press ctrl+d.

Alternatively, you can use the ATQ command to view all tasks for the current user, or use sudo atq to view all user tasks. It will show all the scheduled tasks, and each task is accompanied by an ID. If you want to cancel a scheduled task, you can use the ATRM command with the task ID as the parameter.

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

Remembering the name of the command is very difficult, especially for beginners. Fortunately, Linux comes with a tool to search the man page by name and description.

Next time, if you don't remember the name of the tool you want to use, you can try using the apropos command plus a description of what you want to do. For example, apropos build filesystem will return a list of names and tools that describe words that include "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've ever done software development, you'll understand the importance of cross-project management support for different versions of the language. Many Linux distributions have tools to handle different built-in versions.

Executables such as Java are often linked to directory/etc/alternatives. In turn, the directory stores symbolic links as binary files and provides an interface to manage those links. Java may be the most commonly managed language in an alternative system, but, with some configuration, it can also be used as a substitute for other applications, such as NVM and RVM (NVM and RVM are version managers of NodeJS and Ruby, respectively).

In 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 that you might run on the command line.

Shred command is a more secure way to delete files

Most of the time we always use the RM command to delete files. But where did the papers go? The truth is that what the RM command does is not what you think it is, it simply removes hard links to the data on the file system and hard disk. The data on the hard disk still exists until overwritten by another app rewrite. For very sensitive data, this poses a big security risk.

The Shred command is an upgraded version of the RM command. When you use the Shred command to delete a file, the data in the file is repeated randomly. There is even an option to clear all data after a random overwrite.

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

Shred-u-Z [file name]

You can also use the-n option and a number as a parameter to specify how many times to iterate when the data is randomly overwritten.

Avoid entering long, invalid file paths with AutoCorrect

How many times do you enter an absolute path to a file, but you see a "No file or directory" message. Anyone will understand the pain of entering a very 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 the shell. Setting the Cdspell option is an easy way to avoid a headache with a letter error 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 is automatically corrected to the most matching directory.

Shell options are a good way to save time (not to mention hassle), and there are plenty of other options. If you want to see a complete list of all the options on your system, you can run the shopt command without parameters. It is important to note that this is the feature of Bash, which may not be available if you run zsh or other shell that is available for selection.

Return to the current directory through a child shell

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

The Linux system actually provides a way to solve the problem and is very simple. If you want to go to another directory with a CD command to complete some tasks and then return to the current working directory, you can put the command in parentheses. You can try the following command on your Linux system. Remember your current working directory, and then run:

(Cd/etc && ls-a)

The command outputs the contents of the/etc directory. Now, check your current working directory. It is the same as the directory before executing the command, not the/etc directory.

How does it work? Running a command in parentheses creates a child shell or a duplicate copy of the current shell process. The child shell can access all of the parent variables, and vice versa. So keep in mind that you are running a very complex single-line command.

Child shells are often used in parallel processing, but in the command line it can also give you the same power, making it easier to navigate the file system.

Seven things you have to know about Linux tips

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.