How do I tar a directory without retaining the directory structure?

Use the --directory option:

 tar czf ~/backup.tgz --directory=/home/username/drupal/sites/default files 

cd /home/username/drupal/sites/default/files
tar czf ~/backup.tgz *

Create a tar archive

tar czf  $sourcedir/$backup_dir.tar --directory=$sourcedir WEB-INF en

Un-tar files on a local machine

tar -xvf $deploydir/med365/$backup_dir.tar -C $deploydir/med365/

Upload to a server

scp -r -i $privatekey $sourcedir/$backup_dir.tar $server:$deploydir/med365/
echo "File uploaded.. deployment folders"

Un-tar on server

ssh -i $privatekey $server tar -xvf $deploydir/med365/$backup_dir.tar -C $deploydir/med365/

Hi I've a better solution when enter in the specified directory it's impossible (Makefiles,etc)

tar -cjvf files.tar.bz2 -C directory/contents/to/be/compressed .

Do not forget the dot (.) at the end !!

Tags:

Linux

Unix

Gnu

Tar