Bash Script 1.0

Ive started to learn bash scripting and have decided to document it on my blog. Its mainly for my reference but I guess it could also be useful for other beginners. Im not doing anything fancy so dont judge đŸ™‚

The idea behind the script is to run on redhat source directories/files to identify which have the wrong user/group permissions and which files are checked out for longer than expected.

Ill put all the explanations in red so they are easy to read, they are currently not part of the script.



set -e #If an error occurs, the script will stop)
set -u #reports if there are any undefined variables)

# Define the variable for the search directory


# Define a function to find the correct directories

function list_src_dirs {

find $_SRC_ROOT -type d -printf ‘%m\t%u\t%g\t%p\n’ 2>/dev/null | \
sed  ‘/\/__/d; /RCS$/d’



Explanation of the find command

type d (find directories only)

printf (prints to the screen)

%mDisplays permissions in octal format
%uDisplays owners username
%gDisplays group name
%pDisplays filename
\ttab between columns

2>/dev/null (sends any error messages to /dev/null, running the script without this we see the permission denied entries to the directories we cannot access)

sed  ‘/\/__/d; /RCS$/d’ (ignores directories starting __ and ending /RCS)

Enclose sed regular expressions in /
/d = delete from the output (/p will print to the screen)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: