Posts

Showing posts with the label shortcut

Bash Shell, X, & Firefox Shortcuts

Image
As I was writing a script, I noticed that I pressed Shift-PageUp without even thinking about it. Then I realized that there are a lot of shortcuts we take for granted as Sysadmins. I thought it would be helpful to share some of them. This is not a comprehensive list, but a few shortcuts I find myself using all the time. Bash Shell shortcuts Shift-PageUp / PageDown See more of the screen Ctrl-a, Ctrl-e Move to beginning / end of line up & down arrows See bash history !! / !$ Execute the previous command / parameter !n Execute the nth command in history Ctrl-D Logout, or exit Ctrl-u, Ctrl-h, Ctrl-b Delete previous char, or entire line Alt-F1 to Alt-F7 Switch to another console —see also: using-bash-history , ...

Mail a Text File from the Shell

Image
Would you like an easy way to send files to someone outside of your local network, or quickly test a mail server? Well the old "mail" command is still available, and it comes in handy for sending config files, or using within a shell script. This is all you need: $ mail -s test me@company.com That's the shortcut. If you want more details, you can read the rest of the post... Using the mail command 1) Use Mail Interactively to read mail a) type Mail b) enter the number of the message to read, press enter c) press space to page down, n for next message d) ? for help e) q to quit 2) Use mail Interactively to send mail a) type mail command followed by email address b) Enter subject, press enter c) Enter text of message d) press Ctrl-d on a line by itself when finished e) Enter CC: if desired, or press Ctrl-d again $ mail user@company.com Subject: test Here is my test message <Ctrl-d> Cc: <Ctrl-d>$ For a little less work, add the subject to the command prompt. ...

Shell Console Reset

Image
Did you ever cat a file that caused the terminal to display all kinds of strange characters? Pressing Ctrl-C and Enter, or typing clear doesn't get the console back to normal. The characters are there, but they are unreadable. A quick way to fix this is to use "reset" -- type: $ reset That should bring the console back to normal. Of course, if you just want to clear the screen, you can type "clear" ("cls" in DOS, or a Windows command prompt).

Using the Bash History

Image
The command history is stored in ~/.bash_history. The history typically contains the last 500 commands typed at the shell prompt. You can view the history by using the history command. history | less Then you can search for a command. e.g. what was the name of that directory I created yesterday? Oh, yeah, I can search history for the mkdir command by using the slash. /mkdir You could also use grep, but with less, you can see the surrounding commands, as you often want to see the sequence of what was done. History Shortcuts !! - Executes the last command !902 - Executes command number 902 (from the history list) !service - Executes the command whose string matches the most recent history entry Up / Down - The most common shortcut is to simply use the up and down arrows to scroll through the bash history. Example If you recently restarted the network service, and then wanted to restart it again, you might do something like this; service network restart ping somehost.example.c...