5 ms·
The most useful thing I took away from this was not 'piping cats' but instead the interesting syntax for creating multiple directories in one go: ~ $ mkdir -
by aarongough 17y ago
The most useful thing I took away from this was not 'piping cats' but instead the interesting syntax for creating multiple directories in one go:
~ $ mkdir -p tmp/a/b/c
~ $ mkdir -p project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat/a}
- jerf 17y agoIt should be pointed out, since the article does not, that that is merely one example of shell expansion that can be used anywhere. It is not a mkdir feature. $ echo project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat/a} project/lib/ext project/bin project/src project/doc/html project/doc/info project/doc/pdf project/demo/stat/a (I added a linefeed to prevent wrapping.)
- aarongough 17y agoHuh, I'm definitely going to have to play with that! I only drop into a shell at most for 20 minutes a day at the moment, so a lot of the really neat time-saving trick simply don't stick in my head due to disuse...
- jerf 17y agoShells are one of those things that I find you should basically just plan on reading the man page every couple of months. Every time you do, you are virtually sure to discover something useful you'd swear you never saw before, even though you're pretty sure it's the exact same man page as before....
- tsuraan 17y agoAnother fun thing to do is use an empty entry, like mv .xinitrc{,.bak} or, if you have some stuff mounted under another mountpoint, such as when installing gentoo: umount /mnt/gentoo/{proc,dev,boot,} That empty entry expands to the base path, which can be a nice shortcut.
- silentbicycle 17y agoIt works in makefiles, too. (100% sure about BSD make, pretty sure about GNU make and others.)
- danudey 17y agoMy favourite use is when installing packages using package managers, especially when I need the dev packages. Old fink example: sudo fink install lib{png,jpeg,ssl,whatever}{,-{dev,shlibs}} which expands to: sudo fink install libpng libpng-dev libpng-shlibs libjpeg libjpeg-dev libjpeg-shlibs libssl libssl-dev libssl-shlibs libwhatever libwhatever-dev libwhatever-shlibs
- jrockway 17y agoBrilliant. I am ashamed to admit that I usually say "apt-get install libfoo.*", wait for the downloads to start, hit Control-c, and then cut-n-paste the package names I actually want onto the command-line. It sounds bad when I type it out, but it's really not the most horrible thing ever. But your way is definitely like 83x better.
- yason 17y agoIf you don't know the exact package names, Ubuntu happily auto-completes apt-get and aptitude on package names. So I would just type "aptitude install libfoo" and hit tab a couple of times to see what libfoos can I install.
- jedbrown 17y agoOr `M-*` to expand all the completions and then, if necessary, delete the ones you didn't want. Beats typing the extensions.
- yason 17y agoThis is golden, I didn't know that. A perfect example of the infinite features that can be found in bash manual page. I've been using bash since the early 90's and I've written lots of non-trivial programs in bash, and I know a lot many other people don't know and yet I had somehow managed to miss this pearl.
- protomyth 17y agolet's remember the the -p option is cool, but could cause pain if you mis-type one of the directories. for example: $ cd $ ls tmp - some files lists - $ mkdir -p tmm/a/b/c oops (remember your esc key)
- nagrom 17y agoWhy would this cause you any more pain than normal? You can just remove that chain with rm -r, surely?
- nitrogen 17y agormdir -p might be a bit safer, but it can get greedy and remove all the way up to root if you specify an absolute path.
- protomyth 17y agonormally you would get an error on the first mkdir, but you could be tired and just using your history and changing the commands and realize a little late you did a lot of stuff somewhere you shouldn't. I had a bad night once with this (still use the -p anyway, but...).