Quickest way to untar file linux9/8/2023 Once one of these "explodes" on you, the solutions in the other answers are way better than what I would have suggested. That kind of (antisocial) archive is called a tar bomb because of what it does. One other thing: you may need to use the tar option -numeric-owner if the user names and/or group names in the tar listing make the names start in an unpredictable column. The $perms variable is used only for the dry run so really only the $dirent substring needs to be proper. Note: if that initial dry run output doesn't look right, you should be able to fiddle with the numbers in the two substr function calls until they look proper. I prefer this kind of cleanup because it doesn't destroy anything that isn't already destroyed by being overwritten by that initial tar xv. If it is, you can now clean up your mess with: $ sh fixup.sh Have a peek through this script to confirm that it's all kosher. The fixup.sh script will be the shell commands that will move the top-level files and directories into a "clean" folder (in this instance, the folder called cleanup). $ tar tvf myarchive.tar | perl -clean=cleanup > fixup.sh If that looks good, then run it again like this: $ mkdir cleanup You should get output like: -rw-rw-r-|batch This will confirm that your tar list is like mine. Save this to the file and then execute it like this: $ tar tvf myarchive.tar | perl -dry Print "mv -i '$dirent' '$clean_folder'/.\n" # Emit the shell code to clean up the folder # If we're in "dry run" mode, just list the permissions and the directory # Drop entries that are in subdirectories # Strip out permissions string and the directory entry from the 'tar' list # Process the "tar tv" listing and output a shell script. # Protect the 'clean_folder' string from shell substitution Here's a possibility that will take the extracted files and move them to a subdirectory, cleaning up your main folder. And have backups, eat your breakfast, brush your teeth, etc. And perhaps try rm -i to confirm everything. Shut this up with 2>/dev/null if it annoys you, but I'd prefer to keep as much information on the process as possible.Īnd don't do it until you are sure that you match the right files. Rmdir: failed to remove `file': Not a directory This will generate a lot of rm: cannot remove `dir/': Is a directoryĪnd rmdir: failed to remove `dir/': Directory not empty Sort -r (glennjackman suggested tac instead of sort -r in the comments to the accepted answer, which also works since tar's output is regular enough) is needed to delete the deepest directories first otherwise a case where dir1 contains a single empty directory dir2 will leave dir1 after the rmdir pass, since it was not empty before dir2 was removed. To first remove all files that were in the archive, and then the directories that are left empty. Tar tf archive.tar | sort -r | xargs -d'\n' rmdir -v You could do tar tf archive.tar | xargs -d'\n' rm -v You don't want to just rm -r everything that tar tf tells you, since it might include directories that were not empty before unpacking! It's worth noting that everything in this article also works on the Windows Subsystem for Linux, which allows you to install the Bash shell inside of Windows 10 or Windows 11, although there are other ways to open tar.gz files on Windows as well.This can be piped to xargs directly, but beware: do the deletion very carefully. You just need to use the appropriate tar command line options. bz2 extension suffix indicates that the archive has been compressed, using either the gzipĬompression algorithm. The tar command will work happily with both types of file, so it doesn't matter which compression method was used-and it should be available everywhere you have a Bash shell. Someone somewhere is probably still using tar with tape. Forty years later we are still using the tar command to extract tar files on to our hard drives. Tar files date all the way back to 1979 when the tar command was created to allow system administrators to archive files onto tape. Portion of the file extension stands for tape archive, and is the reason that both of these file types are called tar files. Extension is uncompressed, but those will be very rare.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |