2009-10-24から1日間の記事一覧

2つのファイルの新旧を比較する

#!/bin/sh #file_datecmp.sh if [ $# -ne 2 ]; then echo "Usage: file_datecmp.sh file1 file2" exit 1 fi [ -e "$1" ] || { echo "$1 does not exist"; exit 1; } [ -e "$2" ] || { echo "$2 does not exist"; exit 1; } if [ "$1" -nt "$2" ]; then echo …

指定されたパスがファイルなのかディレクトリなのか調べる

#!/bin/sh #fileordir.sh if [ -e "$1" ]; then if [ -d "$1" ]; then echo "$1 is a directory" else echo "$1 is a file (regular or special)" fi else echo "$1 is does not exist" fi $ ./fileordir.sh 1.text 1.text is a file (regular or special)

ディレクトリの大きさを調べる

#!/bin/sh #dirsize.sh if [ $# -ne 1 ]; then echo "Usage: dirsize.sh dirname" exit 1 fi set -- `du -ks "$1"` expr $1 \* 1024 $ ./dirsize.sh /home/anmino 1198080