Posts Tagged ‘bash’

Bash script to fix file permissions recursively

I love the redhat implementation of cron, simply drop a shell script into /etc/cron.daily/ and your script will be executed every day (by default at 4am).

Recently I’ve been having a small problem with mediatomb, further investigation lead me to a “Inotify thread caught exception” error which can be fixed by recursively resetting your file permissions.

What I have done to fix the issue is save the following code as /etc/cron.daily/fix_mt.sh and ‘jobs a gooden’ :cool:

History Meme - What’s your shell top 10?

Planet gnome have started a trend

$ history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
114 ping
107 sudo
82 ssh
71 top
71 cd
68 iwconfig
56 ls
46 usbkey.sh
43 ps
33 evolution

The output shows what commands you type the most, usbkey.sh is a script to unlock the secret-keys held on my usb key-fob, sudo is high up probably cause I use sudo to bounce services (the intel wireless drive crashes quite alot and both it and Network Manager then need restarting) and evolution needs a shutdown every now and again :( The other commands are fairly self-explanatory.

Bash looping through directories & sub-directoires

Note to self…. If I want to “do” something to all files in all sub-directories then I need…..


#!/bin/bash
export IFS=$'\n'
for i in $(find $1 -type f)
do
echo "$i"
done