![]() 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! The files will be extracted in the current folder (most of the times in a folder with the name 'file-1.0').This can be piped to xargs directly, but beware: do the deletion very carefully.In x mode, changes directoriy after opening the archive but before extracting entries from the archive. In c and r mode, this changes the directory before adding the following files. (what is next after the f is the archive file) v = verbose (optional) the files with relative locations will be displayed. ![]() x = eXtract, this indicated an extraction c = create to create ).tar xf file.tar - to uncompressed tar file (.tar) tar xC /var/tmp -f file.tar - to uncompress tar file (.tar) to another directory tar.gz) tar xjf 2 - to uncompress a bzip2 tar file (.tbz or. Tar xzf - to uncompress a gzip tar file (.tgz or. The program, tar, will uncompress both types and extract the files from archive. Generally that are compressed using gzip or bzip2. Tar file can come compressed or uncompressed.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |