Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is there a way (preferrable via GUI, but may be via command line) to extract a zip file and delete the zip after extracted, all in a single command?

(I remember I saw someone doing something like this in the command line one day)

share|improve this question
    
I am not aware of single command but you can queue second command. unzip 1.zip; rm 1.zip –  Amey Jah Aug 17 '11 at 13:39
add comment

3 Answers

up vote 8 down vote accepted

For a GUI I'd say the easiest way is a nautilus script. The main line of which would be:

unzip "$item" && trash "$item"

It works in bash/dash just as easy. In nautilus the whole thing would look like this:

unzip delete nautilus script

#!/bin/bash
# Nautilus script to unzip and then remove a zip archive.
# Nautilus script usually go in "$HOME/.gnome2/nautilus-scripts"

IFS='
'
for item in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS; do
    if [ -n "$(file -b "$item" | grep -o 'Zip')" ]; then
        unzip "$item" && trash "$item"
        # use trash instead of rm to move them to trash
        # (trash-cli package installed)
    fi
done
share|improve this answer
    
Not what I saw, but it works. Anyway, thanks! –  Tom Brito Aug 22 '11 at 12:50
add comment

It's pretty easy through a shell command:

unzip <filename>.zip && rm <filename>.zip

Perhaps, if you're using nautilus, you could create a relevant nautilus-action in order to automate the command through a GUI selection.

share|improve this answer
    
yeah, actually these are 2 commands in a single line.. I'm really trying to remember the single command I saw someone use.. –  Tom Brito Aug 17 '11 at 13:45
    
I don't see how it matters whether it's one or two command. You sure he did use an alias or was in fact compressing and used tar --delete-files? –  con-f-use Aug 17 '11 at 14:14
add comment

You could simply write a bash script. It will look sth like this:

unzip $1 && rm -rf $1

where $1 is argument. Then just alias unzip command in ~/.bashrc file to run this script. And after typing in terminal:

unzip test.zip

you will get:

unzip test.zip && rm -rf test.zip

Cheers, Mateusz

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.