I\'m working on a backup script and want to tar up a file directory:
tar czf ~/backup.tgz /home/username/drupal/sites/default/files
This ta
cd /home/username/drupal/sites/default/files
tar czf ~/backup.tgz *
For me -C or --directory did not work, I use this
cd source/directory/or/file
tar -cvzf destination/packaged-app.tgz *.jar
# this will put your current directory to what it previously was
cd -
Use the --directory option:
tar czf ~/backup.tgz --directory=/home/username/drupal/sites/default files
tar czf $sourcedir/$backup_dir.tar --directory=$sourcedir WEB-INF en
tar -xvf $deploydir/med365/$backup_dir.tar -C $deploydir/med365/
scp -r -i $privatekey $sourcedir/$backup_dir.tar $server:$deploydir/med365/
echo "File uploaded.. deployment folders"
ssh -i $privatekey $server tar -xvf $deploydir/med365/$backup_dir.tar -C $deploydir/med365/
Kindly use the below command to generate tar file without directory structure
tar -C <directoryPath> -cvzf <Path of the tar.gz file> filename1 filename2... filename N
eg:
tar -C /home/project/files -cvzf /home/project/files/test.tar.gz text1.txt text2.txt
This worked for me:
gzip -dc "<your_file>.tgz" | tar x -C <location>