<?xml version="1.0" encoding="utf-8"?>
			
			<rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cc="http://web.resource.org/cc/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">

			<channel>
			<title>Jamie Krug&apos;s ColdFusion Blog - Bash</title>
			<link>http://jamiekrug.com/blog/index.cfm</link>
			<description>Jamie Krug&apos;s ColdFusion blog, regarding ColdFusion/CFML and other programming adventures as well as some learning experiences. EDB: Event Driven Blogging (in the event that I actually have something worth sharing:)</description>
			<language>en-us</language>
			<pubDate>Wed, 08 Sep 2010 19:41:57 -0400</pubDate>
			<lastBuildDate>Mon, 28 Dec 2009 15:57:00 -0400</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>jamie@jamiekrug.com</managingEditor>
			<webMaster>jamie@jamiekrug.com</webMaster>
			<itunes:subtitle></itunes:subtitle>
			<itunes:summary></itunes:summary>
			<itunes:category text="Technology" />
			<itunes:category text="Technology">
				<itunes:category text="Podcasting" />
			</itunes:category>
			<itunes:category text="Technology">
				<itunes:category text="Tech News" />
			</itunes:category>
			<itunes:keywords></itunes:keywords>
			<itunes:author></itunes:author>
			<itunes:owner>
				<itunes:email>jamie@jamiekrug.com</itunes:email>
				<itunes:name></itunes:name>
			</itunes:owner>
			<itunes:image href="" />
			<image>
				<url></url>
				<title>Jamie Krug&apos;s ColdFusion Blog</title>
				<link>http://jamiekrug.com/blog/index.cfm</link>
			</image>
			<itunes:explicit>no</itunes:explicit>
			
			
			
			
			
			<item>
				<title>Bash Script to Set Sensible Directory/File Permissions</title>
				<link>http://jamiekrug.com/blog/index.cfm/2009/12/28/bash-script-to-set-sensible-directory-file-permissions</link>
				<description>
				
				Every once in a while a directory structure&apos;s permissions just get messy (or an archive I download and extract has stupid permissions, like making every single file executable). So I&apos;ll occasionally want to &lt;em&gt;chmod 755&lt;/em&gt; all directories and &lt;em&gt;chmod 644&lt;/em&gt; all files. If you&apos;re new to file system permissions in Linux, let me translate that goal. For every directory I want the owner to be able to read/write/execute (execute allows to cd into directory) and both group and all others to have read/execute permissions. For every file I want the owner to have read/write permissions and both the group and all others to have read-only permission. The Ubuntu Community Documentation has a good &lt;a href=&quot;https://help.ubuntu.com/community/FilePermissions&quot;&gt;&lt;em&gt;File&lt;/em&gt; Permissions page&lt;/a&gt; that covers this in more detail.

That same documentation has a &lt;em&gt;&lt;a href=&quot;https://help.ubuntu.com/community/FilePermissions#Recursive%20chmod%20using%20find,%20pipemill,%20and%20sudo&quot;&gt;Recursive chmod using find, pipemill, and sudo&lt;/a&gt;&lt;/em&gt; section that details precisely the two commands I need, but I hate to waste time finding this link and carefully remembering what I want to do. So, I&apos;ve whipped up a simple &lt;a href=&quot;http://en.wikipedia.org/wiki/Bash&quot;&gt;Bash&lt;/a&gt; script that simply accepts a directory path as its only parameter and prompts me to confirm before making the permission changes. Here it is.

&lt;code&gt;#!/bin/bash

# exit this bash script if any statement returns a non-true return value (same as: set -e)
set -o errexit

if [ -z &quot;$1&quot; ]; then
	echo
	echo &quot;ERROR: Must pass parameter of path to directory (which will have permissions set accordingly; 755 directories and 644 files).&quot;
	echo &quot;USAGE: $0 /path/to/directory&quot;
	echo
	exit 1
fi

echo
echo &quot;Working recursively with directory $1 this script will chmod 755 all directories and chmod 644 all files.&quot;

read -p &quot;Okay to continue (y/n)? &quot;
if [ &quot;$REPLY&quot; != &quot;y&quot; ]; then
	echo
	echo &quot;EXITING -- NO ACTION TAKEN.&quot;
	echo
	exit 1
fi

echo
echo &quot;Starting...&quot;
echo

find &quot;$1&quot; -type d -print0 | xargs -0 chmod 755
find &quot;$1&quot; -type f -print0 | xargs -0 chmod 644

echo &quot;Done.&quot;
echo

exit 0&lt;/code&gt;

Since I&apos;ll often need to run this script as root, I&apos;ve taken a few extra steps to protect it by making it owned and executable only by root:

&lt;code&gt;sudo chown root:root setperms.sh
sudo chmod 744 setperms.sh&lt;/code&gt;

So, from the directory containing this script (as you can see I&apos;ve named mine &lt;em&gt;setperms.sh&lt;/em&gt;), here&apos;s an example usage:

&lt;code&gt;sudo ./setperms.sh ~/directory-to-clean-up-permissions&lt;/code&gt;

If your directory has strange owners and/or groups set, you can quickly clean that up recursively as well. For example:

&lt;code&gt;sudo chown -R jkrug:jkrug ~/directory-to-clean-up-permissions&lt;/code&gt;
				
				</description>
						
				
				<category>Linux</category>				
				
				<category>Bash</category>				
				
				<pubDate>Mon, 28 Dec 2009 15:57:00 -0400</pubDate>
				<guid>http://jamiekrug.com/blog/index.cfm/2009/12/28/bash-script-to-set-sensible-directory-file-permissions</guid>
				
			</item>
			
		 	
			</channel></rss>