Thursday, 25 August 2011

BASH

file.sh

run:

chmod +x file.sh
./file.sh


BACK UP:
---------------------------------------
#!/bin/bash
# Copy files into a backup folder, skipping directories.

# 1. If the backup directory does not exist, create it.
if [ ! -d ./bak ]
then
mkdir ./bak
fi

# 2. for each file in the current directory listing
for file in `ls`
do
# 3. Skip it if it's a directory...
if [ -d $file ]
then
echo $file " is a directory."
else
# 4. If a backup version already exists, skip past them all and backup a new version.
# The value of index will be appended to the file name.
index=0
if [ -f ./bak/$file.0 ]
then
for bakfile in `ls ./bak/$file.*`
do
# 5. Increment the value of the index.
index=`expr $index + 1`
done
fi
echo "Copying " $file
cp $file ./bak/$file.$index
fi
done

---------------------------------------


http://commandlinemac.blogspot.com/2008/12/bash-basics.html
http://tldp.org/LDP/abs/html/index.html
http://www.freeos.com/guides/lsst/
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html



http://www.cyberciti.biz/faq/bash-for-loop/
http://www.thegeekstuff.com/2009/09/unix-sed-tutorial-replace-text-inside-a-file-using-substitute-command/
http://www.thegeekstuff.com/2010/12/50-unix-linux-sysadmin-tutorials/

No comments:

Post a Comment