up () {
if [[ $# -eq 1 && "$1" -gt 0 ]] ; then
local i d
for (( i = 0; i < $1; i++ )) ; do d="../$d" ; done
cd $d
else
echo "Usage: up N"
fi
}Looks like I wrote the tab-completion script on my work machine. I don't have access to it right now, but if I remember when I do have access I'll pastebin that as well.
Note it's the only tab completion script I've written, and it's probably a hack :P
cd .. # to go one level up
cd ... # to go two levels up (note: 3 dots, not 4, makes sense when you think of "cd ." and "cd ..")
# and so on.
Something like:
mkdir foo -go and mv foo ~/bar -go
... Probably simple enough to script, but I guess I'm too lazy at the moment.
Or, you could just
bash$ mkdir -p /some/dir/to/make
bash$ cd !$
Bang (!) is a history lookup with lots of variation in use. It probably works in other *nix shells too.Look under "event designators" in "man bash" for more info.
$ mkdir foo
$ cd !$
Not quite what you're asking for but it can certainly save some keystrokes -- especially if you're doing something like: $ mkdir -p foo/bar/baz/whatever # mkdir, cd into it
mkcd () {
mkdir -p "$*"
cd "$*"
}
Just copy and paste that at the end of your `.bashrc` or `.zshrc` file. You may also want to include this comment above it so you know why it’s written like that: # from http://onethingwell.org/post/586977440/mkcd-improvedmkdir some/long/path/to/a/dir cd $_
mv foo some/long/path/bar cd $_
both work for what you want, and the extra keystrokes are so few that it hardly matters. The $_ is not specific to those two commands, so works for others as well, and is typically very useful because command sequences often tend to need the last argument of the previous command in the next command; un-tar-ing a .tar file and then going to the extracted directory is another example.
i.e.:
cd /var/log
cd /etc/ssh
cd /home/samstave/Downloads
cd -- (takes me back to /var/log/)
pushd /var/log
pushd /etc/ssh
pushd /home/samstave/Downloads
popd;
!! (takes me back to /var/log/)
You could alias cd to pushd and cd- to popd...