~
is expanded by the shell. Don't use ~
with -C:
tar czf ~/files/wp/my-page-order.tar.gz \
-C ~ \
webapps/zers/wp-content/plugins/my-page-order
(tar will include webapps/zers/wp-content/plugins/my-page-order
path)
or
tar czf ~/files/wp/my-page-order.tar.gz \
-C ~/webapps/zers/wp-content/plugins \
my-page-order
(tar will include my-page-order
path)
Or just cd
first....
cd ~/webapps/zers/wp-content/plugins
tar czf ~/files/wp/my-page-order.tar.gz my-page-order
If your pax
supports the -0
option, with zsh
:
print -rN dir/**/*(D/e:'reply=($REPLY/*(ND^/[1,10]))':) |
pax -w0 | xz > file.tar.xz
It includes the first 10 non-directory files of each directory in the list sorted by file name. You can choose a different sorting order by adding the om
glob qualifier (order by modification time, Om
to reverse the order), oL
(order by length), non
(sort by name but numerically)...
If you don't have the standard pax
command, or it doesn't support -0
but you have the GNU tar
command, you can do:
print -rN -- dir/**/*(D/e:'reply=($REPLY/*(ND^/[1,10]))':) |
tar --null -T - -cjf file.tar.xz
If you can't use zsh
, but have access to bash
(the shell of the GNU project), you could do:
find dir -type d -exec bash -O nullglob -O dotglob -c '
for dir do
set -- "$dir/*"; n=0
for file do
if [ ! -d "$file" ] || [ -L "$file" ]; then
printf "%s\0" "$file"
(( n++ < 10 )) || break
fi
done
done' bash {} + | pax -0w | xz > file.tar.xz
That would be significantly less efficient though.
Best Answer
Usually
tar
needs the--absolute-names
or--absolute-paths
option to retain the root'/'
part while creating an archive. Even if you force it in that way, the extract skips the leading'/'
too.However, if you have an archive with the leading
'/'
and you tar does not skip it while extracting, NoahD's answer should work in this form,I think
pax
does not handle compressed files, so you would need to pipe after decompress intopax
.That would go like this (assuming you have a gzipped archive)
I found this wiki page on Google just now.