Search code examples
linuxbash7zip

7zip: can't compress directories from text file, "WARNING: No more files"


I've diff'ed a directory on a home and work computer and got a list of directories I have at home but not at work:

comm -23 <(ls home_dir) <(ssh login@address ls work_dir) >missing

Then I edited the file missing so that it has become like this:

"dir1" "dir2" "dir3" .....

Then I tried to compress missing directories with 7zip:

7z a missing.7z $(cat missing)

But I got an error message:

Scanning the drive:

WARNING: No more files
"dir1"


WARNING: No more files
"dir2"


WARNING: No more files
"dir3"

.............

When I pasted the directory list to a 7zip command:

7z a missing.7z "dir1" "dir2" "dir3" ......

everything was fine.

Why can't I get a directory list from file?


Solution

  • If you remove the quotes from the file, your command will work. I don't know exactly why this happens, but I think it has something to do with how arguments are passed. I think "dir1" is literally sent, and that's what 7z complains about.

    If you have spaces in the filenames or in directories, I suggest to use the following code. You will have to change the "missing" file to have directories or files separated with newlines.

    #! /bin/bash
    archive=test.7z
    while read -r line; do 7z a ${archive} "$line"; done < "missing"
    
    dir1
    dir2
    dir 4
    

    I couldn't get anything else to work with 7z.