Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I have a file that contain list of files I want to archive with tar.
Let's call it mylist.txt
It contains:
/path1/path2/file1.txt
/path1/path2/file3.txt
...
/path1/path2/file10.txt
What I want to do is to archive this file into a tarball but excluding /path1/path2/.
Currently by doing this:
tar -cvf allfiles.tar -T mylist.txt
preserves the path after unarchiving.
I tried this but won't work too:
tar -cvf -C /path1/path2 allfiles.tar -T mylist.txt
It archives all the files in /path1/path2 even those which are not in mylist.txt
Is there a way to do it?
In your "Extraction phase" you can use the strip-components flag like
tar xvf tarname.tar --strip-components=n
which will remove the first n leading components of the file name. Although if you have different file-path-components this will not work for all cases.
If you want to do it while archiving, only one thing comes to mind, and I will share
INPUT: list of files + full paths
1) for each line, split the path out of the filename
2) execute cd to that path and tar on that filename
3) repeat for each line
Related
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Suppose i have a zip file Old.zip , inside it are fileA and fileB. then i unzip them using: unzip Old.zip -d Old, then i will have a directory named Old, with fileA and fileB inside.
Now the Old.zip is gone, and i want to zip it again, but if i use: zip -r New.zip Old, the New.zip is different from Old.zip: inside it are not two files, but one directory!
Before: After: I want:
Old.zip--+ New.zip--+ New.zip--+
+--fileA +--Old--+ +--fileA
+--fileB +--fileA +--fileB
+--fileB
Any suggestions? How should i use zip command correctly to keep the structure? I will NOT go into Old folder and use zip New.zip fileA fileB and move it to the parent folder since i will write it in shell script.
Try passing the the -j (junk paths) option to zip:
$ zip -rj New.zip Old
That way, the files will be stored without their relative paths.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have linux installed on SD card, I used this command to install the rootfs
tar xpjf rootfs.tar.bz -C /mnt/rootfs/
Now, I made some changes to the rootfs and I would like to create a backup that I can use with the same command above, I tried using:
tar cpjf rootfs.tar.bz2 /mnt/rootfs
and
tar cpjf rootfs.tar.bz2 -C / mnt/rootfs
I also tried
tar cpjf rootfs.tar.bz2 /mnt/rootfs/*
And tried:
cd /mnt/rootfs
tar -cvpjf rootfs.tar.bz2 --exclude=/rootfs.tar.bz2 .
tar: ./rootfs.tar.bz2: file changed as we read it
but I end up with an archive that has two levels before the file system i.e mnt/rootfs/files What am I doing wrong ?
That's because it starts from current working directory, you can do:
cd /mnt/rootfs
tar cpjf /rootfs.tar.bz2 .
And that should create an archive at /rootfs.tar.bz2 with its root at the contents of /mnt/rootfs/
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
i'm trying to move folders to another folders using command line, with overwrite if already exists, but i got error "Is a directory" when using mv..
example:
mv src/test/ dest/
there are many files and folders on src/test/, there are also some files and some folders on dest/
and i want files and folders on dest/ replaced with files and folder from src/test/ if exists, example:
src/test/bla/boo replaces dest/bla/boo
src/test/bla/bla/boo replaces dest/bla/bla/boo
also, everytime one file transfer completed, that one file deleted from src/test/
and overall transfer progress bar would be fine..
what rsync flag should i use to make this happend?
The following command line should achieve what you want:
$ rsync -a --progress --remove-source-files src/test/ dest
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I want to create a tarball of files, but not include the directory name. I know there's another way to do it, but I want to know why this way is not working.
If I run the following to create the tarball comprised of a specific file, then it works:
tar -vcf file.tar -C <PATH TO DIR> file1
However, if I run it on a wild card to include multiple files, then it fails:
tar -vcf file.tar -C <PATH TO DIR> *
I get an error saying, for each file in the current dir (not the dir specified in -C), tar: <FILE>: Cannot stat: No such file or directory
Any idea why running the above command on a wild card vs a file name behaves differently?
The * wildcard is expanded by the shell before tar is invoked. tar then changes directory (because you asked it to), but then can't find the files that were in the shell's current directory.
Of course, changing directories in the shell means that you can't open the output file in the original current directory. So you have to redirect the output of tar outside of the subshell, like this:
(cd $DIR; tar -vc *) > file.tar
You have to use a directory:
tar -vcf files.tar /path/to/directory
If your files are in your folder, then use the . to reference the current folder:
tar -vcf files.tar .
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 12 years ago.
Improve this question
When I type " tar -cvf ~/changeset.tar --files-from ~/changeset.txt", It responds with this output: http://pastie.org/1071080. Here is the contents of ~/changeset.txt: http://pastie.org/1071084 . In other words, a bunch of relative paths. As a sanity check,
$ ls admin/memberinformation.php admin/memberinformation.php
Why can't tar find any of these files even though they are clearly reachable from the current directory with the relative paths given?
FYI: $ tar --version tar (GNU tar) 1.15.1
The clue is the position of the colon in the tar output.
You've got a bad case of the trailing spaces. Get rid of them in your changeset file.