Saturday, May 28, 2011

Lock a folder(/directory)

Sometime it happens in few cases that you are sharing a common pc and an user account with others. It may happen that you want few of your data to keep away the reach of other users.

use the below code with some modification(where specified) to lock your folder:
#! /bin/bash

# Use the bash shell to run the script

cd <path to folder>

i=$(ls -al | grep "<folder name>")


echo "$j"

if [ "$j" == 'drwxr-xr-x' ]; then

chmod 000 <folder name>

elif [ "$j" == 'd---------' ]; then

chmod 755 <folder name>


i=$(ls -al |grep '<folder name>')

echo " -> ${i:0:10}"
Now, place the above file on the same directory which you want to lock.

now type(in terminal):

1. $ cd <path to directory where your file exists>

2. $ chmod 500

3. $ ./

from next time use $ ./ to lock and unlock your directory.

No comments:

Post a Comment