Copy list of files from text file and retain directory structure?
I have a text file with installation location of firefox that i get with 'dpkg -L firefox'. In my home directory i created folder 'firefox1' and i want to copy the files from the list to that directory retaining the directory structure. How can i do that? I want to create chroot directory for firefox and run it from that directory. I am using debian.
|
there are several ways, like:
1. tar source | tar target 2. rsync 3. cp -r 4- etc |
You can use tools like cp, tar, cpio, rsync. Since I don't see the list with the file names, I can't say more.
|
Quote:
Code:
/. |
Quote:
|
Quote:
|
Quote:
For example this command copy the files but do not copy directory structure: Code:
cat your_text_file | xargs cp -t /path/to/destination |
Palemoon has a tarball that can be extracted and run from any folder.
http://linux.palemoon.org/download/mainline/ Does Firefox have a download like that? That would be the way to do what you want. Doubt if it will run if you move those files to another dir. They may if you put $HOME in your $PATH. Quote:
Look at man cp -R -r |
Or with tar
Code:
(cd /source/; tar -cf - ./*) | (cd /path/to/destination/; tar -xpf -) |
Code:
mkdir ~/test |
rsync has an exclude/include flag, tar also can work on a filelist (given by a file).
|
Quote:
Code:
/. |
Quote:
|
I guess you could chain several utilities together to create the directories first. Then your cp will have a place to put them.
Code:
cat your_text_file \ |
Quote:
You do realize a list which can be processed by the shell can come from a text file? Are you having trouble understanding how to process a text file and use the data as entries in a list? |
Nevermind, i copy the files and directories one by one. I guess there is no simple solution for what i am looking for.
|
Quote:
Something like (there's probably a simpler way than this, and you'll want to verify it does the right thing): Code:
dpkg -L firefox-esr | while IFS= read -r line; do test -f "$line" && echo "$line" >> ~/firefox-files.txt || echo "$line" >> ~/firefox-skipped.txt ;done (UPDATE: ignore the rest and use the cleaner version crts wrote below) Then you can just do: Code:
tar -cvf ~/firefox-files.tar $(cat ~/firefox-files.txt) Code:
cd ~/firefox1 (And for the benefit of anyone transferring between different machines, you can add -z to both tar commands to compress the tar file into a tgz (.tar.gz) which will transfer quicker.) |
Quote:
|
Quote:
Code:
tar c -T /path/to/filelist | tar x -C /path/to/targetdirectory Edit: The main problem is that technically you do not have a filelist because it also contains directories and an "invalid" entry. So you will need to filter that list: Code:
find $(</path/to/filelist) -maxdepth 0 -type f | tar c -T - | tar x -C /path/to/targetdirectory Code:
find $(dpkg -L firefox) -maxdepth 0 -type f | tar c -T - | tar x -C /path/to/targetdirectory |
Sorry the various solutions proposed do not suit your needs
I agree with others that there are viable solutions discussed and presented. |
cpio -pdumva < list targetdir
cpio is exactly the correct tool for that. |
Quote:
If i run: Code:
tar c -T file.txt Code:
tar: Refusing to write archive contents to terminal (missing -f option?) |
Quote:
This worked very well. Thanks. |
Quote:
Of course. That's because a pipe is needed to deal with the outout. What happens when you put in the rest of the line as suggested? Code:
tar c -T /path/to/filelist | tar x -C /path/to/targetdirectory |
Quote:
Code:
tar: usr/bin: Cannot stat: No such file or directory |
Quote:
(Did you edit the file manually and make an editing mistake - have you verified no other mistakes were made?) The same error message it output with cpio, however cpio skips invalid entries instead of aborting (tar can do the same with --ignore failed-read option). If you corrected the path (or "cd /" first) then it will not error, (but it will include the entire contents of the /usr/bin directory, which is not what you want). A second difference of cpio compared to tar is that when it see a directory in the list cpio only copies the directory, not its contents - a useful feature to know about, and one that I don't see an equivalent tar option for, which as you say does make cpio a more suitable option for this scenario. One more note - the -u option overrides the default behaviour of skipping files that haven't changed or are newer, so I would consider not using it, especially if running the command multiple times. |
Quote:
I am genuinely curious, what was your thought process that made you cut off my proposed solution in the middle of the line and then come back here posting: "It no worky, worky" |
All times are GMT -5. The time now is 02:25 AM. |