1

I can't find the default directory .tar files are extracted to. OS - Ubuntu 16 4. Please don't answer : the same folder as the tar file, because it's not there (and every tutorial or question I've found uses that answer). Help, please ?!

1

When the image is packed its directory structure can be preserved. To see the directory structure of a tar without untar-ing it:

tar -ztvf my-data.tar.gz

The -t (short for --list):

List the contents of an archive. Arguments are optional. When given, they specify the names of the members to list.

If it's not in the same directory as the tar file was extract then it will be in a subdirectory of that directory, unless -C or --directory was specified:

   -C, --directory=DIR
          Change  to  DIR  before  performing any operations.  This option is
          order-sensitive, i.e. it affects all options that follow.

Try find . -name '*expected file*' to search for it under the current directory.

  • Find helped, thank you. It wasn't in the directory or subdirectory I was in. It defaulted to another folder for some reason. Sent it to my home folder for some reason. – eftexar Jun 1 '17 at 2:38
  • @eftexar what was the command you used to un-tar? – Andy Jun 1 '17 at 2:49
  • Either tar -xzf or -zxvf, was what I used. – eftexar Jun 1 '17 at 3:03
1

It's the directory that is encoded in the archive, unless changed with e.g. -C when extracting. You can always get a listing of the file paths in the archive with

tar -t -f archive.tar

The paths stored in the archive are almost always relative paths (unless -P was used when creating the archive), which means that the contents of the archive will be unpacked as a file hierarchy in the current directory (unless changed with -C).

  • Most versions of tar that I've used over the ages will always remove the leading slash when adding an absolute path (/path/to/foo) so that when it is extracted it will always be relative to your current workign directory, unless as noted in another answer you use the -C option – ivanivan Jun 1 '17 at 4:10
  • @ivanivan With -P, the absolute pathnames are not stripped of their initial / when archiving. That's why I said "almost always". – Kusalananda Jun 1 '17 at 4:13
0

The tar command extracts files in its current working directory. When you run tar from a shell, that's the current working directory of the shell, the one that's set by the cd command, displayed by the pwd command, and sometimes displayed in the prompt. The extraction directory can be changed with the -C option.

Many tar files have all the files inside a single top-level directory (relative to the extraction directory), usually with a name that resembles the tar file. In this case all the extracted files are under that directory. But that's not an obligation, there are many tar files that contain multiple top-level directories and top-level files. On the other hand, tar on Ubuntu and on most other systems won't extract any files outside of the extraction directory.

The extraction directory does not depend on the location of the tar file at all. (That's for the tar command, and generally most command line archive manipulation programs. GUI programs might behave differently.) The extraction directory is the location of the tar file if the tar file name argument passed to tar doesn't contain any directory part, but in general it could be anywhere.

If you don't remember what the current directory was when you ran the tar command, check your shell history (in bash, press Ctrl+R then type tar; press Ctrl+R again to repeat the search). If you find a relative path to the archive (e.g. tar xf subdir/archive.tar), you may be able to work out what the current directory was (with this example, it was the parent of the directory containing the archive). Of course this won't always help, for example if the path is an absolute one.

If you can't find the files, you can try to look for files that were created or modified (more precisely, any change whatsoever made to the file or its properties) in the right time range, with the command find and its -ctime or -cmin option, e.g.

find ~ -cmin +30 -cmin -61

to look for files that were changed between 30 and 60 minutes ago under your home directory. Instead of -cmin and -ctime you may use -cnewer somefile to compare the change time with that of the file somefile. You can add -name foo at the end of the find command to narrow down to a specific file name contained in the archive (without any directory part).

If you ran tar the previous day or before then the locate database may let you know where your file is. For example, if the archive contains a file some/directory/myfile.txt then locate some/directory/myfile.txt will tell you where such a file can be found.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.