| 1 |
Tests of the file helper tool |
| 2 |
|
| 3 |
$ f -h |
| 4 |
?sage: f [options] [filenames] (glob) |
| 5 |
|
| 6 |
?ptions: (glob) |
| 7 |
-h, --help show this help message and exit |
| 8 |
-t, --type show file type (file or directory) |
| 9 |
-m, --mode show file mode |
| 10 |
-l, --links show number of links |
| 11 |
-s, --size show size of file |
| 12 |
--line-count show line count of file |
| 13 |
-n NEWER, --newer=NEWER |
| 14 |
check if file is newer (or same) |
| 15 |
-r, --recurse recurse into directories |
| 16 |
-S, --sha1 show sha1 hash of the content |
| 17 |
--raw-sha1 show raw bytes of the sha1 hash of the content |
| 18 |
--sha256 show sha256 hash of the content |
| 19 |
-M, --md5 show md5 hash of the content |
| 20 |
-D, --dump dump file content |
| 21 |
-H, --hexdump hexdump file content |
| 22 |
-B BYTES, --bytes=BYTES |
| 23 |
number of characters to dump |
| 24 |
-L LINES, --lines=LINES |
| 25 |
number of lines to dump |
| 26 |
-q, --quiet no default output |
| 27 |
|
| 28 |
$ mkdir dir |
| 29 |
$ cd dir |
| 30 |
|
| 31 |
$ f --size |
| 32 |
size=0 |
| 33 |
|
| 34 |
$ echo hello | f --md5 --size |
| 35 |
size=6, md5=b1946ac92492d2347c6235b4d2611184 |
| 36 |
|
| 37 |
$ f foo |
| 38 |
foo: file not found |
| 39 |
|
| 40 |
$ echo foo > foo |
| 41 |
$ f foo |
| 42 |
foo: |
| 43 |
|
| 44 |
$ f --sha1 foo |
| 45 |
foo: sha1=f1d2d2f924e986ac86fdf7b36c94bcdf32beec15 |
| 46 |
|
| 47 |
$ f --sha256 foo |
| 48 |
foo: sha256=b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c |
| 49 |
|
| 50 |
#if symlink |
| 51 |
$ f foo --mode |
| 52 |
foo: mode=644 |
| 53 |
#endif |
| 54 |
|
| 55 |
$ "$PYTHON" $TESTDIR/seq.py 10 > bar |
| 56 |
|
| 57 |
#if unix-permissions symlink |
| 58 |
$ chmod +x bar |
| 59 |
$ f bar --newer foo --mode --type --size --dump --links --bytes 7 |
| 60 |
bar: file, size=21, mode=755, links=1, newer than foo |
| 61 |
>>> |
| 62 |
1 |
| 63 |
2 |
| 64 |
3 |
| 65 |
4 |
| 66 |
<<< no trailing newline |
| 67 |
#endif |
| 68 |
|
| 69 |
#if unix-permissions |
| 70 |
$ ln bar baz |
| 71 |
$ f bar -n baz -l --hexdump -t --sha1 --lines=9 -B 20 |
| 72 |
bar: file, links=2, newer than baz, sha1=612ca68d0305c821750a |
| 73 |
0000: 31 0a 32 0a 33 0a 34 0a 35 0a 36 0a 37 0a 38 0a |1.2.3.4.5.6.7.8.| |
| 74 |
0010: 39 0a |9.| |
| 75 |
$ rm baz |
| 76 |
#endif |
| 77 |
|
| 78 |
#if unix-permissions symlink |
| 79 |
$ ln -s yadda l |
| 80 |
$ f . --recurse -MStmsB4 |
| 81 |
.: directory with 3 files, mode=755 |
| 82 |
./bar: file, size=21, mode=755, md5=3b03, sha1=612c |
| 83 |
./foo: file, size=4, mode=644, md5=d3b0, sha1=f1d2 |
| 84 |
./l: link, size=5, md5=2faa, sha1=af93 |
| 85 |
#endif |
| 86 |
|
| 87 |
$ f --quiet bar -DL 3 |
| 88 |
1 |
| 89 |
2 |
| 90 |
3 |
| 91 |
|
| 92 |
$ cd .. |
| 93 |
|
| 94 |
Yadda is a symlink |
| 95 |
$ f -qr dir -HB 17 |
| 96 |
dir: directory with 3 files (symlink !) |
| 97 |
dir: directory with 2 files (no-symlink !) |
| 98 |
dir/bar: |
| 99 |
0000: 31 0a 32 0a 33 0a 34 0a 35 0a 36 0a 37 0a 38 0a |1.2.3.4.5.6.7.8.| |
| 100 |
0010: 39 |9| |
| 101 |
dir/foo: |
| 102 |
0000: 66 6f 6f 0a |foo.| |
| 103 |
dir/l: (symlink !) |
| 104 |
0000: 79 61 64 64 61 |yadda| (symlink !) |
| 105 |
|