The biggest advantage of this over the functions is that it is portable.
This will create the intermediate directories that do not exist. I did not know about this for a long time.
How often do you make a directory (or series of directories) and then change into it to do whatever? 99% of the time that is what I do. This BASH function 'md' will make the directory path then immediately change to the new directory. By using the 'mkdir -p' switch, the intermediate directories are created as well if they do not exist. Show Sample Output
In my example, the mount point is /media/mpdr1 and the FS is /dev/sdd1 /mountpoint-path = /media/mpdr1 filesystem=/dev/sdd1 Why this command ? Well, in fact, with some external devices I used to face some issues : during data transfer from the device to the internal drive, some errors occurred and the device was unmounted and remounted again in a different folder. In such situations, the command mountpoint gave a positive result even if the FS wasn't properly mounted, that's why I added the df part. And if the device is not properly mounted, the command tries to unmount, to create the folder (if it exists already it will also work) and finally mount the FS on the given mount point. Show Sample Output
Taken from: http://www.webmasterworld.com/forum40/1310.htm
create tree of dir's in one command
Not a discovery but a useful one nontheless.
In the above example date format is 'yyyymmdd'. For other possible formats see 'man date'.
This command can be also very convenient when aliased to some meaningful name:
alias mkdd='mkdir $(date +%Y%m%d)'
This Anti-TarBomb function makes it easy to unpack a .tar.gz without worrying about the possibility that it will "explode" in your current directory. I've usually always created a temporary folder in which I extracted the tarball first, but I got tired of having to reorganize the files afterwards. Just add this function to your .zshrc / .bashrc and use it like this;
atb arch1.tar.gz
and it will create a folder for the extracted files, if they aren't already in a single folder.
This only works for .tar.gz, but it's very easy to edit the function to suit your needs, if you want to extract .tgz, .tar.bz2 or just .tar.
More info about tarbombs at http://www.linfo.org/tarbomb.html
Tested in zsh and bash.
UPDATE: This function works for .tar.gz, .tar.bz2, .tgz, .tbz and .tar in zsh (not working in bash):
atb() { l=$(tar tf $1); if [ $(echo "$l" | wc -l) -eq $(echo "$l" | grep $(echo "$l" | head -n1) | wc -l) ]; then tar xf $1; else mkdir ${1%.t(ar.gz||ar.bz2||gz||bz||ar)} && tar xf $1 -C ${1%.t(ar.gz||ar.bz2||gz||bz||ar)}; fi ;}
UPDATE2: From the comments; bepaald came with a variant that works for .tar.gz, .tar.bz2, .tgz, .tbz and .tar in bash:
atb() {shopt -s extglob ; l=$(tar tf $1); if [ $(echo "$l" | wc -l) -eq $(echo "$l" | grep $(echo "$l" | head -n1) | wc -l) ]; then tar xf $1; else mkdir ${1%.t@(ar.gz|ar.bz2|gz|bz|ar)} && tar xf $1 -C ${1%.t@(ar.gz|ar.bz2|gz|bz|ar)}; fi ; shopt -u extglob}
Show Sample Output
This will mv all your mp3 files in the current directory to $ARTIST/$ALBUM/$NAME.mp3 Make sure not to use sudo - as some weird things can happen if the mp3 file doesn't have id3 tags.
Very basic, but who knows.. mkdir !$ should work too, only uses 'the last' argument. !-2 executes cd Desktop/Notes again. More tips in 'man history' Show Sample Output
Takes all the .3gp files in the directory, rotates them by 90 degrees, and saves them in the lossless ffv1 encoding. If this rotates in the wrong direction, you may want transponse=1 Re-encoding to ffv1 may result in a significant increase in file size, as it is a lossless format. Other applications may not recognize ffv1 if they don't use ffmpeg code. "huffyuv" might be another option for lossless saving of your transformations. The audio may be re-encoded as well, if the encoding used by your 3gp file doesn't work in a avi container.
Add the functions to the .bashrc to make it work Example: First go to the iso file directory and type: ---------------------------------------------------------------------------------------------------- user@box:~$ miso file.iso ---------------------------------------------------------------------------------------------------- It will put you into a temporary mounting point directory (ISO_CD) and will show the files You can umount the iso file whatever the directory you are ---------------------------------------------------------------------------------------------------- user@box:~/ISO_CD$ uiso ---------------------------------------------------------------------------------------------------- It wil umount the iso file and remove the temporary directory in your home
I find that I create a directory and then cd into that directory quite often. I found this little function on the internets somewhere and thought I'd share it. Just copy-paste it into you ~/.bash_profile and then `source ~/.bash_profile`. Show Sample Output
With this form you dont need to cut out target directory using grep/sed/etc.
Periodically run the one-liner above if/when there are significant changes to the files in /usr/
= Before rebooting, add following to /etc/fstab : =
/squashed/usr/usr.sfs /squashed/usr/ro squashfs loop,ro 0 0
usr /usr aufs udba=reval,br:/squashed/usr/rw:/squashed/usr/ro 0 0
No need to delete original /usr/ ! (unless you don't care about recovery). Also AuFS does not work with XFS
Creates one letter folders in the current directory and moves files with corresponding initial in the folder.
Instead of typing separate commands to create various subfolders, we can create multiple subfolders by listing them between brackets and separated by commas. Show Sample Output
Create a directory named with the current date in ISO 8601 format (yyyy-mm-dd). Useful for storing backups by date. The --iso switch may only work with GNU date, can use format string argument for other date versions.
Copies a dir structure without the files in it. Show Sample Output
Nice reading in the morning on the way to work, but sadly the .tar.gz for the whole issue 66 is not on phrack's website yet. So use wget to download.
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for: