Bashスクリプトの例
3947 ワード
Bashスクリプトの例
普段使用するために役立つスクリプトインスタンスを収集し、不定期に更新します.
#!/bin/bash
#
for filename in *
do
# :+ { ; " \ = ? ~ ( ) < > & * | $
badname=`echo "$filename" | sed -n /[\+\{\;\"\\\=\?\~\(\)\<\>\&\*\|\$]/p` rm $badname 2>/dev/null # done # # find {} find . -name "* *" -exec rm -f {} \; exit 0
#!/bin/bash
#
if [-z "$1"]
then
echo "Usage: `basename $0` dir"
exit 1
fi
ls . | xargs -i -t cp ./{} $1
exit 0
#!/bin/bash
# kill
if [ -z "$1" ]
then
"Usage: `basename $0` name"
exit 1
fi
ps -ax | grep "$1" | awk '{print $1}' | xargs -i kill {} 2&>/dev/null
exit $?
#!/bin/bash
#
FILEHEAD="#!"
if [ $# -gt 2 ]
then
"Usage: `basename $0` [dir]"
exit 1
fi
DIRNAME=$PWD
if [ -n "$1" ]
then
DIRNAME=$1
fi
for file in $DIRNAME/*
do
if [[ -f $file ]] && [[ `head -c2 $file`==$FILEHEAD ]]
then
echo "File \"$file\""
fi
done
exit 0
リファレンスドキュメント