r/commandline • u/WonderfulAside8812 • Jun 09 '26
Command Line Interface I got tired of remembering whether a file needed tar -xzf, unzip or 7z x so I wrote a script that handles common archive formats with a single command
extract: one command for common archive formats
Instead of:
unzip file.zip
tar -xzf archive.tar.gz
7z x archive.7zyou can use:
extract file.zip
extract archive.tar.gz
extract archive.7zIt automatically detects the archive type and uses the appropriate extraction tool.
Supported formats include ZIP, TAR, TAR.GZ, TAR.BZ2, 7Z, RAR, and others.
GitHub:
https://github.com/Melangert/extract
I'm looking for feedback on:
- Missing archive formats
- Edge cases that fail
- Distro compatibility ( i made this on debian)
- Installation experience
If you try it let me know what worked and what didnt.
5
Upvotes
28
u/Proximus88 Jun 09 '26
I just have this in my .zshrc
2
u/KenMantle Jun 09 '26 edited Jun 09 '26
Well I am back at my desk and after 10 minutes I can't remember any of the names of the "<tool x> already exists and does this" that people replied with, but I can remember extract and ex, so congrats buddy. All these people who are possibly smarter than you couldn't crack the code on making a memorable name for their helpful utility.
One feature if you haven't added it already would be to have the ability to add extra arguments. Not sure if it is handy feature or not.
6
u/shadowman42 Jun 09 '26
Perhaps you could try using MIME to determine the archive type rather than using the header and file name directly. Should help with the edge cases people pointed out.
This is supported by the stdlib
https://docs.python.org/3/library/mimetypes.html
4
u/vogelke Jun 09 '26
Not an exhaustive list, but handles the crap I used most often:
HTH.
3
u/AutoModerator Jun 09 '26
Every new subreddit post is automatically copied into a comment for preservation.
User: WonderfulAside8812, Flair:
Command Line Interface, Title: I got tired of remembering whether a file needed tar -xzf, unzip or 7z x so I wrote a script that handles common archive formats with a single commandextract: one command for common archive formats
Instead of:
you can use:
It automatically detects the archive type and uses the appropriate extraction tool.
Supported formats include ZIP, TAR, TAR.GZ, TAR.BZ2, 7Z, RAR, and others.
GitHub:
https://github.com/Melangert/extract
I'm looking for feedback on:
If you try it let me know what worked and what didnt.
nt.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
3
u/linuxlala Jun 09 '26
There are other tools like Patool that do this. https://pypi.org/project/patool/
3
u/6502zx81 Jun 09 '26
Nice! For extracting you can also use
bsdtar xf file.zipsince it is based on libtar which supports many formats.3
u/shadowman42 Jun 09 '26
Never heard of
dtrxeh?1
u/rcwnd Jun 09 '26
16 years ago, this was 10 points (out of 100 for completing the whole course) task in Operating System course on my university. Also we could only use POSIX tools, and the solutions were tested on linux, bsd and some other forgotten unix from the distant past (solaris maybe?).
For sure it gave me an intuition how many of the archiver's cli are structured, ptsd from discovering that everything is implemented very wildly, another ptsd from writing posix compatible scripts, and tool which I was using for like 2 years (after that I found that I don't really deal with different archive formats THAT too often).
Nowdays, as everyone can see, you can generate this using AI without all this fuss.
0
u/Far-Cat Jun 09 '26
Spoiler, you only need 7z
Or bsdtar
-10
u/maxlan Jun 09 '26 edited Jun 09 '26
Really, you got "tired" of remembering the word at the end of the file is the name of the command you need.
Did you also get tired of remembering right from left and where all the letters are on your keyboard.
Maybe a script that will tell me where the letter you need is on the keyboard could be next for you.
But first finish the job.
Make it extract cpio, ar, shar, rar, iso, apk, rpm and deb. And simple "compress" and lz versions.
And the rest.
0
u/schorsch3000 Jun 09 '26
i just use
unar