What are the tips for using sudo in linux
This article mainly introduces what are the tips for using sudo in linux. It is very detailed and has a certain reference value. Friends who are interested must finish it!
1) sudo!
Usage: want to run a command as root authorization, but forget to use "sudo"? Don't worry. We can use "sudo!!" Combine the command history to execute the commands you want to execute. Parameter "!!" The same as "!-1", both allow the user to execute the command we just entered as a root. Of course, and so on, we can execute the penultimate command with the following command:
Sudo!-2
2) sudo-I
Using the above command, we can switch to the root state.
We can log in to shell with a specified user in the following command format:
Sudo-u username-I
Note that username can be changed to the user name you want to use, and you need to enter the authorization password of username in this process.
3) sudo output redirection
When we use sudo for output redirection, the second part of the command cannot be authorized
Sudo command > outputfile--root---user-
Solution:
Use 'sudo tee' instead of' >'
Use "sudo tee-a" instead of "> >"
Sudo command | sudo tee outputfile--root-root--
4): W! sudo tee%
The above command can be used in the vi/vim editor. Don't worry about not having permission to modify the file when you save it after editing it.
These are all the contents of this article entitled "what are the tips for using sudo in linux?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!