Hacker News new | comments | show | ask | jobs | submit login
A great list of command-line tips (commandlinefu.com)
223 points by shocks on Apr 15, 2012 | hide | past | web | favorite | 28 comments

The #1 thing that'll improve most people's workflow is learning how to use readline effectively. I'm continually amazed by how many people who use shells daily use the arrow keys to navigate around, don't know about common things like C-r to reverse-search through history and other commands that make editing on the command-line a breeze.

In aid of helping others along this path, here's a crib sheet I've found for readline shortcuts. I've been meaning to become more efficient in using bash and this might just be the push I need. http://www.bigsmoke.us/readline/shortcuts

Thanks. That's an excellent reference. I've been pointing people towards the relevant section in the readline or bash manuals, but this is much better.

I've honestly tried to use the man pages for bash before, they are unarguably complete but unfortunately difficult to get started with. The chances of me knowing ahead of time to either search first for "readline" followed "Commands for Moving" or read the full man page until I get to line 2957 is slim.

I have one cheat sheet at my desk, and it is this one.

Agreed. It's almost always worth investing time in learning your tools, and if you're like me the bash shell is your fundamental, most used tool.

I have to give Peteris Krumins credit for creating some great references like http://www.catonmat.net/blog/the-definitive-guide-to-bash-co... and http://www.catonmat.net/blog/bash-vi-editing-mode-cheat-shee... (or for the depraved, http://www.catonmat.net/blog/bash-emacs-editing-mode-cheat-s...)

set -o vi

I love my vim, but yuck on the shell.

> Next time you are using your shell, try typing ctrl-x e [...]. The shell will take what you've written on the command line thus far and paste it into the editor specified by $EDITOR.

I'm astonished this works in bash but not in zsh.

I have these in my .zshrc:

  autoload edit-command-line
  zle -N edit-command-line
  bindkey '^X^E' edit-command-line

And if you use set -o vi in .bashrc, or set editing-mode vi in .inputrc, then 'v' will do the same thing, e.g.

    $ blah blah[ESC]v
puts you in vim with the command line thus far.

I tried "set -o vi" and every v sent me into the editor. This was on the latest cygwin.

Well, you must have been command mode. Try pressing "i".

ctrl-x ctrl-e ... the e isn't naked as you suggested.

This is almost a useful resource, but there are many bashisms on the list! Its utility is kind of limited for those of us who use a different shell when they don't have some sort of standardized "this only works in bash" warning.

I have the opposite complaint: I'm using bash, but thinks like mtr aren't part of coreutils, so I think of them as just separate programs that happen to work at the command-line. I could just as easily list ttyter as a command-line 'tool' for tweeting from the command line.

I don't really have a solution to this, because at the end of the day, the goal is to do more things at the command line, but it'd be nice to have a way to distinguish between features of the shell, features of the OS, and non-OS programs that have command-line interfaces. Even if I'm interested in all three, it's nice to know that 'sudo !!' can be expected to work machines than mtr, for example.

mtr is pretty awesome though, you should install it and give it a try.

Autojump rocks! Currently I am using [fasd](https://github.com/clvv/fasd), which is inspired by Autojump but works for stuff other than cd.

I'm using rupa/j. This looks way featureful. Thanks for the link!

I love the autojump, but it's not exactly using a built-in *nix tool like most of these are. Would love to see more people open their eyes to how awesome autojump really is. Using cd to change directories is so broken.

On win7 I found forfiles command the other day that allows me to do a dir with a date restriction. By using the > redirect to output to file I got a list of files that changed in a certain time.


This is a related commandline script that allows you to search commandlinefu.com


Use this to help remember them: alias fu='curl -s http://www.commandlinefu.com/commands/browse/sort-by-votes/p... | grep -vE "^$|^#"'

Put it in your .bash_profile file in your home directory on OSX, or your .bashrc file on Linux.

Simply type 'fu' on the command line to jog your memory!

loved all the commands...specially "python -m SimpleHTTPServer"

alias pyserv="python -m SimpleHTTPServer"


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