Difference between revisions of "SoutHACKton:TipsAndTricks/Unix Shells"

From SoMakeIt
Jump to: navigation, search
(zsh only)
(Tab completion.)
 
Line 1: Line 1:
 +
== Tab Completion ==
 +
 +
Most shells support tab completion; some more than others. When typing a command or a path, always use tab to complete - it helps to protect against typos and make it more obvious that you've made a mistake before you type too much further.
 +
 +
Pressing tab twice will (generally) show you a list of potential completions.
 +
 
== Pushd and Popd ==
 
== Pushd and Popd ==
 
You can use the pushd command to save your current directory on a stack and cd to a new location. Then, when you want to go back to you original location you just run popd to remove the directory from the stack and cd to it:
 
You can use the pushd command to save your current directory on a stack and cd to a new location. Then, when you want to go back to you original location you just run popd to remove the directory from the stack and cd to it:

Latest revision as of 16:32, 14 April 2013

[edit] Tab Completion

Most shells support tab completion; some more than others. When typing a command or a path, always use tab to complete - it helps to protect against typos and make it more obvious that you've made a mistake before you type too much further.

Pressing tab twice will (generally) show you a list of potential completions.

[edit] Pushd and Popd

You can use the pushd command to save your current directory on a stack and cd to a new location. Then, when you want to go back to you original location you just run popd to remove the directory from the stack and cd to it:

# pwd
/home/user/some/long/path
# pushd /home/user/another/long/path
# pwd
/home/user/another/long/path
<do some work in the new location>
# pushd /tmp/somewhere/else
# pwd
/tmp/somewhere/else
# popd
# pwd
/home/user/another/long/path
# popd
# pwd
/home/user/some/long/path

You can alias pushd to cd to make it easy to move back through the paths you have been by adding the following line to your ~/.bashrc file:

alias cd=pushd

popd will now behave similar to the back button in gui file browsers:

# pwd
/home/user
# cd /home/user/some
# cd directory
# cd ../other/directory
# pwd
/home/user/some/other/directory
# popd
# pwd
/home/user/directory
# popd
# pwd
/home/user

Note that this is already how zsh behaves, so there is no need for the alias in zsh.

[edit] cd -

cd - takes you to the last directory you where in:

# pwd
/home/user/some/long/path
# cd /home/user/another/long/path
# cd -
# pwd
/home/user/some/long/path
# cd -
# pwd
/home/user/another/long/path
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox
Donate