My script tars a folder in my /home/user directory and saves it all in a backup folder. However, when I open each of the tar.gz all of them have the directory /home/user and then the folders and files I wanted to compress.
My script:
#!/bin/bash
if [ ! -d ~/backup ]; then
mkdir ~/backup
fi
for i in `ls ~/folder`; do
echo "~/folder/$i"
if [ -d ~/folder/$i ]; then
tar -zcf ~/backup/$i.tar.gz ~/folder/$i
fi
done
What can I do to prevent /home/user to be saved?