3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

適当なファイルサイズのダミーファイルを作るシェル

3
Last updated at Posted at 2012-12-26

mkfileコマンドを使う場合(Mac)

mkfile 20g sparseFile

ddコマンドを使う場合

dd コマンドを使ってダミーファイルを作る方法はよく知られているけど、引数とかが思い出せないのでカプセル化したシェルスクリプトを書いた。

dummy-file.sh 10m とかやると、10メガバイトのファイルができる。

dummy-file.sh
# !/bin/sh

print_help() {
	name=$(basename $0)
	echo "A script for creating sized dummy files."
	echo 
	echo "  Usage:"
	echo
	echo "    $name [size]"
	echo "    $name [size] [filename]"
	echo 
	echo "  Example1: Make 32MB file as '32m'"
	echo 
	echo "    \$ $name 32m"
	echo 
	echo "  Example2: Make 10MB file as 'foo.zip'"
	echo 
	echo "    \$ $name 10m foo.zip"
	exit 1
}

make_file() {
	dd if=/dev/zero of=$1 bs=$2 count=1
}

case $# in
	1)
		make_file $1 $1
		;;
		
	2)
		make_file $2 $1
		;;
	
	*)
		print_help
		;;
esac
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?