touchを指定ディレクトリの全ファイルに再帰的に行う

2010-11-22

touchを指定ディレクトリの全ファイルに再帰的に行う

メモ。ちょっと必要だったので・・・。 デフォで出来ないのかなぁ。  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash

if [ "$1" = "" ]; then
echo "usage : touch_all {dir_name}"
exit
fi

for file in `ls -Ra $1`
do
if [ "$file" = "." ] || [ "$file" = ".." ]; then
continue
fi

if expr "${file}" : ".*:$" >/dev/null; then
dir=${file%%:}/
else
touch $dir$file
fi
done;