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 ?!
When the image is packed its directory structure can be preserved. To see the directory structure of a
tar without un
tar -ztvf my-data.tar.gz
-t (short for
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
--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.
find . -name '*expected file*' to search for it under the current directory.
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
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
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
-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
-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
locate some/directory/myfile.txt will tell you where such a file can be found.