How to create each directory tar in a directory and save to different localtion

tar multiple directories
tar exclude directory
tar options
tar extract specific file to directory
tar multiple files
tar write to directory
untar all files in a directory
output folder tar

I have multiple directory in /home/ path and i want to make script to make .tar for each folder and save into another location.

After googling what i have found is:

find /home/ -type d -maxdepth 1 -mindepth 1 -exec tar cvf {}.tar {}  \;

but my problem is this is creating .tar files in /home and after that i have to move them to another location which is taking long time.

what i want is, tar file should be create in another location not in /home/ directory.

Thanks: Akash

This simple script worked for me.

DW=`date +%a`
DM=`date +%d`

cd /home/
for file in *;
tar -czvf /databackup_Allin/$DW/home/$file.tar.gz $file;

How to create tar archive in a different directory?, The easy way, if you don't particularly need to use -C to tell tar to change to some other directory, is to simply specify the full path to the archive on the command  The tar utility is one of the utilities that you can use to create a backup on a Linux system. It includes many options that one can use to specify the task to achieve. One thing to understand is that you can extract tar files to a different or specific directory, not necessarily the current working directory.

have you tried specifying the directory like this?

find /home/ -type d -maxdepth 1 -mindepth 1 -exec tar cvf \path\to\directory\{}.tar {} \;

create tar with multiple directories and file locations, I want to make a tar file so that it copies files and folders with the location structure. When I untar to another location, all the files will be copied to their respective  The path to the backup location (destination) is not stored in the tar file at all. But the path to the source files is stored in the tar file by default relative to where the tar command was issued from unless absolute path is given.

How to Extract Tar Files to Specific or Different Directory in Linux, Extract Linux Tar Files Different or New Directory Let me start by creating the /​tmp/my_article directory using the command View all Posts. The script that you wrote will not work if you have some spaces in a directory name, because the name will be split, and also it will tar files if they exist on this level. You can use this command to list directories not recursively: find . -maxdepth 1 -mindepth 1 -type d and this one to perform a tar on each one:

How to compress and extract files using tar command in Linux , The tar command in Linux is often used to create .tar.gz or .tgz archive files. It will also compress every other directory inside a directory you in the current directory and you want to save it to a file named archive.tar.gz , you  Then you can be in whatever directory you prefer to create the directory structure that you want inside the archive. The following will create the archive /var/www/file.tar.gz and put file1 from the current directory (whatever that happens to be) in it, with no in-archive path information.

How do I Compress a Whole Linux or UNIX Directory?, Explains how to use tar command to compress a whole directory It is useful to backup files, email all files, or even to send software you have created to friends. It is hard to keep the site running and producing new content when so Without knowing each folder name, can I zip the directory using your  The tar command in Linux is often used to create .tar.gz or .tgz archive files. This command has a large number of options, but you just need to remember a few letters to quickly create archives with tar. The tar command can extract the resulting archives, too. Compress an Entire Directory or a Single File

How To Extract a Tar Files To a Different Directory on a Linux/Unix , How to Extract Tar Files to Specific or Different Directory in Linux directory called /tmp/data. First, you have to create the directory manually, enter: Extract .​tar.gz/.tgz archive to specific folder. To extract All rights reserved. This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter. For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration.

  • I tried your suggestion but getting below error: tar: /databackup_Allin/Tue/home//home/akash.tar: Cannot open: No such file or directory tar: Error is not recoverable: exiting now