history – Internetblog.org.uk https://www.internetblog.org.uk Web hosting, Domain names, Dedicated servers Fri, 29 Jan 2016 11:05:52 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.5 https://www.internetblog.org.uk/files/2016/01/cropped-favico-32x32.png history – Internetblog.org.uk https://www.internetblog.org.uk 32 32 Easily Repeat Root Commands with History https://www.internetblog.org.uk/post/1561/easily-repeat-root-commands-with-history/ Thu, 22 Jul 2010 15:36:55 +0000 http://www.internetblog.org.uk/post/1561/easily-repeat-root-commands-with-history/ Password keys iconPreviously, I mentioned some of the benefits of using the “history” command to display any or all of your previous commands. On dedicated servers, whether Linux or Unix, that use “sudo” rather than “su” to become root, it can be aggravating when you type a long command string only to realize you forgot to type “sudo.”

One easy solution is to press the up arrow, move over to the beginning of the string, and add sudo. But there is an even easier way to replay the command with root permissions.

Right after you have entered the command missing sudo, just type the following:

sudo !!

This will automatically run the last command in the shell history with whatever you place before it (in this case “sudo”). It is quick, easy, and gets the job done. In fact, you can use “!!” any time you want to repeat the previous command. Log in to your server via SSH and give it a try.

Photo Source: Wikimedia Commons

]]>
Quick and easy sudo trick for servers https://www.internetblog.org.uk/post/1461/quick-and-easy-sudo-trick-for-servers/ Wed, 23 Jun 2010 18:58:00 +0000 http://www.internetblog.org.uk/post/1461/quick-and-easy-sudo-trick-for-servers/ keysQuestion: I just typed a really long complicated command line string on my server, but I forgot to type “sudo” at the beginning. Is there a quick way to enter it again?

Answer: The history feature in Linux and Unix-like operating systems is truly a beautiful thing. With it, you can easily re-enter commands. But what do you do if you need to re-enter a command but need to add “sudo” to the beginning? On Ubuntu, Mac OS X, and many other servers, “sudo” is the default method used to gain administrative rights, but it must be entered before each administrative command.

There are two ways to fix this. One is to simply press the up arrow. You will again see your command exactly as you typed it. To add sudo to the beginning, press the “Home” key, which should move the cursor to the front. Then, all you have to do is enter sudo, add a space, and press Enter.

An even quicker method is to use “sudo !!” to automatically reload the command with sudo. This will look to the last command entered in the “history” list and run it again. You can also use “!!” without sudo anytime you want to quickly run a command again.

Image Source: Wikimedia Commons

]]>
The "history" command in Linux https://www.internetblog.org.uk/post/693/the-history-command-in-linux/ Thu, 19 Nov 2009 20:20:08 +0000 http://www.internetblog.org.uk/post/693/the-history-command-in-linux/ Linux Inside
If you spend a lot of time working from the command line on your server, you will undoubtedly grow tired of having to type the same ones repeatedly in a session. And if you are anything like me, you might grow tired of having to look up long strings of old commands even within a new session. Fortunately, those of you on Linux servers have the “history” command.

An easy way to scroll through the immediate history is to press the up arrow key. You can press it as many times as you want to go through the entire command history. To find something specific, executed several sessions ago, the history command is more efficient. To execute, simply type “history” from the command prompt. To execute a particular command type “!” followed by the number. For example: “!477”.

To write your history to a file, type: history -w filename, and to append the current history to the end of an already created history file, type history -a. You can also do the reverse, appending whatever you have in the history file to your current list with history -r. Finally, if you need an empty list, history -C will clear it completely. For more information about “history”, type man history from the command line.

Photo Source: Flickr

]]>