I use this all the time. In fact it was one of the first aliases i made when i switched to a UNIX system. Though I named mine `greph` (for grep history). Absolutely invaluable
It always feels more logical to me to just type "Ctrl-P Ctrl-A sudo" (previous history line, beginning of line, add missing sudo) than typing "sudo !!" or "sudo !!<tab>" if you need to edit the substitution.
Same thing for the last argument, it's easily edited if you know the right shortcuts: Ctrl-P Alt-B Ctrl-U. (Works for bash, for zsh you need http://stackoverflow.com/q/3483604/414272). That said, I didn't know about Alt-.
You know what I hate? My history isn't aggregated in real time across all my Mac OS X terminal windows.
You know what else I hate? Typing in long commands in the Mac OS X terminal and then them wrapping weirdly. Especially when I hit the up arrow to go back in my terminal history.
> You know what else I hate? Typing in long commands in the Mac OS X terminal and then them wrapping weirdly.
Yeah, keeping ctrl pressed in and pressing x followed by e (CTRL + x e) will open up the current line in $EDITOR and when you edit and save, replaces the current line with what you entered in your editor. Really a killer feature.
> Typing in long commands in the Mac OS X terminal and then them wrapping weirdly.
For all people who dont use Mac OS X:
This happens because your PS1 is wrongly set and bash cant calculate correctly the length left of your line. Try it out, by going back to default with no colors and crap and see how long it goes.
For mac os x users. The above wont help, dont even try it.
I prefer to keep mine separate, but I always use specific terminals / screen sessions for (mostly) the same type of work (admin, specific projects, web dev, etc.) so each have their own history, as well as keeping a per-directory record.
So far over 130000 command lines (with timestamp & cwd) for past 2.5 years, just on my laptop.
You know what I hate? My history isn't aggregated in real time across all my Mac OS X terminal windows.
I used to feel this way. Then one day I figured out how to enable this in Bash. Resulted in a confusing mess. Turns out you most likely want terminal sessions to be distinct until you end them.
No! In emacs ctrl-r searches your command history. It happens that bash use emacs mode by default. All other emacs basic commands work too: ctrl-p, ctrl-n, ctrl-f etc...
If you are a vim user, and especially if you love venting how much you hate emacs, then please add this to your bashrc:
The -n flag tells ssh to only make a connection, without ever running a shell. This means it even works when you don't have shell access (say, with a command= entry in .authorized_keys).
Also, I cannot recommend envoy enough in lieu of ssh-agent, if you're not using a GUI ssh agent already (e.g OSX keychain or GNOME keyring)
Last, I guarantee you don't want "$@" in those aliases, but either "$*" or $@ (certainly the latter).
I think you meant -N, not -n. From the man page[1]:
-N Do not execute a remote command. This is useful for just for‐
warding ports (protocol version 2 only).
-n Redirects stdin from /dev/null (actually, prevents reading from
stdin). This must be used when ssh is run in the background.
I usually visit these threads knowing that I will pick up something useful to add to the toolbox... thank you for 'envoy' - I think it will streamline my ssh key management.
I wonder if I can convince the author of this to put it up in a Git repo so everyone can contribute. It probably needs the tiny URLs removed (IME, they're more likely to break than the original site)
I love fish and have happily been using it for years. Every time it comes up here, though, someone inevitably will complain about compatibility - and I will admit that RVM, for instance, has definitely caused me problems with fish in the past. I guess it depends quite a lot on your particular usage and requirements.
"- Compile your own version of 'screen' from the git sources. Most versions have a slow scrolling on a vertical split or even no vertical split at all"
I suggest bashmarks http://www.huyng.com/projects/bashmarks/ to bookmark directories and jump there with a quick command.
I also like to alias ..="cd .." and alias ...="cd ../.." to quickly navigate up.
A really handy one a colleague showed me yesterday was the /dev/fd/0|1|2 files, which are stdin/out/err respectively.
Means you can use that file for utils that expect a file only.
E.g echo "This would be contents of file" | someCommand /dev/fd/0
You can even access the file descriptors of other processes with /proc/${pid}/fd/; which is handy for (say) un-deleting a file that a process still has open.
Another handy one is "process substitution" which lets you do the same thing with multiple streams by creating new file descriptors, and automatically turning them into /dev/fd/* paths:
someCommand <(echo "contents of file 1") <(echo "contents of file 2")
which is somewhat explained by:
$ echo someCommand <(echo "contents of file 1") <(echo "contents of file 2")
someCommand /dev/fd/63 /dev/fd/62
[+] [-] Tepix|11 years ago|reply
In bash, "ESC" then "." fetches the last parameter of the previous command. It's invaluable (same as typing "!$" but you get to see and edit it)
[+] [-] wazoox|11 years ago|reply
[+] [-] WickyNilliams|11 years ago|reply
[+] [-] hrrsn|11 years ago|reply
[+] [-] valarauca1|11 years ago|reply
[+] [-] a3_nm|11 years ago|reply
Same thing for the last argument, it's easily edited if you know the right shortcuts: Ctrl-P Alt-B Ctrl-U. (Works for bash, for zsh you need http://stackoverflow.com/q/3483604/414272). That said, I didn't know about Alt-.
[+] [-] cheepin|11 years ago|reply
[+] [-] vehementi|11 years ago|reply
[+] [-] 3rd3|11 years ago|reply
[+] [-] ciupicri|11 years ago|reply
[1]: https://plus.google.com/+LennartPoetteringTheOneAndOnly/post...
[+] [-] spopejoy|11 years ago|reply
"apropos Regular Expressions" brings up wild stuff: re_format(7) -- posix regex docs at last!, treereg(1) (huh????).
Some serious lore in here ...
[+] [-] robert_tweed|11 years ago|reply
[+] [-] danielweber|11 years ago|reply
Why do some distributions use /opt a lot while others don't seem to use it at all?
[+] [-] smorrow|11 years ago|reply
[+] [-] curiousHacker|11 years ago|reply
You know what else I hate? Typing in long commands in the Mac OS X terminal and then them wrapping weirdly. Especially when I hit the up arrow to go back in my terminal history.
[+] [-] Tiksi|11 years ago|reply
[+] [-] diggan|11 years ago|reply
[+] [-] ibotty|11 years ago|reply
zsh has `setopt inc_append_history` and `setopt share_history`. i am sure bash has something similar.
[+] [-] Spiritus|11 years ago|reply
Are you escaping your color codes in PS1 correctly?
Bad:
Good (notice the extra \[ and \]):[+] [-] JoeAcchino|11 years ago|reply
I solved this by adding the following line in my ~/.bashrc
Never tried on Mac OS X though, so I don't know if it works.[+] [-] antocv|11 years ago|reply
For all people who dont use Mac OS X:
This happens because your PS1 is wrongly set and bash cant calculate correctly the length left of your line. Try it out, by going back to default with no colors and crap and see how long it goes.
For mac os x users. The above wont help, dont even try it.
[+] [-] toddkaufmann|11 years ago|reply
So far over 130000 command lines (with timestamp & cwd) for past 2.5 years, just on my laptop.
[+] [-] naner|11 years ago|reply
I used to feel this way. Then one day I figured out how to enable this in Bash. Resulted in a confusing mess. Turns out you most likely want terminal sessions to be distinct until you end them.
[+] [-] jdong|11 years ago|reply
[+] [-] samsaga2|11 years ago|reply
Ctrl-x Ctrl-e nice tip!
[+] [-] pling|11 years ago|reply
[+] [-] raju|11 years ago|reply
[+] [-] tomsthumb|11 years ago|reply
[+] [-] danielweber|11 years ago|reply
sort -u
[+] [-] WickyNilliams|11 years ago|reply
[+] [-] dorfsmay|11 years ago|reply
No! In emacs ctrl-r searches your command history. It happens that bash use emacs mode by default. All other emacs basic commands work too: ctrl-p, ctrl-n, ctrl-f etc...
If you are a vim user, and especially if you love venting how much you hate emacs, then please add this to your bashrc:
set -o vi
and now you can use vim command instead of emacs.
[+] [-] dllthomas|11 years ago|reply
[+] [-] nemasu|11 years ago|reply
[+] [-] lloeki|11 years ago|reply
Also, I cannot recommend envoy enough in lieu of ssh-agent, if you're not using a GUI ssh agent already (e.g OSX keychain or GNOME keyring)
Last, I guarantee you don't want "$@" in those aliases, but either "$*" or $@ (certainly the latter).
[+] [-] ciupicri|11 years ago|reply
[+] [-] zipperhead|11 years ago|reply
[+] [-] voltagex_|11 years ago|reply
[+] [-] TimWolla|11 years ago|reply
[+] [-] bshimmin|11 years ago|reply
[+] [-] currysausage|11 years ago|reply
Ctrl-V: type next input literally (e.g. Ctrl-V [Tab] if you don't want [Tab] to autocomplete).
Alt-#: Prefix current line with "#" (don't execute it) and put it into history for later use.
I'm sometimes surprised how many people don't know these: Ctrl-U/K: kill line before/after cursor.
[+] [-] chanux|11 years ago|reply
alias clip='xsel -i --clipboard'
Get tree view of directories
alias lst='tree -L 2 $1'
Also I use za to go up in directory tree
bash https://gist.github.com/chanux/1119556 fish https://gist.github.com/chanux/9411092
[+] [-] thln666|11 years ago|reply
Or you could just use tmux which afaict is superior to screen in almost every way. http://tmux.sourceforge.net/
[+] [-] pmontra|11 years ago|reply
[+] [-] rzimmerman|11 years ago|reply
[+] [-] buerkle|11 years ago|reply
[+] [-] cmatteri|11 years ago|reply
[+] [-] JonnieCache|11 years ago|reply
This might be a zsh thing though.
[+] [-] o_____________o|11 years ago|reply
https://github.com/ziyaddin/jean
It would be nice to get all of these .bash_profile enhancements in as packages.
I suppose it could be improved to prompt for a brew/apt install if needed.
[+] [-] marcosscriven|11 years ago|reply
E.g echo "This would be contents of file" | someCommand /dev/fd/0
[+] [-] LukeShu|11 years ago|reply
Another handy one is "process substitution" which lets you do the same thing with multiple streams by creating new file descriptors, and automatically turning them into /dev/fd/* paths:
which is somewhat explained by: