3 ms·
Also handy for your .zshrc or .bashrc: mkcd () { mkdir -p $1 cd $1 } Also, moving a tarball before unpacking it is indeed brain-damaged, but,
by dreish 19y ago
Also handy for your .zshrc or .bashrc:
mkcd () {
mkdir -p $1
cd $1
}
Also, moving a tarball before unpacking it is indeed brain-damaged, but,
cd /target/directory
tar xzvf /source/dir/sourcefile.tar.gz
works for me. I don't know why you would need -C, though it saves five keystrokes ("cd -") if you didn't want to end up in the target directory for some reason.
Listing 6 looks like a bad idea; it either goes to or makes a directory, depending on whether it existed. I realize he's just illustrating the use of "||", but don't copy the command. Usually you would want pwd to be an invariant. It looks like he really wanted to write:
[ -d tmp/a/b/c ] || mkdir -p tmp/a/b/c
GNU mkdir -p will not complain if the target directory already existed, so you could just run
mkdir -p tmp/a/b/c
but then that doesn't illustrate the use of "||".
Overuse of 'cat' is a hard habit to break for some reason, especially since it's so harmless. I found it useful as an intermediate step that Z shell is more flexible than other shells about where to put redirection, so:
< foo.txt | wc -l
works in zsh instead of cat foo.txt (to get line count without a filename, which is useful in shell scripts and long one-liners), and seeing that, I would see more obviously that the pipeline is unnecessary.
- foonamefoo 19y agoYour mkcd script breaks for directories with spaces in their names; you've got to put $1 in quotes. Also, never heard of a tar bomb? =)
- dreish 19y agoIt works in Z shell, and breaks in Bash -- thanks, I didn't realize that. I don't see how -C protects against a tar bomb. Generally when I untar a tarball from a new source whose packaging habits I'm not familiar with, I tar tzvf it first.
- foonamefoo 19y ago-C protects if you create an empty directory and then use it as the argument to -C; saves you a command line cd and a cd back to where you were, though it doesn't save much if you use your mkcd command to make the directory. (I'm talking about GNU tar where any leading slash(es?) is stripped off of the path of any files in the tar (and .. is disabled))