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 tips for using sudo in linux

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

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!

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

Servers

Wechat

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

12
Report