Jump to content

Bash script to "move" all files/directory in the current directory to a rar achive


FunkyBuddha

Recommended Posts

Posted

If you haven't installed "rar," you can use the command "apt install rar" to install it. This script will archive and delete all the files and directories in the current directory. You need to pass the archive name to the script.

 

Bash script:

Quote

winrar() {
    if [[ -z "$1" ]]; then
        echo " "
        echo Missing Parm:
        echo -e '\t'parm1=archive_name
        exit
    fi
    echo start - `date` > /var/log/winrar.log
    find . -maxdepth 1 -mindepth 1 -type d | sort > /path/to/dirar.txt
    find . -maxdepth 1 -mindepth 1 -type f | grep -v $1.rar | grep -v nohup | sort > /path/to/filrar.txt
    IFS=$'\n'       # make newlines the only separator
    for i in $(cat /path/to/dirar.txt)
    do
        local f_nm=${i}
        rar a -df -r -md512m $1 "$f_nm" >> /path/to/winrar.txt
    done
    for i in $(cat /path/to/filrar.txt)
    do
        local f_nm=${i}
        rar a -df -md512m $1 "$f_nm" >> /path/to/winrar.txt
    done
    wc -l /path/to/dirar.txt /path/to/filrar.txt >> /var/log/winrar.log
    echo end - `date` >> /var/log/winrar.log
}

 

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...