Skip to content

Instantly share code, notes, and snippets.

@yhshin11
Last active July 12, 2016 22:55
Show Gist options
  • Save yhshin11/ae25c48ac0d2588f385eccec667cb999 to your computer and use it in GitHub Desktop.
Save yhshin11/ae25c48ac0d2588f385eccec667cb999 to your computer and use it in GitHub Desktop.

Ctrl+r

Start backwards search through command history for all commands containing "keyword". Works in bash, and even in ROOT prompt!

echo -e "\a"

Beeps, or rings visual bell, etc. If your terminal is set up to transmit visual bells, beeps, etc, it can alert you when a long command finishes. For example: ./run_long_command.sh; echo -e "\a"

Emacs style bindings on the command line (bash, tcsh, ROOT prompt)

You can use many emacs style bindings to delete a word forwards or backwards (Alt+Backspace or Alt+d), kill line (Ctrl-k), and even undo (Ctrl+_). Other useful bindings: Alt-f/Alt-b to move forwards/backwards by single word Ctrl-a/Ctrl-e to move to start/end of line

<command> &

Runs command in the background, so you can do other stuff.

Note: If <command> produces command line output, it will show up on your prompt, which makes it hard to see what's going on. To fix this, you can direct both the stdout and stderr of a command to a file instead. In bash: <command> > log.txt 2>&1 Doing <command> >> log.txt 2>&1 appends to file instead. You should not have multiple processes writing to the same file at the same time though.

Ctrl-z

Suspends current process. You can bring it back to the ForeGround by typing fg. This is very useful for having an editor session running while you do other things in the terminal. You can also put the process in the BackGround by typing bg, which is just like doing <command> & but you can do it after you've already started running the command. If you have more than one suspended processes, you can do jobs to find out what they are, then do fg %<jobnumber> to bring up a specific one.

<command1>; <command2> && <command3>;

You can use semi-colons (;) to chain commands together. Each command will run after the previous one has completed. You can use double ampersand (&&) to chain commands, with each command ONLY executing if the previous command did not return an error. For example: In make && ./main, ./main will only run if the make command was successful.

Note: A command is considered to have completed error-free, if it returns exit code 0. Any other return code is considered an error. If your compile commands are in a script as in the example above, you have to make sure that your script returns a non-zero exit code, if compilation fails.

Wildcard expansion

Use # to pass multiple files with similar names to a command. For example, rm *.txt removes all files in the current directory with the file type ".txt". cp dir1/* dir2/ copies all files in dir1 to dir2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment