Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
UNIX Tips and Tricks To Save You Time In Terminal (onextrapixel.com)
38 points by AndrewHathaway on Oct 9, 2013 | hide | past | favorite | 19 comments


Don't use too many aliases, a dozen generic ones should do it, learn to use reverse history search (usually mapped to Ctrl-r) instead.

Once you get used to it, your brain just triggers this combination whenever the command is more complex than let's say `ls -al`. This means you have to change some habits like to `tail` your logs with absolute paths, so you don't need to `cd` into the folder first, etc.


If anyone is interested, there were several great posts on Hacker News a while, these are packed with useful UNIX commands [0, 1, 2, 3].

[0] https://news.ycombinator.com/item?id=6360320

[1] https://news.ycombinator.com/item?id=6046682

[2] https://news.ycombinator.com/item?id=5022457

[3] https://news.ycombinator.com/item?id=4985393


Half these "unix tricks" are bash tricks. :/


This is what Gary Bernhardt would call 'atom' level unix programming. I encourage people to watch this talk : http://www.confreaks.com/videos/615-cascadiaruby2011-the-uni...

First it's quite funny, second it shows very pragmatic yet abstract usage of unix way of life, like quickly gathering data about your code base by combining other these atoms into new abstractions (as in SICP).

As he says, it's often half-assed, but it's the right half of the ass.


Obligatory:

http://www.commandlinefu.com/

I found some nice tricks there that I ended up using.

On the other hand, I found that customizing my shell, emacs, and other such things too much a bit frustrating when dealing with multiple machines. So often I have learned to live with the defaults. In other words I don't want to get used to typing "gst" for "git status" I just type "git status" because next machine I log into might not have the gst alias.


http://explainshell.com/ is pretty funky too.


This is really cool. Thanks for posting that!


I've also found the book "From Bash to Z Shell - Conquering the Command Line" very, very useful.[1] It's written as a beginner text, but even after ~15 years of *nix usage, I've learned a huge amount of new information, as well as learning the reasoning behind a number of the cargo-cult command line tricks that I had.

[1] http://www.bash2zsh.com/


I find it interesting that there's a whole section on creating bash aliases for git commands, completely ignoring the [alias] section available in .gitconfig (see https://git.wiki.kernel.org/index.php/Aliases for details and a variety of contributed examples).


>"If your terminal window is getting cluttered and you'd like to start from fresh, you can type clear. This will clear your window as if you've just reopened Terminal."

No, it won't. It only looks like it's like reopening the terminal, it won't reload your configs and stuff. Instead of writing "clear", you can do ctrl + r to achieve the same thing.

If you instead really want your terminal to be like reopened, do "reset" instead.

Regarding the history command, combining it with grep is when it becomes really useful. Example, all my latest git commands:

history | grep -i "git"


> you can do ctrl + r to achieve the same thing.

C-r will (usually?) invoke reverse-search-history (http://www.gnu.org/software/bash/manual/html_node/Commands-F...) in bash (and I'm sure some other shells also).


That is absolutely true. I meant super + r.


I think he meant C-l .


No, I didn't but that's pretty handy since it doesn't hide the new prompt.


Agreed, and clear won't help if you accidentally cat some binary code and put the terminal into "goofy symbols mode". In that case it's important to remember the reset command, especially if there's something vital running in that terminal and you can't just kill it.

But ctrl-r in bash starts a reverse history search, which is also very useful. It doesn't clear the screen, at least not the way it's configured on my linux machines.

See: http://www.talug.org/events/20030709/cmdline_history.html


You mean Ctrl + l?


Came here to post this.

Save more time with these: http://www.bigsmoke.us/readline/shortcuts


Genuinely useful tips, but a slightly misleadingly named article.


These are really, really newb level "tips" here. I'd consider this more of a "welcome to bash" intro. Are there really people on HN who don't know this stuff?




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: