0

I'm currently using this command

    tar -zxvf foo.tgz -C /root/dir1/ dir2/dir3/dir4/dir5/file

to extract my specific file from a tar archive to a given directory, dir1. As is, I end up with root/dir1/dir2/dir3/dir4/dir5/file but what I am after is root/dir1/file. This is important because I have 1000 of these files and I don't want to have to open all the individual directories to get to them. Does anyone know how to extract just the file?

Many thanks.

1 Answer 1

1

With GNU tar, you can use --strip-components to remove a specific number of directory levels before the filename. Otherwise, use -O and redirect the output into the desired file.

4
  • Thanks! --strip-components works in regular tar too Commented Dec 13, 2013 at 19:02
  • @user1792403: No, it doesn't. Commented Dec 13, 2013 at 19:06
  • oh, then i must be in GNU tar without realising? i haven't loaded gnu though Commented Dec 13, 2013 at 20:14
  • @user1792403: If you're running Linux, you're using GNU tools. Commented Dec 13, 2013 at 20:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .