Skip to content

Instantly share code, notes, and snippets.

@simonc
Last active December 28, 2015 23:19
Show Gist options
  • Save simonc/7578108 to your computer and use it in GitHub Desktop.
Save simonc/7578108 to your computer and use it in GitHub Desktop.
Shell tips

Here are some shell/term tips I use on a day to day basis.

Escape-dot

When typing a command, using esc-. inserts the last argument of the previous command.

$ ls aaa.txt bbb.txt ccc.txt
...
$ ls <esc-.>
$ ls ccc.txt

You can even type esc-. several times and go back from command to command.

$ ls aaa.txt
$ ls bbb.txt
$ ls ccc.txt
...
$ ls <esc-.>
$ ls ccc.txt<esc-.>
$ ls bbb.txt<esc-.>
$ ls aaa.txt

Using a command output as a file

If you need to use the output of a command as file you can use <(command). Let's say we have a command that needs a file and does not take standard input.

$ some_command some_file.txt

We would like to pass it the output of ls. We can put the output of ls in a file and then pass that file to some_command but sometimes it's not very practical to do so. Using <(...) can save the day.

$ some_command <(ls)

You can even do a diff of two command outputs that way.

$ diff <(ls -1 /some/directory) <(ls -1 /some/other/directory)

Go back to previous directory

Using cd - you can go back to the previous directory.

~/somewhere $ cd ~/somewhere-else
~/somewhere-else $ cd -
~/somewhere $ cd -
~/somewhere-else $

Kill a frozen SSH session

Sometimes a SSH session can freeze and nothing more can be done, except... there is. Use ↵~. (enter, tilde, dot) to kill the frozen session.

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