Just in case it has already happened to you: For an unpacked TAR archive🗄️ no extra folder 📁 is created and the content is mixed with many other files in the same directory? How to clean up this mess⁉️

$ tar -tf Nice_Prog_RC1.tar.gz | xargs rm -r

With 'tar -tf' in :terminal: only the content of the archive is displayed. This list of files is given to 'xargs', which passes it on to 'rm -r' for deletion. On the next try we better unpack the archive into an extra folder.👨‍💻

@datenteiler The famous extra-folder convention...

You never know if you have to cd into the final destination before extracting.

And that's the fastest way to clean up the mess if it occurs !

thanks :)

@datenteiler Nice solution, because I've done that exact thing on more than one occasion. I've usually done a second extract to a sub folder and then ran diffs against the files I didn't want to make sure I was getting what I wanted, but this solution is much more elegant.

@datenteiler Workaround for file names containing space or tab characters:

tar -tzf Nice_Prog_RC1.tar.gz | xargs -d '\n' -r rm -r

@Steinar Right. I was going to mention the whitespace-containing-filenames issue.


@datenteiler you always have the "-C" option to put the contents in a separate folder. Really handy after an mkdir.

@souldessin @datenteiler is there a way to tell mkdir to create a directory and cd into it at the same time? I mean a parameter in mkdir, not an alias or function.


IDK but I think the usual command for this is:

$ mkdir -p foo/bar && cd $_


@datenteiler There's a handy program called `dtrx` which does the right file extraction, including creating a directory based on the filename if the archive doesn't include a directory.

Sign in to participate in the conversation

Fosstodon is an English speaking Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.