tar -cf archive.tar foo bar #Create „archive.tar“ with the files „foo“ and „bar“ tar -czf archive.tar.gz foo bar #Create „archive.tar.gz“ with the files „foo“ and „bar“ with higher compression (gzip) tar -tvf archive.tar #Detailed listing of archive „archive.tar“ (verbose) tar -xf archive.tar #Extracting all data of archive “archive.tar” tar -xzf archive.tar path/to/folder #Extracting just "path/to/folder" (particular folder) from archive “archive.tar” tar --extract --file={tarball.tar} {file} #Extract a directory called file from tarball.tar tar --extract --file=cbz.tar css #Extract a directory called css from cbz.tar tar -xf cbz.tar --wildcards --no-anchored '*.php' #To extract all php files tar -cvf /dev/st0 /home #Backup of /home to taperecoreder st0 tar -cvf /backup/home/tmade.tar /home/tmade #backup of /home/tmade to /backup/home/tmade.tar tar -cvzf /backup/home/tmade.tar.gz /home/tmade #compressed backup of /home/tmade to /backup/home/tmade.tar.gz (cd /orignl/path tar -cf - . ) | (cd /dst/dir;tar -xvf - ) #tar pipe to copy files, alternate to "cp -Ra" tar -czvf /mnt/test.tgz --one-file-system / #stay on filesystem = /dev/, /proc , /sys and all other mountpoints (if there are) aren´t in the file tar -xzf bar.tar.gz -C /foo #Untar "bar.tar.gz" to "/foo/*" directory
-c creates the archive -v verbose -f the name of the archive to be created after the option f
View contents of archive:
tar -tvf /path/to/*.tar
Exclude files from backup: create a file called exclude.files and save line by line into it like:
/home/tmade/.bashrc #exclude .bashrc /home/tmade/test* #exclude all files starting with test
than save the backup:
tar -czv -X /home/tmade/excluded.files -f /backup/home/excluded/backup_exclude.tar.gz /home/tmade
Unpack:
tar -xvf /path/to/device #writes all files to current directory tar -xvf /dev/st0 #writes all files to current directory
Extract just one file
tar -xvf /path/to/*.tar -C /home/targetdirectory/filename
Only new created files and folders will be backuped.
First step: Make full backup
tar -cz -g /mnt/newroot/snapshot_file -f /mnt/newroot/full_backup.tar.gz /home
Second step: Make incremental backup
tar -cz -g /mnt/newroot/snapshot_file -f /mnt/newroot/backup_monday.tar.gz /home
Only files and folders with a newer timestamp will be backuped. Newly created empty folders won´t be backuped!
First step: Make full backup
tar –czvf /mnt/newroot/full_backup.tar.gz /home
Second step: Make differential backup
find /home –type f –newer /mnt/newroot/full_backup.tar.gz –print0 | tar ––null –czvf /mnt/newroot/backup_monday.tar.gz –T –
Note:
-print0 and --null ensure files with a spaces in their names are also archived -T determines that files piped to stdin are included in the archive
Compress:
gzip file.txt
In the above example command this would compress the file.txt file as file.txt.gz in the current directory.
Expand:
gunzip file.txt.gz
In the above example command it would extract the file.txt from file.txt.gz.