How to create a TAR File in a Custom Destination Directory?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to create a TAR File in a Custom Destination Directory?
# 1  
Old 04-02-2014
How to create a TAR File in a Custom Destination Directory?

I want to create the tarzip file into a destination directory, i am in /var/sftp/home/archive/rquadri directory and i am using below command. However it is creating the file in the /var/sftp/home/archive/rquadri directory itself instead of /tmp, may i please know how do i resolve this.
Code:
tar -cvzf FCBTEXAS_20130930_v2.xml.tgz -C /tmp /var/sftp/home/archive/rquadri/FCBTEXAS_20130930_v2.xml

# 2  
Old 04-02-2014
try:
Code:
tar -cvzf /tmp/FCBTEXAS_20130930_v2.xml.tgz -C /tmp /var/sftp/home/archive/rquadri/FCBTEXAS_20130930_v2.xml

You may not want the -C option.
# 3  
Old 04-02-2014
As an after thought: /tmp may not be a safe pace to create huge tar files. Some systems map /tmp to RAM rather than to disk. You seem to be using a linux-like version of tar so this may be applicable to your situation.
# 4  
Old 04-02-2014
-C applies to reading input files. This doesn't matter since you gave it an absolute path for those, but if you gave it a relative one the results could have been far different.
# 5  
Old 04-02-2014
Quote:
Originally Posted by jim mcnamara
try:
Code:
tar -cvzf /tmp/FCBTEXAS_20130930_v2.xml.tgz -C /tmp /var/sftp/home/archive/rquadri/FCBTEXAS_20130930_v2.xml

You may not want the -C option.
If i do it your way with out using the -C /tmp, i see 2 issues.

1) After creating the tar file i did tar -zxvf FCBTEXAS_20130930_v2.xml.tgz, it is creating the subdirectories /var/sftp/home/archive/rquadri which i don't want to create, i just want to unzip & untar the file, in which ever directory i am in.

2) why is it removing leading / from member names, is this an error?
Code:
tar: Removing leading `/' from member names
/var/sftp/home/archive/rquadri/FCBTEXAS_20130930_v2.xml

Thank you.
# 6  
Old 04-02-2014
Quote:
Originally Posted by Ariean
If i do it your way with out using the -C /tmp, i see 2 issues.

1) After creating the tar file i did tar -zxvf FCBTEXAS_20130930_v2.xml.tgz, it is creating the subdirectories /var/sftp/home/archive/rquadri which i don't want to create, i just want to unzip & untar the file, in which ever directory i am in.
It does that either way. This is normal behavior.

Quote:
2) why is it removing leading / from member names, is this an error?
This is standard behavior for GNU tar. It assumes that you don't necessarily want to overwrite /var/sftp/home/archive/rquadri/filename every time you extract the tar -- you want to extract it in the current folder, or something given by -C. If it stored the absolute path, that'd override everything, so it strips the first / off.

I believe this is what you want:

Code:
tar -cvzf /tmp/FCBTEXAS_20130930_v2.xml.tgz -C /var/sftp/home/archive/rquadri FCBTEXAS_20130930_v2.xml

This tells it to chdir into /var/sftp/home/archive/rquadri before doing anything. It will still create the tar in /tmp/ because that was given an absolute path.
This User Gave Thanks to Corona688 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script cannot create directory and move the file to that directory

I have a script, which is checking if file exists and move it to another directory if then mkdir -p ${LOCL_FILES_DIR}/cool_${Today}/monthly mv report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv ${LOCL_FILES_DIR}/cool_${Today}/monthly ... (9 Replies)
Discussion started by: digioleg54
9 Replies

2. UNIX for Beginners Questions & Answers

How do I custom sort the files in a directory using the filenames in a text file.?

Hi all, (5 Replies)
Discussion started by: KMusunuru
5 Replies

3. UNIX for Dummies Questions & Answers

How to move gz files from one source directory to destination directory?

Hi All, Daily i am doing the house keeping in one of my server and manually moving the files which were older than 90 days and moving to destination folder. using the find command . Could you please assist me how to put the automation using the shell script . ... (11 Replies)
Discussion started by: venkat918
11 Replies

4. AIX

Making Tar of directory and tar file is going to be placed

Quick question, is it possible to make a Tar of completely directory and placing the tar file in it (will this cause even the tar file to tarred ?) sample: /opt/freeware/bin/tar -cvf - /oracle | gzip > /oracle/backup.tgz will the tar file backup.tgz also include backup.tgz ? i tried... (5 Replies)
Discussion started by: filosophizer
5 Replies

5. Shell Programming and Scripting

Command / Script to create touch file in destination server

Hello Team, Is there any Linux command / script available so that, I could create a simple 0 byte file in destination server by issuing the command from source server. If yes, Could you please let me know the possible solutions. in other words I just want to create a touch file in my home... (1 Reply)
Discussion started by: madhuraju
1 Replies

6. Shell Programming and Scripting

Create tar file

Following are the list of files available in the dataout directory a1.txt.gz a2.txt.gz b3.txt.gzStep 1: now the tar file needs to be created as follows. tar -cvf ab.tar *.gzAll the files with extn .gzg has to be bundled in the tar file. Once the tar file is created, the files which are... (9 Replies)
Discussion started by: kmanivan82
9 Replies

7. UNIX for Advanced & Expert Users

Create corrupted *.tar.gz file ?

Hello. I`m writing a bash script who archive log files and send them to backup server. I need some kind of checking mechanism for *.tar.gz files. I found something like: gunzip -t file.tar.gz //Not output from it. And for tar: tar tf file.tar.gz //Only lists archive 1.) I need make a... (3 Replies)
Discussion started by: jabalv
3 Replies

8. UNIX for Dummies Questions & Answers

move all 2008 year's file to destination directory

I am trying to move file created/modified in 2008 year to <new directory>. But trapped badly in Xargs {}. Looks like mv is not getting destination file properly. It assumes source file s to be destination directory n gives me erroir. "Target must be a directory" Run- #/home/mktrisk: find... (4 Replies)
Discussion started by: kedar.mehta
4 Replies

9. UNIX for Dummies Questions & Answers

create tar archive without preserving directory structure?

I am adding some individual files to a tar archive and would like them to be added to the archive without any directory hierarchy, even though the files themselves exist in levels of hierarchy. Unfortunately, tar seems to always preserve the directory hierarchy when it adds the files. Here is... (2 Replies)
Discussion started by: Special_K
2 Replies

10. UNIX for Dummies Questions & Answers

script to create tar file

hello, im a newbie in unix scripting. can someone pls send me a sample script that will tar files in the folders of a specific directory, but will exclude specific files, and afterwards, will ftp the tar into another server. for example: in this directory, pshrprod:/opt/psoft/weblogic/818sp9_80... (2 Replies)
Discussion started by: ajrandrup
2 Replies
Login or Register to Ask a Question