Home  >  Article  >  System Tutorial  >  Seven secrets about Linux systems that you may not know yet

Seven secrets about Linux systems that you may not know yet

WBOY
WBOYforward
2024-01-05 08:16:401131browse

Seven secrets about Linux systems that you may not know yet

Linux is a free-to-use and freely disseminated Unix-like operating system. It is a multi-user, multi-task, multi-thread and multi-CPU operating system based on POSIX and UNIX. It can run major UNIX software tools, applications and network protocols. It supports 32-bit and 64-bit hardware. Linux inherits the network-centric design philosophy of Unix and is a multi-user network operating system with stable performance.

One of the coolest parts of using Linux is gaining new knowledge over time. Every day, you might come across a new utility, or, perhaps, an unfamiliar flag that does something useful. These small details may not always be life-changing, but they are the building blocks of expertise.

Even the experts don’t know it all. No matter how experienced you are, there's always more to learn, so here are seven things you may not know about Linux systems.

Historical commands have interactive mode

You may be familiar with the command history of Linux systems. This command can provide a standard list of bash input commands. However, this list may not be very useful if you are looking for a specific URL among many "curl" commands.

Using substitution, Linux provides an interactive reflection search function to help you deal with the above troubles. You can press the "Crtl r" key to activate the command history query function, you can interactively enter the command content, and press the "Crtl r" key to cycle through the command history containing the input content. After finding it, press the Enter key to execute it again, or you can use the arrow keys to select it, and the command will be entered again and wait for execution.

Cron is not the only way to schedule tasks

The cron command is extremely useful for users at the task level. Whether they are beginners or experienced experts, they can use this command to formulate task plans for system execution. But if you only develop a task once, then the "at" command allows you to achieve the goal without touching the crontab table.

Enter "at" at the command prompt and follow the task plan execution time. The command supports a variety of time formats, which can be specific execution time and delayed time nodes. Here are some specific examples:

"at 12:00 PM September 30 2017"

“at now 1 hour”

"at 9:00 AM tomorrow"

After the input is completed, you can enter the tasks to be performed. After all tasks are entered, start a new line and press "Ctrl D" again. "EOF" will be displayed to indicate that the input is completed. Now you have completed setting up a task plan. Furthermore, you can use the "atq" command to query your unexecuted task list; you can also use "atrm" plus the task number to cancel the task plan.

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

Remembering each command name can be a bit difficult, especially for beginners. Fortunately, Linux comes with a man tool that searches by function description and command name. Next time, if you have trouble remembering the name of a command you want to use, you can try looking up the command you want with an appropriate description. For example, a command about building a filesystem would return a list of names and descriptions for the tool, including "build" or "filesystem". Now, you can enter "manbuild filesystem" and the man tool will display the corresponding commands based on your input.

man will receive one or more strings as arguments, but it also has the option -R, which allows you to search by regular expressions.

An alternative system allows you to manage versions

If you have ever been involved in software development, then you will know the importance of cross-project version management. Many Linux distributions have tools to handle the different versions built-in.

Executable files like java are often symbolically linked to /etc/alternative. This directory, in turn, stores symbolic links to binary files and provides an interface for managing these links. Java is the most commonly used language replacement, but with a little configuration, it can also be used as an application replacement like NVM and RVM (e.g. NodeJS, Ruby).

On Debian-based systems, you can create and manage these link update scenarios. In CentOS, tools are so-called replacements. By changing the link in the replacement file, you can install multiple language versions and use different binaries in different situations. Of course, this isn't limited to programming languages. This alternative system also supports any executable you might want to run from the command line.

"shred" command

Most people use the "rm" command to delete files, but are the files actually deleted? In fact, the system does not do what you expect. The system only creates a hard link between the file system and the disk file. delete. These "0" and "1" values ​​persist until they are overwritten by another application, which is very unsafe for sensitive data.

The "shred" command is the absolute form of "rm". When you "shred" a file, the physical data of this file is overwritten randomly multiple times. There is even an option to overwrite the original data with a string of zeros after deleting the file.

The command to completely delete a file and overwrite it with zeros is:

shred -u -z [file name]

You can also add the n option with a number as a parameter. This option allows you to specify the number of iterations to randomly overwrite the data.

"AutoCorrect" function to avoid errors when entering long file paths

How many times have you entered an absolute file path, only to get the "No such file or directory" message? Everyone doesn't want to experience the pain of facing a long list of wrong paths. Fortunately, Linux has a simple solution.

The built-in "shopt" command allows you to set various options to change the behavior of your shell. Setting the cdspell option to "on" can avoid the headache of file path problems caused by a single incorrect letter. You can enable this option using the "shopt-s cdspell" command. Once activated, file paths are automatically corrected to the closest match when you try to enter the directory.

The

shell option is a great way to save time (not to mention trouble), and there are many others. To see a complete list of shell options, run shopt without arguments. Be aware that this is a feature of bash, so if you are using another shell, you may not be able to use this command.

Quickly return to the current directory

If you have configured a moderately complex system, you may find yourself changing directories frequently, making it difficult to keep track of where you are. Wouldn’t it be nice if you automatically returned to your current location after running a command?

Linux actually provides a solution to this problem, and it's very simple. If you go into another directory to do something and then return to the current working directory, enclose the command in parentheses. Here's an example you can test yourself. Make a note of your current directory and run:

(cd /etc && ls -a)

This will display the contents of the /etc/ directory instead of the contents of your current directory.

The above is the detailed content of Seven secrets about Linux systems that you may not know yet. For more information, please follow other related articles on the PHP Chinese website!

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