Skip to content

Instantly share code, notes, and snippets.

@editnuki
Created July 3, 2012 06:18
Show Gist options
  • Save editnuki/3038032 to your computer and use it in GitHub Desktop.
Save editnuki/3038032 to your computer and use it in GitHub Desktop.
.txtの拡張子を持つファイルの名前を時刻にするシェルスクリプト
#!/bin/bash
TIMESTAMP=`date +"%Y%m%d%H%M"`
COUNT=1
DIR=/home/username/test
cd $DIR
for file in *
do
if expr "$file" : ".*.txt$" > /dev/null ;then
mv $file $TIMESTAMP\_$COUNT.txt
COUNT=`expr $COUNT + 1`
else
echo $file
fi
done
@editnuki
Copy link
Author

editnuki commented Jul 3, 2012

if文の中で正規表現を使う参考になるかな

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment