3 ms·
I didn't know this one, and glad I do now! Is it possible that the other one I wish existed is already commonplace? I'd like to have an arg that cd's to a direc
by spenuke 13y ago
I didn't know this one, and glad I do now! Is it possible that the other one I wish existed is already commonplace? I'd like to have an arg that cd's to a directory automatically after mkdir'ing it... or mv'ing a file to a directory.
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.
- pbhjpbhj 13y agoYou could have scripted it faster than doing that comment ... 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.
- octo_t 13y agofunction take_dir { mkdir -p "$1"; cd "$1" ; }; alias take="take_dir"
- barrkel 13y agoI call my version of this function 'enter'.
- jlgaddis 13y agoI typically use: $ 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
- roryokane 13y agoI use the version at http://onethingwell.org/post/586977440/mkcd-improved http://onethingwell.org/post/586977440/mkcd-improved, called `mkcd`. # 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-improved
- vram22 13y ago$_ in bash means the last argument of the previous command. So: mkdir 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.