zip command not working

后端 未结 7 900

I am trying to zip a file using shell script command. I am using following command:

  zip ./test/step1.zip $FILES

where $FILES contain all the

相关标签:
7条回答
  • 2021-02-13 06:38

    zip warning: name not matched: myfile.dat

    This means the file myfile.dat does not exist.

    You will get the same error if the file is a symlink pointing to a non-existent file.

    As you say, whatever is the last file at the of $FILES, it will not be added to the zip along with the warning. So I think something's wrong with the way you create $FILES. Chances are there is a newline, carriage return, space, tab, or other invisible character at the end of the last filename, resulting in something that doesn't exist. Try this for example:

    for f in $FILES; do echo :$f:; done
    

    I bet the last line will be incorrect, for example:

    :myfile.dat :
    

    ...or something like that instead of :myfile.dat: with no characters before the last :

    UPDATE

    If you say the script started working after running dos2unix on it, that confirms what everybody suspected already, that somehow there was a carriage-return at the end of your $FILES list.

    od -c shows the \r carriage-return. Try echo $FILES | od -c

    0 讨论(0)
  • 2021-02-13 06:39

    spaces are not allowed:

    it would fail if there are more than one files(s) in $FILES unless you put them in loop

    0 讨论(0)
  • 2021-02-13 06:41

    I just discovered another potential cause for this. If the permissions of the directory/subdirectory don't allow the zip to find the file, it will report this error. Actually, if you run a chmod -R 444 on the directory, and then try to zip it, you will reproduce this error, and also have a "stored 0%" report, like this:

    zip warning: name not matched: borrar/enviar adding: borrar/ (stored 0%)

    Hence, try changing the permissions of the file. If you are trying to send them through email, and those email filters (like Gmail's) invent silly filters of not sending executables, don't forget that making permissions very strict when making zip compression can be the cause of the error you are reporting, of "name not matched".

    0 讨论(0)
  • 2021-02-13 06:43

    Another possible cause that can generate a zip warning: name not matched: error is having any of zip's environment variables set incorrectly.

    From the man page:

    ENVIRONMENT
        The following environment variables are read and used by zip as described.
    
    ZIPOPT
        contains default options that will be used when running zip.  The contents of this environment variable will get added to the command line just after the zip command.
    
    ZIP
        [Not on RISC OS and VMS] see ZIPOPT
    
    Zip$Options
        [RISC OS] see ZIPOPT
    
    Zip$Exts
        [RISC OS] contains extensions separated by a : that will cause native filenames with one of the specified extensions to be added to the zip file with basename and extension swapped.
    
    ZIP_OPTS
        [VMS] see ZIPOPT
    

    In my case, I was using zip in a script and had the binary location in an environment variable ZIP so that we could change to a different zip binary easily without making tonnes of changes in the script.

    Example:

    ZIP=/usr/bin/zip
    ...
    ${ZIP} -r folder.zip folder
    

    This is then processed as:

    /usr/bin/zip /usr/bin/zip -r folder.zip folder
    

    And generates the errors:

    zip warning: name not matched: folder.zip
    zip I/O error: Operation not permitted
    zip error: Could not create output file (/usr/bin/zip.zip)
    

    The first because it's now trying to add folder.zip to the archive instead of using it as the archive. The second and third because it's trying to use the file /usr/bin/zip.zip as the archive which is (fortunately) not writable by a normal user.

    Note: This is a really old question, but I didn't find this answer anywhere, so I'm posting it to help future searchers (my future self included).

    0 讨论(0)
  • 2021-02-13 06:55

    eebbesen hit the nail in his comment for my case (but i cannot vote for comment). Another possible reason missed in the other comments is file exceeding the file size limit (4GB).

    0 讨论(0)
  • 2021-02-13 06:55

    I also encountered this issue. In my case, the line separate is CRLF in my zip shell script which causes the problem. Using LF fixed it.

    0 讨论(0)
提交回复
热议问题