I wrote a script to change permissions on all files in a directory:
#!/bin/bash files=`find "$1"` for f in $files; do chown "$2" "$f" chmod 600 "$2" done Obviously, the second argument to chmod should be "$f" instead of "$2". However, when I ran the script (on a small directory) I also forgot to include the second argument, which should have been "dave:dave". Now, all the files in the directory are completely messed up:
~ $ ll Documents/ ls: cannot access Documents/wiki.txt: Permission denied ls: cannot access Documents/todo.txt: Permission denied ls: cannot access Documents/modules.txt: Permission denied ls: cannot access Documents/packages.txt: Permission denied total 0 -????????? ? ? ? ? ? modules.txt -????????? ? ? ? ? ? packages.txt -????????? ? ? ? ? ? todo.txt -????????? ? ? ? ? ? wiki.txt Running sudo chown dave:dave Documents/* and sudo chmod 600 Documents/* throws no errors, but the files remain unchanged. I know I can sudo cat each file into a new file, but I'm curious how to fix the permissions on the original files.
Documentsas well, not just the files inside it.find $1 -type fis better in this situation thanfind $1