Other Shell Features

Speeding up your use of the shell

Changing directories

  • Problem:You find yourself moving frequently between two or more directories cd’ing here, then there, and then back again. The directories never seem to be close by, and you’re tired of always typing long pathnames.
    • Use pushd, popd
    • Stack LIFO
      • dirs -v will show what is in stack
    • If you use pushd without specifying a directory, it swaps the top item on the stack with the next one down, so that you can alternate between two directories using repeated pushd commands with no arguments.

Command quick subsitution

  • Assume you typed a command like ls -lat, but want to go back and edit it. Obviously you can hit the up arrow and edit, but you could also ^lat^-l -a -h^ to find and replace.
    • only works with immediate previous command
    • probably only useful with real long commands

Reusing arguments

  • Use !$ to indicate the last argument of the preceding command. Use !:1 for the first argument on the command line, !:2 for the second, and so on.

      cat /tmp/cows.txt
      vi !$