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.
|
Display Git branch and status in the prompt
export GIT_PS1_SHOWDIRTYSTATE=true
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$(__git_ps1 "#%s")\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1 "#%s")\$ '
fi
|
|||||
|
|
Sometimes bash settings are such that |
||||
|
|
|
Displays a nice ascii art of the current proccess tree, with the most cpu intensive proccess higlighted.
Kill it with |
|||||
|
|
Once so often when you've typed a long command and before finishing it you've realized it won't work right away, because you need to run something else before (e.g. entered Another time-saver: |
||||
|
|
|
My favourite command is 'find', I use it everywhere... examples:
Just display heaviest files in ls -l (long) format. Then, if you need your code with 0640 permissions, just search:
or replace:
Then, do you need a symbol and don't know where is it??
Newer files than XFILE??
Yeah, "find" rulez! |
||||
|
|
|
my favorite feature is NO COLORS! =) TERM=xterm-mono or TERM=linux-m depends on OS... I really like black and white IRSSI, mc and any other "Text user interface" tool |
||||
|
|
|
ZSH has global aliases. It expands the alias anywhere in the command line. I've found this useful for hostnames: E.g.:
Then, I can do e.g.:
etc. |
||||
|
|
|
||||
|
|
|
See command output updated every n seconds
Show statistics about network device wlan0
Show routing table for device eth1
Display statistics for all routers packet travels through to reach HOST
Consult reverse DNS records for host names on NETWORK
Benchmark a website
Get all links from a web page
Show default gateway
Write standard error to a file
Redirect stderr to stdout
Redirect both stderr and stdout to the same file.
|
||||
|
|
|
Replace parts of the previous command:
Great for typos:
|
||||
|
|
|
Summarize directory size, with descending human size
e.g.
|
||||
|
|
|
double star expansion with zsh (which recursively descends the directory tree, not just one level, something similar to
|
||||
|
|
|
Display a prompt where the hostname is bold. I tried color prompts for a while, but the color would sometimes look bad depending on the background. Bold works for me for light background, dark background, blue backgrounds, etc. This is in my .bashrc :
|
||||
|
|
|
This is for zsh, not bash, fyi (if you haven't used it, you won't regret trying it out). This is really useful for quickly typing out long paths for scp transfers. It works just like using to complete or list available filenames/directories. Example
will complete the path to I'm bad at examples, but that should give you the idea. Try it out, it can really save you fingers from typing.
|
||||
|
|
|
I have folders named in my home folder as Document, Downloads, Temp, etc with the first letter in uppercase. When I work on the terminal it's annoying to shift press the first key when you are cd'ing into a directory. Just key in the following in your terminal and bash would auto-correct the case for you.
|
||||
|
|
|
None of the following 'tricks' is technically challenging or impressive, but they have some impact on the other person. If we can't use our jobs to make our lives happier, then we should think again about some things. I like
or another romantic quotation. Another "trick" I especially like is:
where 123 is the of the person to whom I would like to wish happy birthday and mails.txt contains the message that I would like to write as the body of the email. Sleep 1; is sometimes necessary as there is a limit on fork(). You could also use command line arguments |
||||
|
|
|
I can't live without
in my ~/.inputrc. Activates them in every readline enabled application. Only activating vi command line editing in the shell works via:
Thus, hitting ESC or CTRL+[ gets you the well known vi-command mode. And you can use powerful vi commands everywhere! |
||||
|
|
|
Use e.g. instead of |
||||
|
|
dc is a RPN calculator; this function enables me to type the expression as the command arguments:
|
||||
|
|
|
There is a great site for this at: http://www.commandlinefu.com/commands/browse |
||||
|
|
|
I found the following useful when constantly switching between Windows and Unix/Linux:
|
||||
|
|
|
Not really a one-liner but I think it's useful. Convert many files to uppercase, for example
|
||||
|
|
|
Mine favorite is to use the python command to make the temporary http server:
and accessing files from this machine over the lan as: Another one is to download the tar file in extracted form as:
Here the link can be any over the www and bz2 can be either gz, tgz or bz2 itself for that matter. |
||||
|
|
Backup your fancy dot files automagicallyModular .bashrc --> .bashrc.d
Safer rm, compatible with Linux and Mac OS X
Super hot 'cd' up action
Readline is your one true god.
Terminal fontsAfter looking at bazillions of fonts, I use On Mac (Apps): Try this app that gives key bindings.KeyCue (tm)(r)(c)($) gives context of almost ANY running app by simply holding command. |
||||
|
|
|
get the file name with the most recent timestamp in the current directory:
|
||||
|
|
|
zsh's auto pushd feature:
and together with that:
So that at any time, I can type
and then I can
|
||||
|
|
|
ReTTY, which allows you to move a running program from one terminal to another. That way, if you have an ncurses program running outside of screen, tmux, or ssh, you can attach it to an ssh session or a networked screen or tmux session by running ReTTY inside the terminal where you want to use the program in question. In other words, it is similar to screen and tmux but with the exceptions that (a) it can only run one program at a time, and (b) it can be run after you start the child process. |
||||
|
|
|
sync;sync;sync;reboot can be really useful sometimes. Be careful ! |
|||||
|
|
My personal favorite is
What the above command does is find a file of name x and then searches said file for whatever pattern you are looking for. Incredibly useful if you are looking for a particular bit of code in a file that's somewhere in your subdirectories. |
|||||||||
|
|
I find understanding bash key strokes leads to more efficient shelling, and that a lot of them are straight from emacs clarifies their usage (i.e. that The "meta" key is usually the "alt" key, but can also be "esc" key. e.g. For the alt- key mappings to work, you may have to unset "menu access keys" or its equivalent in the console options. Basically if you press alt-f and get the file menu prompt, turn off the alt-key access menus.
|
||||
|
|