ls: --color now highlights hard linked files, too
[coreutils/bo.git] / tests / du / basic
blob94e62a8384d841b5156de812e61198b4eb5cdd82
1 #!/bin/sh
2 # Compare actual numbers from du, assuming block size matches mine.
4 # Copyright (C) 2003, 2006-2008 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 if test "$VERBOSE" = yes; then
20 set -x
21 du --version
24 . $srcdir/test-lib.sh
26 mkdir -p a/b d d/sub || framework_failure
28 # Ensure that these files contain more than 64 bytes, so that we don't
29 # immediately disqualify file systems (e.g., NetApp) on which smaller
30 # files take up zero disk blocks.
31 printf '%*s' 257 make-sure-the-file-is-non-empty > a/b/F || framework_failure
32 printf %4096s x > d/1
33 cp d/1 d/sub/2
35 fail=0
37 B=`stat --format=%B a/b/F`
39 du --block-size=$B -a a > out || fail=1
40 echo === >> out
41 du --block-size=$B -a -S a >> out || fail=1
42 echo === >> out
43 du --block-size=$B -s a >> out || fail=1
45 f=`stat --format=%b a/b/F`
46 b=`stat --format=%b a/b`
47 a=`stat --format=%b a`
48 bf=`expr $b + $f`
49 tot=`expr $bf + $a`
51 cat <<EOF | sed 's/ *#.*//' > exp
52 $f a/b/F
53 $bf a/b
54 $tot a
55 ===
56 $f a/b/F # size of file, a/b/F
57 $bf a/b # size of dir entry, a/b, + size of file, a/b/F
58 $a a # size of dir entry, a
59 ===
60 $tot a
61 EOF
63 compare out exp || fail=1
65 # Perform this test only if "." is on a local file system.
66 # Otherwise, it would fail e.g., on an NFS-mounted Solaris ZFS file system.
67 if df --local . >/dev/null 2>&1; then
68 rm -f out exp
69 du --block-size=$B -a d | sort -r -k2,2 > out || fail=1
70 echo === >> out
71 du --block-size=$B -S d | sort -r -k2,2 >> out || fail=1
73 t2=`stat --format=%b d/sub/2`
74 ts=`stat --format=%b d/sub`
75 t1=`stat --format=%b d/1`
76 td=`stat --format=%b d`
77 tot=`expr $t1 + $t2 + $ts + $td`
78 d1=`expr $td + $t1`
79 s2=`expr $ts + $t2`
81 cat <<EOF | sed 's/ *#.*//' > exp
82 $t2 d/sub/2
83 $s2 d/sub
84 $t1 d/1
85 $tot d
86 ===
87 $s2 d/sub
88 $d1 d # d + d/1; don't count the dir. entry for d/sub
89 EOF
91 compare out exp || fail=1
94 Exit $fail