No wrong way to do it. That's the beauty of *NIX!
You could compile a file list first and use cat instead of ls and pipe that into a while loop.
No wrong way to do it. That's the beauty of *NIX!
You could compile a file list first and use cat instead of ls and pipe that into a while loop.
Or, use caution, ...
Code:locate .gbc | while read file; do zip "${file}".zip "${file}"; done
Wow guys, thanks a lot.
I started from the last post, made by KiLaHuRtZ, but unfortunately his command...
...failed to do anything, no errors or anything.Code:locate .gbc | while read file; do zip "${file}".zip "${file}"; done
However, DaithiF's command...
...works perfectly, and did exactly what I was looking for!Code:for file in *.gbc; do zip "${file}.zip" "$file"; done
I did not test the other two that you guy's posted, I think DaithiF's command is as simple as you can get, and it'll definitely help out if I ever have a problem like this again.
And, thanks a lot, and I'm going to mark this as solved.
Glad to hear it! DaithiF's is simpler for a single directory. The last one I posted should find all files with ".gbc" included in the string and zip them. Since it didn't work for you, my guess is that you power down often and may need to update the DB for the system to find them. Hence, run this first...
Code:sudo updatedb locate .gbc | while read file; do zip "${file}".zip "${file}"; done
Ah yes, your command does work now. Thanks a lot for explaining that little problem.
Just to simplify for anyone stumbling over this in the future:
If all of the files you want to Zip are located in one directory, run this command:
...And if the files you want to Zip are located in various directories, run this command:Code:for file in *.gbc; do zip "${file}.zip" "$file"; done
Code:sudo updatedb locate .gbc | while read file; do zip "${file}".zip "${file}"; done
In the event you want to Zip files that are not .GBC files, replace .GBC with their file extension.
And of course, a lot of thanks to KiLaHuRtZ and DaithiF!
Bookmarks