Important! This is an automatic machine translated page. If you can read english, you should Click Here to read the original English version of the article.

Add Sudo to Your Last Bash Command With "!!" Thêm Sudo để Bash cuối của bạn Command Với "!!" Syntax Cú pháp

How often have you typed in a command in your linux shell, and then realized that you forgot to type sudo, so you end up with an error or editing the dreaded read-only file? Làm thế nào thường có bạn gõ lệnh trong shell linux của bạn, và sau đó nhận ra rằng bạn quên sudo loại, vì vậy bạn kết thúc với một lỗi hoặc chỉnh sửa các chi sợ hãi-chỉ tập tin? This happens to me much more than I'd like to admit, so I'm writing about it. Điều này xảy ra với tôi nhiều hơn tôi muốn thừa nhận, vì vậy tôi đang viết về nó.

You have a couple of options, the easiest one is to just use !! Bạn có một vài tùy chọn, một đơn giản nhất là chỉ cần sử dụng!! to tell bash to use the last command. nói cho bash để sử dụng lệnh cuối cùng.

For instance, if you tried to type this, you'd get an error that you are editing a read-only file: Ví dụ, nếu bạn đã cố gắng loại này, bạn sẽ nhận được một lỗi mà bạn đang chỉnh sửa một tập tin chỉ đọc:

vi /etc/apt/sources.list vi / etc / apt / sources.list

Once that happens, then you can just use this command: Khi điều đó xảy ra, sau đó bạn có thể chỉ cần sử dụng lệnh này:

sudo !! sudo!!

Which bash will then expand into this command: Bash mà sau đó sẽ mở rộng ra lệnh này:

sudo vi /etc/apt/sources.list sudo vi / etc / apt / sources.list

Screenshot of this in action: Ảnh chụp màn hình này trong hành động:

hình ảnh

An alternative method would be to just hit the up arrow key, hit either the Home key or Ctrl+A, and then type sudo. Một phương pháp khác sẽ được để chỉ bấm các phím mũi tên, hoặc nhấn phím Home hoặc Ctrl + A, sau đó gõ sudo.

This article was originally written on 07/30/07 Tagged with: Bài viết này ban đầu được viết ngày 07/30/07 Tagged với: Linux Linux

Daily Email Updates Email cập nhật hàng ngày

You can get our how-to articles in your inbox each day for free. Bạn có thể làm thế nào chúng tôi vào các bài viết trong hộp thư của bạn mỗi ngày miễn phí. Just enter your name and email below: Chỉ cần nhập tên và email của bạn dưới đây:


Name: Tên:
Email: Email:

Comments (11) Bình luận (11)

  1. Oliver Oliver

    Thanks. Cảm ơn.

  2. Thomas Thomas

    Thanks you very much, this is very usefull. Cảm ơn bạn rất nhiều, điều này rất có ích.

  3. Nep'n Nep'n

    That is surprisingly useful, I like the way you give us more than one way to do a lot of these things, the alternative methods can be useful for other stuff too Đó là hữu ích đáng ngạc nhiên, tôi muốn theo cách bạn cho chúng tôi nhiều hơn một cách để làm nhiều những việc này, các phương pháp thay thế có thể có ích cho các công cụ khác quá

  4. lachlan Lachlan

    the !! các!! also works with other commands like man cũng làm việc với các lệnh khác như người đàn ông

  5. arch vòm

    Just wondering if it would be possible to create a script that would execute this or an alias in ~/.bashrc or something. Chỉ cần tự hỏi, nếu nó sẽ có thể tạo một kịch bản mà có thể thực thi này hoặc một bí danh trong ~ / bashrc hoặc. Gì đó. I'm super-lazy so “sudo !!” is too many characters to type. Tôi là siêu lười như vậy "sudo!"! Là quá nhiều ký tự để loại. Why not something like “sss” The issue is that when I try a script or alias, it doesn't execute the previous command. Tại sao không giống như "sss" Vấn đề là khi tôi thử một kịch bản hay bí danh, nó không thực hiện lệnh trước đó. Any ideas? Bất cứ ý tưởng?

  6. A554551N A554551N

    I've been working on heavily modding my Ubuntu desktop, and whatever I google, howtogeek.com comes up as a top result. Tôi đã làm việc rất nhiều modding Ubuntu trên máy tính để bàn của tôi, và những gì tôi google, howtogeek.com đến như là một kết quả hàng đầu. Your suggestions, tips, and tricks are spot-on and incredibly useful, and I just wanted to say thank you. Góp ý, lời khuyên của bạn, và thủ thuật được tại chỗ trên và vô cùng hữu ích, và tôi chỉ muốn nói cảm ơn bạn.

  7. blu blu

    great, i love this one tuyệt vời, i love this one :)

  8. lowell Lowell

    no emacs love, huh? emacs không có tình yêu, huh? ;)

  9. Kalamadea Kalamadea

    This is so useful – thanks a lot. Điều này giúp ích - cảm ơn rất nhiều. It's *SO* annoying to have go all the way to the beginning of a command to add sudo after you forgot to the first time. It's * SO * gây phiền nhiễu để có đi tất cả các cách để đầu của một lệnh để thêm sudo sau khi bạn quên lần đầu tiên.

  10. Sam Sam

    Yes!!! Vâng! This is one of the most useful things I have ever heard Đây là một trong những điều hữu ích nhất mà tôi đã từng nghe nói

  11. Samik Samik

    Thanks! Cảm ơn! This would help me a lot. Điều này sẽ giúp đỡ tôi rất nhiều.


Our Friends Bạn bè của chúng tôi
Getting Started Bắt đầu


About How-To Geek Giới How-To Geek
What Is That Process? Quá trình đó là gì?
svchost.exe svchost.exe
jusched.exe jusched.exe
dwm.exe dwm.exe
ctfmon.exe ctfmon.exe
wmpnetwk.exe wmpnetwk.exe
wmpnscfg.exe wmpnscfg.exe
rundll32.exe rundll32.exe
wfcrun32.exe wfcrun32.exe
Ipoint.exe Ipoint.exe
Itype.exe Itype.exe
Wfica32.exe Wfica32.exe
Mobsync.exe Mobsync.exe
conhost.exe conhost.exe
Dpupdchk.exe Dpupdchk.exe Adobe_Updater.exe Adobe_Updater.exe

Copyright © 2006-2009 HowToGeek.com. Bản quyền © 2006-2009 HowToGeek.com. All Rights Reserved. Tất cả các quyền.