четверг, 25 августа 2011 г.

Как рекурсивно поменять права только каталогам или только файлам

cd /home/some_dir
chmod -R 644 *
find . -type d -exec chmod 0755 {} ';'

#Эта команда рекурсивно пройдется по текущему (точка ".") каталогу и всем его подкаталогам и изменит права на 755 только у каталогов (-type d)
find . -type d -exec chmod 755 {} \;
#Похожим образом действуем и с файлами:
find . -type f -exec chmod 644 {} \;
#если необходимо применить действия только к определенным файлам, подходящим по маске, то действуем так:
find . -type f -name '*.htm*' -exec chmod 644 {} \;
#а если нужно применить команду только к файлам или каталогам определенного владельца, то -
fiind . -type d -user fileowner -exec chmod 0755 {} \;

четверг, 18 августа 2011 г.

bash howto's

first line:
#!/bin/bash

#input parameters count:
$#

#script parameters:
$0 - self name, $1 ... $9 - input params

#check that file exist, the spaces near "[" and "]" are required :
if [ -e "streamcount.info" ]
then
echo 'file exist info'
fi

#get file extension:
SHORTFILENAME=$(basename $FULLFILENAME)
DEST_EXT=${SHORTFILENAME##*.}

#get temporary file name:
TFILE="/tmp/streaminfo.$RANDOM.$$.tmp"

#working directory:
$PWD

#redirect error stream to console and filter strings that contain word "Stream":
ffmpeg -i "$SRC" 2>&1 | grep "Stream"
#count strings with grep -c and put it into variable:
a=$( cat < $TFILE | grep -c "Audio:" )

#save command result as array with ( $( ) ):
s=( $( cat < $TFILE | grep "Audio:" | cut -f 2 -d "#" | cut -f 1 -d "(" ) )

#print array contents:
echo "stream numbers: ${s[@]:0}"

#use "for" construction:
for i in `seq 2 $a`;
do
index=$( echo "$i-1" | bc )
v="${s[index]}"
echo "$i. $v"
done

#extract float value:
x=$( echo "qwerty: 123.123123 !" | sed "s/.*[^0-9]\([0-9]\.[0-9]*\).*/\1/g" )

#float point operations:
echo "(256 / $x) / 10" | bc
for float result:
bc -l


# Checks for root privileges
if [ "$(whoami)" != 'root' ]
then
echo "You need to be root to execute uphosts. Exiting!"
exit 1
fi

# Checks required packages
ABORT=0
builtin type -P wget &>/dev/null || { echo -n "wget is missing."; ABORT=1; }
builtin type -P unzip &>/dev/null || { echo -n "unzip is missing."; ABORT=1; }
builtin type -P fromdos &>/dev/null || { echo -n "fromdos(tofrodos) is missing."; ABORT=1; }
builtin type -P grep &>/dev/null || { echo -n "grep is missing."; ABORT=1; }
if [ $ABORT != 0 ]
then
echo " Exiting!"
exit 2
fi