File: create-files

package info (click to toggle)
qdirstat 2.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 12,024 kB
  • sloc: cpp: 26,846; perl: 543; sh: 434; xml: 80; makefile: 3
file content (73 lines) | stat: -rwxr-xr-x 1,048 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/sh
#
# Create a huge number of files in a directory
#
# (c) 2019 Stefan Hundhammer <Stefan.Hundhammer@gmx.de>
#
# License: GPL V2


SCRIPT_NAME=$(basename $0)

usage()
{
    echo
    echo "Usage: $SCRIPT_NAME <target-dir> <file-count>"
    echo
    exit 1
}


get_args()
{
    target_dir=$1
    file_count=$2

    test "$#" -eq "2" || usage
    test -d "$target_dir" || usage

    if [ "$file_count" -lt "1" ]; then
       usage
    fi
}


create_files()
{
    file_size=128 # bytes
    large_file=$target_dir/large.$$

    #
    # Create one large file to split up
    #
    
    dd if=/dev/zero of=$large_file bs=$file_size count=$file_count >/dev/null 2>&1

    #
    # Split that large file into tiny chunks
    #
    
    saved_dir=$(pwd)  # pushd can't shut up
    cd $target_dir
    split -b $file_size -d -a 10 $large_file tmp.
    cd $saved_dir
    
    rm $large_file
}


show_summary()
{
    du -hs $target_dir
    count=$(ls -U $target_dir | wc -l)
    echo "$count entries"
}


#
# main
#

get_args $*
create_files
show_summary