Unpacking files with space in the name

2

I'm trying to unpack a large mass of files in linux and I'm trying to use a for that looks like this:

for z in *.zip; do unzip $z ; done

but I get the following message:

  

unzip: can not find or open divide, divide.zip, or divide.ZIP. unzip:   can not find or open install, install.zip or install.zip.

The biggest problem is because there are spaces in the names, etc.

I already made another for replacing the spaces with '_' but I would like to know if there is any way to unpack without replacing the spaces.

    
asked by anonymous 21.06.2016 / 17:07

2 answers

2

You can insert double quotation marks in the for and unzip commands that bash will work well with filenames where space exists:

for z in "*.zip"; do unzip "$z" ; done
    
21.06.2016 / 22:32
1

It is possible, for this, you have to manage to separate your files. As the division of your files will be broken by line (because of ls ), we will use it to divide your Strings .

zfiles=$(ls *.zip) # lista os arquivos .zip e armazena em $zfiles
IFS='
' # IFS é a variável responsável por definir o caractere da quebra de linha
lista=($zfiles) # criará um array com os arquivos

for x in "${!lista[@]}"; do
    unzip "$x" #como os nomes terão espaço, mantenha o $x dentro de aspas duplas
done

The% d of% has a line break, and in IFS a for is required in ! , to scroll through the vector

    
21.06.2016 / 22:51