tar bz2 a directory — a .bashrc function 

To make compression of directories into .tar.bz2 archives quick and simple, put the following function in your .bashrc file:

tar_bz2_dir()
{ # ©2007 dsplabs.com.au
    if [ "$1" != "" ]; then
        FOLDER_IN=`echo $1 |sed -e 's/\/$//'`;
        FILE_OUT="$FOLDER_IN.tar.bz2";
        FOLDER_IN="$FOLDER_IN/";
        echo "Compressing $FOLDER_IN into $FILE_OUT…";
        echo "tar cjf $FILE_OUT $FOLDER_IN";
        tar cjf "$FILE_OUT" "$FOLDER_IN";
        echo "Done.";
    fi
}

Then, to compress directory dir/ into dir.tar.bz2 archive type:

tar_bz2_dir dir/  # ©2007 dsplabs.com.au

The following will be displayed:

$ tar_bz2_dir dir/
Compressing dir/ into dir.tar.bz2...
tar cjf dir.tar.bz2 dir/
Done.

Did you find the above information useful and interesting? If so, please support this site by using the blog directory links at the bottom of this page. Thanks for your support!

If you have any Linux related problems or questions then please feel free to post them on our Linux Forums: http://linux.dsplabs.com.au/forums.




VPS Hosting Referral Code DZZCC3

Add me to Technorati Favorites Vote for me on Blog Catalog

One Response to “tar bz2 a directory — a .bashrc function”

  1. maxgames.me Says:

    Thanks. I looking them

Leave a Reply