Share your command line features and tricks for Unix/Linux. Try to keep it shell/distro agnostic if possible. Interested in seeing aliases, one-liners, keyboard shortcuts, small shell scripts, etc.
|
|
locked by Michael Mrozek♦ Nov 6 '11 at 0:41
This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: FAQ.
|
This expands somewhat on the
Word designators can be added on to a
Modifiers can also be appended to a
|
|||||||||||||||||||||
|
|
bash -- insert preceding line's final parameter alt-. the most useful key combination ever, try it and see, for some reason no one knows about this one. press it again and again to select older last parameters. great when you want to do something more to the argument/file you used just a moment ago. |
|||||||||||||
|
|
My favorite is
Simple and so very useful.
Have a look at this website commandlinefu.com. You can also have a look at these four articles by Peteris Krumins on his blog |
|||||
|
|
Execute last command as root:
|
||||
|
|
|
Not sure if this counts as a "trick", but people seem very unaware of the standard readline hotkeys. Of particular use in shells:
|
|||||||||
|
|
CTRL+R in BASH for searching/activating previously executed commands (the contents of ~/.bash_history). This is often extremely helpful. Running this alias will serve the PWD up over HTTP (indexed) on port 8000:
And because I run make all the time, and spaz out and type too quickly, these aliases are probably my most used (seriously):
And probably my most frequently used piece of BASH is a simple script I call upload. I use it to blit any kind of content to my Linode, and it copies the resulting HTTP URL to my clipboard (middle click). Very useful for pasting stuff to people in IRC:
Just a couple. I can post much more later, must get back to work! |
|||||
|
|
|
||||
|
|
|
Pretty basic, but people don't seem to know, returns you to the previous dir:
|
||||
|
|
It allows you to replace tedious lines like:
with a shorter instance
some other uses
Arithmetic Expansion:
|
|||||
|
|
This is usually in my startup script (.bashrc, .profile, whatever)
An alias that save keystrokes:
And last but not least, I've given up on memorizing tar syntax, so:
|
|||||
|
|
Two bash functions which save me many key strokes. Do automatically an ls after every successfull cd:
Go up n levels:
|
|||||||||
|
|
Since I'm usually halfway into a command line before wanting to search (CTRL-R in bash) I have the following in my .bashrc
This means that if I type cd then press up/down I can see all the options that I have cd'd to. Basically I use this for often used dirs. Like "cd w" and I'm ending up going through all the workspaces I use lots. |
||||
|
|
|
One thing that saves me a lot of time is the pushd/popd commands. These guys let you create a stack of directories and reduce typing a lot:
|
|||||||||||||
|
|
The If one uses
upon typing |
|||||
|
|
If you need to edit a particularly long command line in bash
will open it in the editor ($EDITOR). In zsh you can get the same behaviour by adding this to .zshrc:
|
||||
|
|
|
If you are a fast typist, these come in handy:
This macro helps you compute totals of a column of output: file sizes, bytes, packets, all you have to do is specify the column that you want to add:
You use it like this for example, with no arguments, it adds the total of the first column:
If you provide the argument, it will sum that column, for example, this gives you the total number of bytes used by all the C# files in /tmp:
Sometimes your console gets messed up because you accidentally viewed a binary file (cat /bin/ls for example), you can restore the terminal with this shell function:
I like my ls to use characters to distinguish the class of files, and also to hide the backup files generated by my editor (backup files end with the ~ character):
|
|||||||||||||
|
One of my favorites when I forget
|
|||||
|
|
If a command takes stdin input, you can read the input from a file with
This is particularly useful for grep, as it allows you to place the expression at the end of the line, so you can quickly modify a grep command it by hitting Up, without needing to scroll left to get past the filename:
|
|||||
|
|
You can use
|
|||||
|
For when you don't know where something lives, and you don't care either. |
|||||
|
|
The ampersand. It puts your command in the background, so you can continue typing.
Working along, and after a while you see:
And your process is done! Great for things where you don't need to wait for them to terminate. |
|||||||||
|
|
Tab completion. How bad would it suck if you had to type out all the characters of every path? |
|||||
|
|
Umount last mounted device:
|
||||
|
|
|
I have this in my .bashrc
And when I have html source code in clipboard and want to find all links I use
And I have all urls in clipboard I also have this function
which display size (human readable) and filename.
this alias is for show temerature
with this function I can calculate product or sum of arguments.
This is usefull function which split standard input separated by regex and then join the result.
factorial function
This function display wiki text over DNS I also have three color funcions
This function validate file md5 hash. this will show error message for a given code
You can print all messages with
|
||||
|
|
|
Another useful ZSH trick: Treat the output of a command as a file:
This opens an old version of a Mercurial-tracked file in emacs for syntax-highlighted viewing. Without that, I would have to mess around with Of course, this works with any program that opens files, and any program that prints to standard output. |
|||||
|
|
A ZSH-specific feature is suffix aliases, set by giving
If a given extension has a suffix alias, you can execute a file with that extention directly, and ZSH will launch the given program and pass the filename as an argument. So if the above alias is in effect, these lines are equivalent:
|
||||
|
|
|
One of my all-time favorite ZSH features is named directories. You can export a variable with a given name, with a value that points to a certain path:
Now you can use
|
||||
|
|
|
See this question. When you run
the last line containing You can rid yourself of this by running
update: or just run |
||||
|
|
|
||||
|
|
|
I love chucking as much stuff as I can into my PS1. Some useful things to remember:
Combine with Also, the Another one is the |
||||
|
|
