Move files while making a tar


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Move files while making a tar
# 1  
Old 05-24-2012
Move files while making a tar

I have the following folder structure

code/f1/
code/lib/t1
code/lib/t2
code/lib/t3
code/lib/t3
code/lib_1/t1
code/exc

I would like to create a tar with a folder structure below and I can use the following tar command
f1
lib/t1
lib/t2
lib/t3

tar -cvf code.tar -C code f1 lib --exclude exc lib_1

But in some cases I need to replace lib/t1 with lib_1/t1 and keep the folder structure lib/t1.
I would like to know Is there a way in tar command I can move/replace an existing file in a tar with a different file but keep the existing folder structure?
or Add a file to a tar with a specific folder path?
or Move files during tar?

Thanks for the help in advance!
# 2  
Old 05-24-2012
Do those subfolders contain any symbolic links? If not, what I would do is create a directory skeleton to arrange however I please, with symlinks to the actual targets, then tar it up with -h (to follow symlinks, instead of storing them as symlinks).
# 3  
Old 05-24-2012
i.e.
Code:
mkdir -p tardir/lib
# assumes code is in the CURRENT directory.
# One way to make t1
# ln -s ../../code/lib_1/t1 tardir/lib/t1

# Other way
ln -s ../../code/lib/t1 tardir/lib/t1

# the rest
ln -s ../../code/lib/t2 tardir/lib/t2
ln -s ../../code/lib/t3 tardir/lib/t3
ln -s ../code/exc tardir/exc

tar -hcf /path/to/file.tar -C tardir .

This User Gave Thanks to Corona688 For This Post:
# 4  
Old 05-25-2012
Thanks Corona688!

ln -s ../../code/lib_1/t1 tardir/lib/t1
Would you please explain me why I have to go two level back even though code is in my present working directory?
ln -s ../code/exc tardir/exc
And I only need to go back one level to include a directory?
# 5  
Old 05-25-2012
Quote:
Originally Posted by alpboys
Thanks Corona688!

ln -s ../../code/lib_1/t1 tardir/lib/t1
Would you please explain me why I have to go two level back even though code is in my present working directory?
Because the path is relative to the link's folder, not the current one. If the link you're creating is buried two folders deep, the base path you're trying to reach from it is two folders back out.

You could just use /absolute/paths to avoid all that doublethink. In fact, that's probably a better idea now that I think about it.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Tar - pre-checking before making the Tar file

Coming from this thread, just wondering if there is an option to check if the Tar of the files/directory will be without any file-errors without actually making the tar. Scenario: Let's say you have a directory of 20GB, but you don't have the space to make Tar file at the moment, and you want... (14 Replies)
Discussion started by: filosophizer
14 Replies

2. 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

3. UNIX for Dummies Questions & Answers

Using tar to move directories

I have figured out how to create a tar file that holds all the files in a particular directory. The plan is to move the tar to a new system via FTP so that we can test the new system with our files and libraries. What I can't figure out is how to unzip the tar file; I keep getting messages that... (8 Replies)
Discussion started by: KathyB148
8 Replies

4. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

5. UNIX for Dummies Questions & Answers

Making tar of a remote file system

Hello, I was asked by my boss to make a backup of one of our systems that is slated to be decommissioned. When I suggested if could tar the "/" directory he nodded and said that would do the trick, When I try and execute the command I get EOF error. I think it is because there is not enough... (2 Replies)
Discussion started by: mojoman
2 Replies

6. UNIX for Dummies Questions & Answers

tar, zip multiple separate directories and move the results to another volume

TIA, I'm using FreeBSD 6 I have a series of Directories (A,B,C,...Z). Each directory has files and other directories within it. I want to compress the contents of each top directory into a single file so that I get an archive of each directory (for example, A.gzip) AND and want to move... (5 Replies)
Discussion started by: jccbin
5 Replies

7. UNIX for Advanced & Expert Users

How to create a Tar of multiple Files in Unix and FTP the tar to Windows.

Hi, On my Unix Server in my directory, I have 70 files distributed in the following directories (which have several other files too). These files include C Source Files, Shell Script Source Files, Binary Files, Object Files. a) /usr/users/oracle/bin b) /usr/users/oracle... (1 Reply)
Discussion started by: marconi
1 Replies

8. UNIX for Advanced & Expert Users

Untaring *.tar.tar files

Hi all, How to untar a file with .tar.tar extension. A utility that i downloaded from net had this extension. Thanks in advance, bubeshj. (6 Replies)
Discussion started by: bubeshj
6 Replies

9. UNIX for Dummies Questions & Answers

Making files readonly with vi?

Hi, I'm new at this whole Unix thing, but definately learning (lots of fun)... and I was wondering - how do you make a file read-only with vi? I don't mean how do you load up vi in read-only mode, but how do you save a file (or flag a file, or whatever) in vi to read-only? How do you make it... (2 Replies)
Discussion started by: Flyguy
2 Replies
Login or Register to Ask a Question