Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells, Files

Numeric File Permissions in Unix

Submitted by on June 27, 2009 – 7:50 pm 2 Comments

Suppose you are working with a Web server and your task is to make sure that no files or directories have permissions “777”. It would be easy to just recursively change permissions for all files to something like 644, but this may cause unexpected problems. You only need to change those files and directories that have “777” permission and leave everything else as it is. Here is a simple script that will do just that.

The script will search for files and directories that have “777” permissions and change files to 644 and directories to 755.

#!/bin/bash

find . -type f -exec sh -c '
	if [ `stat -c "%a" "{}"` -eq 777 ]
	then
		chmod 644 "{}"
	fi
' \;

find . -type d -exec sh -c '
	if [ `stat -c "%a" "{}"` -eq 777 ]
	then
		chmod 755 "{}"
	fi
' \;

Print Friendly, PDF & Email

2 Comments »

  • Dana G says:

    Hi

    I have a php file that I need to make writable I’be been told to use chmod 777 but I haven’t a clue what that means – I am using Smartftp anyone got any ideas ?

  • Joey 01 says:

    Assume that you have a directory called public in your home directory. Set the permissions on the public directory to allow all to read, write, and execute by using numeric mode command. Use both an absolute path and a relative path (your working directory is your home directory)

Leave a Reply

%d bloggers like this: