List, How can I check the permissions of all the files of my CentOS server? I'm looking for some kind of report with this information.. Is there some command? Some tool?
Regards, Israel
On Tue, 2005-05-17 at 14:39 -0500, israel.garcia@cimex.com.cu wrote:
List, How can I check the permissions of all the files of my CentOS server? I'm looking for some kind of report with this information.. Is there some command? Some tool?
rpm -Va
On Tue, 2005-05-17 at 14:39 -0500, israel.garcia@cimex.com.cu wrote:
List, How can I check the permissions of all the files of my CentOS server? I'm looking for some kind of report with this information.. Is there some command? Some tool?
Here is a command that will give you the entire list of all files on your system in the format: "user:group mode path"
$ find / -printf "%u:%g %m %p\n"
Note that it _will_ cross filesystems, including any NFS mounts. Use the "-mount" option to keep it from crossing filesystems.
If you want to create a script to reapply all standard UNIX permissions to all files in a tree, here is a script (saveperm.sh) that outputs such a script:
#!/bin/bash mydir="${1}" if [ "${mydir}" == "" ]; then echo "Syntax: " echo " saveperm.sh (path)" echo "NOTE: saveperm.sh does not cross filesystems" echo "NOTE: saveperm.sh does not handle spaces in filenames" exit 127 fi if [ ! -d "${1}" ]; then echo "${1} is not a directory" exit 127 fi echo "#!/bin/bash" echo "# Created by saveperm.sh" echo "# Run from `pwd` targeting ${mydir}" echo "" for mypath in `find ${mydir} -mount`; do find "${mypath}" -maxdepth 0 -printf "chown %u:%g %p\n" find "${mypath}" -maxdepth 0 -printf "chmod %m %p\n" done
You'd typically run it with (examples):
$ saveperm.sh /abspath > /perms_abspath.sh [ save absolute path /abspath to a script /perms_abspath.sh ]
$ saveperm.sh . > ../perms_subdir.sh [ save perms on current directory to script perms_subdir.sh in parent ]
The above script outputs (echos) a script to the screen. You can redirect that into a file for execution later.
Note that the above script will NOT handle spaces in filenames! I have found different bash versions to be exceedingly difficult in handling spaces in filenames when returning from a find. Setting IFS="\n" typically doesn't work well or consistently. I would use an equivalent tcsh script instead of dorking with bash.**
-- Bryan
**NOTE: Ed Schaffer keeps bothering me for a script for his column, so I might just have to just write the tcsh version. ;->
On Tue, 2005-05-17 at 15:52 -0500, Bryan J. Smith wrote:
find "${mypath}" -maxdepth 0 -printf "chown %u:%g %p\n" find "${mypath}" -maxdepth 0 -printf "chmod %m %p\n"
NOTE, if you want to save by UID/GID, change %u:%g to %U:%G.
Also, there is a way to save/apply ACLs as well (using getfacl/setfacl). I've been using a variant of this script to save all ACLs into a script when backing up, just in case the backup approach doesn't save them (e.g., I typically limit my use of ACLs to XFS, because xfsdump preserves them, but just in case I use something that cant').
On Tue, 2005-05-17 at 15:57 -0500, Bryan J. Smith wrote:
Also, there is a way to save/apply ACLs as well (using getfacl/setfacl). I've been using a variant of this script to save all ACLs into a script when backing up, just in case the backup approach doesn't save them (e.g., I typically limit my use of ACLs to XFS, because xfsdump preserves them, but just in case I use something that cant').
Of course, another option instead of using my script (but is more Linux- centric, not sure if it's SUS v3 / POSIX 100x-2001 compliant, let alone it probably doesn't work on other UNIX flavors) is to just use the "getfacl/setfacl" commands directly -- not only for ACLs, but regular UNIX permissions as well.
E.g., $ getfacl -R /abspath > /abspath.acls # Saves UNIX+ACL to file $ setfacl --restore=/abspath.acls # Restores UNIX+ACL from file
My older scripts for ACLs were designed for cross-Linux/Irix with XFS. This seems to work on Linux (I haven't tried older Irix versions), and possibly any UNIX post-SUSv3/POSIX100x-2001.