Andy Regan Ramblings of an Irish Sysadmin

25Feb/100

Quickly Reset Linux File and Directory Permissions

Just a quick post so I can keep these commands handy (since I keep forgetting them). These will allow you to quickly set different permissions for all files (or all folders) within a specific directory in Linux.

Reset File Permissions

$find /path/to/directory/ -type f -exec chmod 644 {} \;

Reset Directory Permissions

$find /path/to/directory/ -type d -exec chmod 755 {} \;

Reset Permissions on 777 PHP Files Only

$find /path/to/directory/ -name \*.php -perm 777 -type f -exec chmod 644 {} \;

28Feb/090

Recovering Files From an Unmountable USB Key

The other night, myself and Rory managed to recover his friend's thesis from a wonky USB thumb drive. We used PhotoRec on Ubuntu Linux. PhotoRec comes with the TestDisk utility. You can install TestDisk via:


$apt-get update
$apt-get install testdisk

The first thing we did was run dmesg in a terminal to get a bit of info on what was going on. We ran dmesg before and after we plugged in the drive and noted the relevant output. The device eventually settled and was given the device location sdb by the kernel, but no filesystem was found.
The partition was likely corrupted somehow.

TestDisk could be used to try to repair the partition on the disk, but it could also damage the data further. We decided to make an image to work with using dd:


$sudo dd if=/dev/sdb ou=./disk_image

Use dd with care! Consult the man page for more info.

This copied the contents of the usb key block-by-block to a file called "disk_image". The was a 2G image (the total capacity) of the wonky drive.

We then used photorec to try to recover any files from the image.


$photorec ./disk_image

Et voila! PhotoRec worked its magic and we recovered the thesis, along with all the other files.

26Feb/093

Webcam Motion Detection in Ubuntu Linux

I bought a cheap usb webcam to add to the list of devices for my fyp. The idea is to push presence updates when motion is detected. I'll be using Motion to handle motion detection. Detailed installation and configuration instructions can be found at InfectedProject.

You can set motion to run commands when certain events happen, such as an image is saved or a movie ends. For example, you could add the following to /etc/motion/motion.conf so that you get an email to you're email account when a movie ends.


# Command to be executed when a movie file (.mpg|.avi) is closed. (default: none)
# To give the filename as an argument to a command append it with %f
on_movie_end echo %f | mutt -s "[Motion]" -a %f joe@bloggs.com