LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Copy list of files from text file and retain directory structure? (https://www.linuxquestions.org/questions/linux-newbie-8/copy-list-of-files-from-text-file-and-retain-directory-structure-4175669252/)

peter7089 02-09-2020 08:20 AM

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.

pan64 02-09-2020 08:25 AM

there are several ways, like:
1. tar source | tar target
2. rsync
3. cp -r
4- etc

berndbausch 02-09-2020 08:25 AM

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.

peter7089 02-09-2020 08:46 AM

Quote:

Originally Posted by berndbausch (Post 6087993)
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.

This is the list:

Code:

/.
/etc
/etc/firefox-esr
/etc/firefox-esr/firefox-esr.js
/usr
/usr/bin
/usr/bin/firefox
package diverts others to: /usr/bin/firefox.real
/usr/lib
/usr/lib/firefox-esr
/usr/lib/firefox-esr/Throbber-small.gif
/usr/lib/firefox-esr/application.ini
/usr/lib/firefox-esr/browser
/usr/lib/firefox-esr/browser/blocklist.xml
/usr/lib/firefox-esr/browser/chrome.manifest
/usr/lib/firefox-esr/browser/crashreporter-override.ini
/usr/lib/firefox-esr/browser/features
/usr/lib/firefox-esr/browser/features/formautofill@mozilla.org.xpi
/usr/lib/firefox-esr/browser/features/fxmonitor@mozilla.org.xpi
/usr/lib/firefox-esr/browser/features/screenshots@mozilla.org.xpi
/usr/lib/firefox-esr/browser/features/webcompat-reporter@mozilla.org.xpi
/usr/lib/firefox-esr/browser/features/webcompat@mozilla.org.xpi
/usr/lib/firefox-esr/browser/omni.ja
/usr/lib/firefox-esr/chrome.manifest
/usr/lib/firefox-esr/crashreporter
/usr/lib/firefox-esr/crashreporter.ini
/usr/lib/firefox-esr/defaults
/usr/lib/firefox-esr/defaults/pref
/usr/lib/firefox-esr/defaults/pref/channel-prefs.js
/usr/lib/firefox-esr/dependentlibs.list
/usr/lib/firefox-esr/firefox-esr
/usr/lib/firefox-esr/fonts
/usr/lib/firefox-esr/fonts/TwemojiMozilla.ttf
/usr/lib/firefox-esr/gmp-clearkey
/usr/lib/firefox-esr/gmp-clearkey/0.1
/usr/lib/firefox-esr/gmp-clearkey/0.1/libclearkey.so
/usr/lib/firefox-esr/gmp-clearkey/0.1/manifest.json
/usr/lib/firefox-esr/gtk2
/usr/lib/firefox-esr/gtk2/libmozgtk.so
/usr/lib/firefox-esr/libfreeblpriv3.chk
/usr/lib/firefox-esr/libfreeblpriv3.so
/usr/lib/firefox-esr/liblgpllibs.so
/usr/lib/firefox-esr/libmozavcodec.so
/usr/lib/firefox-esr/libmozavutil.so
/usr/lib/firefox-esr/libmozgtk.so
/usr/lib/firefox-esr/libmozsandbox.so
/usr/lib/firefox-esr/libmozsqlite3.so
/usr/lib/firefox-esr/libmozwayland.so
/usr/lib/firefox-esr/libnspr4.so
/usr/lib/firefox-esr/libnss3.so
/usr/lib/firefox-esr/libnssckbi.so
/usr/lib/firefox-esr/libnssdbm3.chk
/usr/lib/firefox-esr/libnssdbm3.so
/usr/lib/firefox-esr/libnssutil3.so
/usr/lib/firefox-esr/libplc4.so
/usr/lib/firefox-esr/libplds4.so
/usr/lib/firefox-esr/libsmime3.so
/usr/lib/firefox-esr/libsoftokn3.chk
/usr/lib/firefox-esr/libsoftokn3.so
/usr/lib/firefox-esr/libssl3.so
/usr/lib/firefox-esr/libxul.so
/usr/lib/firefox-esr/minidump-analyzer
/usr/lib/firefox-esr/omni.ja
/usr/lib/firefox-esr/pingsender
/usr/lib/firefox-esr/platform.ini
/usr/lib/firefox-esr/plugin-container
/usr/lib/mime
/usr/lib/mime/packages
/usr/lib/mime/packages/firefox-esr
/usr/lib/mozilla
/usr/lib/mozilla/extensions
/usr/lib/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}
/usr/lib/mozilla/plugins
/usr/share
/usr/share/applications
/usr/share/applications/firefox-esr.desktop
/usr/share/bug
/usr/share/bug/firefox-esr
/usr/share/bug/firefox-esr/control
/usr/share/bug/firefox-esr/presubj
/usr/share/bug/firefox-esr/script
/usr/share/doc
/usr/share/doc/firefox-esr
/usr/share/doc/firefox-esr/NEWS.Debian.gz
/usr/share/doc/firefox-esr/README.Debian
/usr/share/doc/firefox-esr/changelog.Debian.gz
/usr/share/doc/firefox-esr/copyright
/usr/share/firefox-esr
/usr/share/firefox-esr/browser
/usr/share/firefox-esr/browser/chrome
/usr/share/firefox-esr/browser/chrome/icons
/usr/share/firefox-esr/browser/chrome/icons/default
/usr/share/firefox-esr/browser/chrome/icons/default/default128.png
/usr/share/firefox-esr/browser/chrome/icons/default/default16.png
/usr/share/firefox-esr/browser/chrome/icons/default/default32.png
/usr/share/firefox-esr/browser/chrome/icons/default/default48.png
/usr/share/firefox-esr/browser/chrome/icons/default/default64.png
/usr/share/firefox-esr/browser/defaults
/usr/share/firefox-esr/browser/defaults/preferences
/usr/share/firefox-esr/browser/defaults/preferences/debugger.js
/usr/share/firefox-esr/browser/defaults/preferences/devtools-client.js
/usr/share/firefox-esr/browser/defaults/preferences/devtools-startup.js
/usr/share/firefox-esr/browser/defaults/preferences/firefox-branding.js
/usr/share/firefox-esr/browser/defaults/preferences/firefox.js
/usr/share/firefox-esr/browser/defaults/preferences/vendor.js
/usr/share/firefox-esr/browser/defaults/preferences/webide.js
/usr/share/firefox-esr/distribution
/usr/share/firefox-esr/distribution/searchplugins
/usr/share/firefox-esr/distribution/searchplugins/common
/usr/share/firefox-esr/distribution/searchplugins/common/debsearch.xml
/usr/share/icons
/usr/share/icons/hicolor
/usr/share/icons/hicolor/128x128
/usr/share/icons/hicolor/128x128/apps
/usr/share/icons/hicolor/16x16
/usr/share/icons/hicolor/16x16/apps
/usr/share/icons/hicolor/32x32
/usr/share/icons/hicolor/32x32/apps
/usr/share/icons/hicolor/48x48
/usr/share/icons/hicolor/48x48/apps
/usr/share/icons/hicolor/64x64
/usr/share/icons/hicolor/64x64/apps
/usr/share/icons/hicolor/symbolic
/usr/share/icons/hicolor/symbolic/apps
/usr/share/icons/hicolor/symbolic/apps/firefox-esr-symbolic.svg
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/firefox-esr
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/firefox-esr.1.gz
/usr/share/mozilla
/usr/share/mozilla/extensions
/usr/share/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}
/usr/bin/firefox-esr
/usr/lib/firefox-esr/browser/chrome
/usr/lib/firefox-esr/browser/defaults
/usr/lib/firefox-esr/distribution
/usr/lib/firefox-esr/firefox-bin
/usr/share/firefox-esr/browser/defaults/syspref
/usr/share/icons/hicolor/128x128/apps/firefox-esr.png
/usr/share/icons/hicolor/16x16/apps/firefox-esr.png
/usr/share/icons/hicolor/32x32/apps/firefox-esr.png
/usr/share/icons/hicolor/48x48/apps/firefox-esr.png
/usr/share/icons/hicolor/64x64/apps/firefox-esr.png


peter7089 02-09-2020 08:48 AM

Quote:

Originally Posted by pan64 (Post 6087992)
there are several ways, like:
1. tar source | tar target
2. rsync
3. cp -r
4- etc

This will not retain directory structure. Also, the files are not in one directory.

pan64 02-09-2020 08:50 AM

Quote:

Originally Posted by peter7089 (Post 6088000)
This will not retain directory structure.

That is false. Or at least please tell us how did you try to do that?

peter7089 02-09-2020 09:19 AM

Quote:

Originally Posted by pan64 (Post 6088001)
That is false. Or at least please tell us how did you try to do that?

I don't know how to do that from a text file that contain the list of files. That is why i am asking. I can copy directory and files one by one but this is not my goal.

For example this command copy the files but do not copy directory structure:

Code:

cat your_text_file | xargs cp -t /path/to/destination

teckk 02-09-2020 09:37 AM

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:

I want to create chroot directory
Oh ok.

Look at man cp -R -r

Turbocapitalist 02-09-2020 09:43 AM

Or with tar

Code:

(cd /source/; tar -cf - ./*) | (cd /path/to/destination/; tar -xpf -)

teckk 02-09-2020 09:50 AM

Code:

mkdir ~/test

cd ~/palemoon

for i in *; do
    cp -r "$i" ~/test/
done

ls -l ~/test
total 104480
-rw-r--r-- 1 edit users      428 Feb  9 09:49 application.ini
drwxr-xr-x 7 edit users    4096 Feb  9 09:49 browser
-rw-r--r-- 1 edit users        0 Feb  9 09:49 chrome.manifest
drwxr-xr-x 3 edit users    4096 Feb  9 09:49 defaults
-rw-r--r-- 1 edit users      127 Feb  9 09:49 dependentlibs.list
drwxr-xr-x 2 edit users    4096 Feb  9 09:49 dictionaries
drwxr-xr-x 2 edit users    4096 Feb  9 09:49 fonts
drwxr-xr-x 2 edit users    4096 Feb  9 09:49 icons
-rw-r--r-- 1 edit users 10912528 Feb  9 09:49 icudt58l.dat
-rw-r--r-- 1 edit users      899 Feb  9 09:49 libfreeblpriv3.chk
-rwxr-xr-x 1 edit users  526872 Feb  9 09:49 libfreeblpriv3.so
-rwxr-xr-x 1 edit users    59712 Feb  9 09:49 liblgpllibs.so
-rwxr-xr-x 1 edit users  1834944 Feb  9 09:49 libmozavcodec.so
-rwxr-xr-x 1 edit users  212488 Feb  9 09:49 libmozavutil.so
-rwxr-xr-x 1 edit users  884280 Feb  9 09:49 libmozsqlite3.so
...


pan64 02-09-2020 09:51 AM

rsync has an exclude/include flag, tar also can work on a filelist (given by a file).

peter7089 02-09-2020 10:53 AM

Quote:

Originally Posted by Turbocapitalist (Post 6088026)
Or with tar

Code:

(cd /source/; tar -cf - ./*) | (cd /path/to/destination/; tar -xpf -)

I am trying to do that from list in a text file, and files are not in one directory:

Code:

/.
/etc
/etc/firefox-esr
/etc/firefox-esr/firefox-esr.js
/usr
/usr/bin
/usr/bin/firefox
package diverts others to: /usr/bin/firefox.real
/usr/lib
/usr/lib/firefox-esr
/usr/lib/firefox-esr/Throbber-small.gif
/usr/lib/firefox-esr/application.ini
/usr/lib/firefox-esr/browser
/usr/lib/firefox-esr/browser/blocklist.xml
/usr/lib/firefox-esr/browser/chrome.manifest
/usr/lib/firefox-esr/browser/crashreporter-override.ini
/usr/lib/firefox-esr/browser/features
/usr/lib/firefox-esr/browser/features/formautofill@mozilla.org.xpi
/usr/lib/firefox-esr/browser/features/fxmonitor@mozilla.org.xpi
/usr/lib/firefox-esr/browser/features/screenshots@mozilla.org.xpi
/usr/lib/firefox-esr/browser/features/webcompat-reporter@mozilla.org.xpi
/usr/lib/firefox-esr/browser/features/webcompat@mozilla.org.xpi
/usr/lib/firefox-esr/browser/omni.ja
/usr/lib/firefox-esr/chrome.manifest
/usr/lib/firefox-esr/crashreporter
/usr/lib/firefox-esr/crashreporter.ini
/usr/lib/firefox-esr/defaults
/usr/lib/firefox-esr/defaults/pref
/usr/lib/firefox-esr/defaults/pref/channel-prefs.js
/usr/lib/firefox-esr/dependentlibs.list
/usr/lib/firefox-esr/firefox-esr
/usr/lib/firefox-esr/fonts
/usr/lib/firefox-esr/fonts/TwemojiMozilla.ttf
/usr/lib/firefox-esr/gmp-clearkey
/usr/lib/firefox-esr/gmp-clearkey/0.1
/usr/lib/firefox-esr/gmp-clearkey/0.1/libclearkey.so
/usr/lib/firefox-esr/gmp-clearkey/0.1/manifest.json
/usr/lib/firefox-esr/gtk2
/usr/lib/firefox-esr/gtk2/libmozgtk.so
/usr/lib/firefox-esr/libfreeblpriv3.chk
/usr/lib/firefox-esr/libfreeblpriv3.so
/usr/lib/firefox-esr/liblgpllibs.so
/usr/lib/firefox-esr/libmozavcodec.so
/usr/lib/firefox-esr/libmozavutil.so
/usr/lib/firefox-esr/libmozgtk.so
/usr/lib/firefox-esr/libmozsandbox.so
/usr/lib/firefox-esr/libmozsqlite3.so
/usr/lib/firefox-esr/libmozwayland.so
/usr/lib/firefox-esr/libnspr4.so
/usr/lib/firefox-esr/libnss3.so
/usr/lib/firefox-esr/libnssckbi.so
/usr/lib/firefox-esr/libnssdbm3.chk
/usr/lib/firefox-esr/libnssdbm3.so
/usr/lib/firefox-esr/libnssutil3.so
/usr/lib/firefox-esr/libplc4.so
/usr/lib/firefox-esr/libplds4.so
/usr/lib/firefox-esr/libsmime3.so
/usr/lib/firefox-esr/libsoftokn3.chk
/usr/lib/firefox-esr/libsoftokn3.so
/usr/lib/firefox-esr/libssl3.so
/usr/lib/firefox-esr/libxul.so
/usr/lib/firefox-esr/minidump-analyzer
/usr/lib/firefox-esr/omni.ja
/usr/lib/firefox-esr/pingsender
/usr/lib/firefox-esr/platform.ini
/usr/lib/firefox-esr/plugin-container
/usr/lib/mime
/usr/lib/mime/packages
/usr/lib/mime/packages/firefox-esr
/usr/lib/mozilla
/usr/lib/mozilla/extensions
/usr/lib/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}
/usr/lib/mozilla/plugins
/usr/share
/usr/share/applications
/usr/share/applications/firefox-esr.desktop
/usr/share/bug
/usr/share/bug/firefox-esr
/usr/share/bug/firefox-esr/control
/usr/share/bug/firefox-esr/presubj
/usr/share/bug/firefox-esr/script
/usr/share/doc
/usr/share/doc/firefox-esr
/usr/share/doc/firefox-esr/NEWS.Debian.gz
/usr/share/doc/firefox-esr/README.Debian
/usr/share/doc/firefox-esr/changelog.Debian.gz
/usr/share/doc/firefox-esr/copyright
/usr/share/firefox-esr
/usr/share/firefox-esr/browser
/usr/share/firefox-esr/browser/chrome
/usr/share/firefox-esr/browser/chrome/icons
/usr/share/firefox-esr/browser/chrome/icons/default
/usr/share/firefox-esr/browser/chrome/icons/default/default128.png
/usr/share/firefox-esr/browser/chrome/icons/default/default16.png
/usr/share/firefox-esr/browser/chrome/icons/default/default32.png
/usr/share/firefox-esr/browser/chrome/icons/default/default48.png
/usr/share/firefox-esr/browser/chrome/icons/default/default64.png
/usr/share/firefox-esr/browser/defaults
/usr/share/firefox-esr/browser/defaults/preferences
/usr/share/firefox-esr/browser/defaults/preferences/debugger.js
/usr/share/firefox-esr/browser/defaults/preferences/devtools-client.js
/usr/share/firefox-esr/browser/defaults/preferences/devtools-startup.js
/usr/share/firefox-esr/browser/defaults/preferences/firefox-branding.js
/usr/share/firefox-esr/browser/defaults/preferences/firefox.js
/usr/share/firefox-esr/browser/defaults/preferences/vendor.js
/usr/share/firefox-esr/browser/defaults/preferences/webide.js
/usr/share/firefox-esr/distribution
/usr/share/firefox-esr/distribution/searchplugins
/usr/share/firefox-esr/distribution/searchplugins/common
/usr/share/firefox-esr/distribution/searchplugins/common/debsearch.xml
/usr/share/icons
/usr/share/icons/hicolor
/usr/share/icons/hicolor/128x128
/usr/share/icons/hicolor/128x128/apps
/usr/share/icons/hicolor/16x16
/usr/share/icons/hicolor/16x16/apps
/usr/share/icons/hicolor/32x32
/usr/share/icons/hicolor/32x32/apps
/usr/share/icons/hicolor/48x48
/usr/share/icons/hicolor/48x48/apps
/usr/share/icons/hicolor/64x64
/usr/share/icons/hicolor/64x64/apps
/usr/share/icons/hicolor/symbolic
/usr/share/icons/hicolor/symbolic/apps
/usr/share/icons/hicolor/symbolic/apps/firefox-esr-symbolic.svg
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/firefox-esr
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/firefox-esr.1.gz
/usr/share/mozilla
/usr/share/mozilla/extensions
/usr/share/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}
/usr/bin/firefox-esr
/usr/lib/firefox-esr/browser/chrome
/usr/lib/firefox-esr/browser/defaults
/usr/lib/firefox-esr/distribution
/usr/lib/firefox-esr/firefox-bin
/usr/share/firefox-esr/browser/defaults/syspref
/usr/share/icons/hicolor/128x128/apps/firefox-esr.png
/usr/share/icons/hicolor/16x16/apps/firefox-esr.png
/usr/share/icons/hicolor/32x32/apps/firefox-esr.png
/usr/share/icons/hicolor/48x48/apps/firefox-esr.png
/usr/share/icons/hicolor/64x64/apps/firefox-esr.png


peter7089 02-09-2020 10:55 AM

Quote:

Originally Posted by teckk (Post 6088029)
Code:

mkdir ~/test

cd ~/palemoon

for i in *; do
    cp -r "$i" ~/test/
done

ls -l ~/test
total 104480
-rw-r--r-- 1 edit users      428 Feb  9 09:49 application.ini
drwxr-xr-x 7 edit users    4096 Feb  9 09:49 browser
-rw-r--r-- 1 edit users        0 Feb  9 09:49 chrome.manifest
drwxr-xr-x 3 edit users    4096 Feb  9 09:49 defaults
-rw-r--r-- 1 edit users      127 Feb  9 09:49 dependentlibs.list
drwxr-xr-x 2 edit users    4096 Feb  9 09:49 dictionaries
drwxr-xr-x 2 edit users    4096 Feb  9 09:49 fonts
drwxr-xr-x 2 edit users    4096 Feb  9 09:49 icons
-rw-r--r-- 1 edit users 10912528 Feb  9 09:49 icudt58l.dat
-rw-r--r-- 1 edit users      899 Feb  9 09:49 libfreeblpriv3.chk
-rwxr-xr-x 1 edit users  526872 Feb  9 09:49 libfreeblpriv3.so
-rwxr-xr-x 1 edit users    59712 Feb  9 09:49 liblgpllibs.so
-rwxr-xr-x 1 edit users  1834944 Feb  9 09:49 libmozavcodec.so
-rwxr-xr-x 1 edit users  212488 Feb  9 09:49 libmozavutil.so
-rwxr-xr-x 1 edit users  884280 Feb  9 09:49 libmozsqlite3.so
...


Again, i need to do that from a list in a text file, and the files are not in one directory.

Turbocapitalist 02-09-2020 11:01 AM

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 \
    | xargs dirname \
    | sort \
    | uniq \
    | xargs -I {} sh -c 'test -d {} && echo mkdir -p ./{}/'

cat your_text_file \
    | xargs cp -t /path/to/destination


rtmistler 02-09-2020 11:49 AM

Quote:

Originally Posted by peter7089 (Post 6088047)
Again, i need to do that from a list in a text file, and the files are not in one directory.

You've said this a few times.

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?

peter7089 02-09-2020 12:07 PM

Nevermind, i copy the files and directories one by one. I guess there is no simple solution for what i am looking for.

boughtonp 02-09-2020 12:33 PM

Quote:

Originally Posted by peter7089 (Post 6088068)
I guess there is no simple solution for what i am looking for.

Sure there is - first you need to fix your text file to only contain the absolute file paths you want (i.e. no directories, no "package diverts others to: /usr/bin/firefox.real", etc).

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)
And you will collect all the files (and their paths) into a single file, which can then be extracted with:

Code:

cd ~/firefox1
tar -xvf ~/firefox-files.tar

And you'll get the directory structure preserved.

(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.)


Turbocapitalist 02-09-2020 12:36 PM

Quote:

Originally Posted by peter7089 (Post 6088068)
I guess there is no simple solution for what i am looking for.

There have been several offered. :/

crts 02-09-2020 12:45 PM

Quote:

Originally Posted by peter7089 (Post 6088068)
Nevermind, i copy the files and directories one by one. I guess there is no simple solution for what i am looking for.

Actually, there is:
Code:

tar c -T /path/to/filelist | tar x -C /path/to/targetdirectory
The first tar creates an archive and strips the leading '/' from the filenames. The second tar extracts the archive into the destination directory and preserves the directory structure.

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
or maybe (?)

Code:

find $(dpkg -L firefox) -maxdepth 0 -type f | tar c -T - | tar x -C /path/to/targetdirectory

rtmistler 02-09-2020 12:58 PM

Sorry the various solutions proposed do not suit your needs

I agree with others that there are viable solutions discussed and presented.

berndbausch 02-09-2020 03:56 PM

cpio -pdumva < list targetdir

cpio is exactly the correct tool for that.

peter7089 02-10-2020 02:55 AM

Quote:

Originally Posted by crts (Post 6088078)
Actually, there is:
Code:

tar c -T /path/to/filelist | tar x -C /path/to/targetdirectory


If i run:
Code:

tar c -T file.txt
i get:

Code:

tar: Refusing to write archive contents to terminal (missing -f option?)
tar: Error is not recoverable: exiting now

And the text file contain only list of files.

peter7089 02-10-2020 03:05 AM

Quote:

Originally Posted by berndbausch (Post 6088144)
cpio -pdumva < list targetdir

cpio is exactly the correct tool for that.


This worked very well. Thanks.

Turbocapitalist 02-10-2020 03:06 AM

Quote:

Originally Posted by peter7089 (Post 6088274)
If i run:
Code:

tar c -T file.txt
i get:


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

peter7089 02-10-2020 05:23 AM

Quote:

Originally Posted by Turbocapitalist (Post 6088278)
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

It works but the list have to contain only files. If it have directories it gives error like this:

Code:

tar: usr/bin: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors

But with 'cpio' i don't have to clean the list first and remove directories, it works if it contain files and directories. So, i think 'cpio' is the better and simpler solution.

boughtonp 02-10-2020 08:25 AM

Quote:

Originally Posted by peter7089 (Post 6088302)
It works but the list have to contain only files. If it have directories it gives error like this:

Code:

tar: usr/bin: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors


Well you'd already been offered two different solutions for how to filter dpkg output to be files only, but that error message is not because the list contains directories - it is pointing at the relative path "usr/bin", not the absolute path "/usr/bin".
(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.


crts 02-11-2020 01:47 PM

Quote:

Originally Posted by peter7089 (Post 6088274)
If i run:
Code:

tar c -T file.txt
i get:

Code:

tar: Refusing to write archive contents to terminal (missing -f option?)
tar: Error is not recoverable: exiting now

And the text file contain only list of files.

Honestly, I am completely lost here, OP. I just cannot fathom how you could possibly end up taking the course of action that you did. What you basically did is the equivalent of tying only one of your shoelaces and then complain that shoes do not work because you keep tripping.

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.