Skip to content

Commit 3703ded

Browse files
committed
Version 1.36
* [Windows] Do not maximize console window by default * [Windows] Fix maximize console bug * [Windows] Detect that program is launched by powershell.exe or explorer.exe * [UNIX] Reformat information about used inodes and partitions * [JSON] Fix bug in Ncdu export when filename contains double quotes * Show 8 biggest files by default (customizable) * Display sizes in human readable format by default (customizable) * Add Go module support
1 parent c50db70 commit 3703ded

File tree

13 files changed

+589
-73
lines changed

13 files changed

+589
-73
lines changed

Changelog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2021-06-24 Version 1.36
2+
* [Windows] Do not maximize console window by default
3+
* [Windows] Fix maximize console bug
4+
* [Windows] Detect that program is launched by powershell.exe or explorer.exe
5+
* [UNIX] Reformat information about used inodes and partitions
6+
* [JSON] Fix bug in Ncdu export when filename contains double quotes
7+
* Show 8 biggest files by default (customizable)
8+
* Display sizes in human readable format by default (customizable)
9+
* Add Go module support
10+
111
2020-06-10 Version 1.34
212
* Add manual in PDF
313
* Add support for FreeBSD 11

LICENSE

Lines changed: 338 additions & 1 deletion
Large diffs are not rendered by default.

README.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,56 @@ This command-line tool estimates the disk space occupied by all files in a
33
given path. It displays a sorted list of the biggest items. The estimation
44
method is similar to the `du -skx` command from GNU Coreutils package.
55

6-
##Program usage
6+
## Program usage
77
```
88
Usage: tdu [options] [directory]
99
10-
-b n Number of big files shown (default 7)
10+
-b n Number of big files shown (default 7)
1111
12-
-l n Number of depth1 items shown (default 15)
12+
-l n Number of depth1 items shown (default 15)
1313
14-
--max Show deepest and longest paths
14+
--max Show deepest and longest paths
1515
16-
-o file Export result to Ncdu JSON format
17-
(https://dev.yorhel.nl/ncdu/jsonfmt)
16+
-o file Export result to Ncdu JSON format
17+
(https://dev.yorhel.nl/ncdu/jsonfmt)
1818
19-
-e n Number of empty directories shown (default 0)
19+
-e n Number of empty directories shown (default 0)
2020
21-
-d n Number of access denied directories shown (default 0)
21+
-d n Number of access denied directories shown (default 0)
2222
23-
-f n Number of character and block devices shown (default 0)
23+
-f n Number of character and block devices shown (default 0)
2424
25-
-t n Number of sockets and named pipes shown (default 0)
25+
-t n Number of sockets and named pipes shown (default 0)
2626
27-
-s n Number of file status errors shown (default 0)
27+
-s n Number of file status errors shown (default 0)
2828
29-
--human Print sizes in human readable format
30-
--version Program info and usage
31-
--license Show the GNU General Public License V2
32-
--help Program help
29+
--human Print sizes in human readable format (default yes)
30+
--human=false Print sizes in kilobytes
31+
--consolemax Maximize console window (on Windows only, default no)
32+
--version Program info and usage
33+
--license Show the GNU General Public License V2
34+
--help Program help
3335
```
34-
##Quick start guide for end users
36+
## Quick start guide for end users
3537
- If you just want to use the program on Linux or Windows x86-64, then you can download a ready-to-run binary at https://bitbucket.org/josephpaul0/tdu/downloads/
3638
- On the "Downloads" page, you will find packages for:
3739
- Linux (386, Amd64, Armv6), including Raspberry Pi.
3840
- Windows 7, 8, 10 (386, Amd64)
39-
- FreeBSD 11 (386, Amd64)
41+
- FreeBSD (386, Amd64)
4042

41-
##Quick start guide for advanced users / developers
43+
## Quick start guide for advanced users / developers
4244
- You need a Go compiler
4345
- Do not use Go v1.12 or v1.12.1 on Windows, because of this issue: https://github.com/golang/go/issues/30883
4446
- Clone the git repository or download the source archive.
4547
- Run 'make' or 'build.cmd' to build the binary
4648

47-
##Other Operating Systems
49+
## Other Operating Systems
4850
- If you use FreeBSD or macOS, please test the code and submit patches for supporting those operating systems.
4951

50-
##Project information:
52+
## Project information:
5153
- Author: Joseph Paul
52-
- Homepage: https://bitbucket.org/josephpaul0/tdu
54+
- Homepage: https://github.com/josephpaul0/tdu
5355
- License: GNU General Public Licence version 2.
5456

55-
##Screenshot
57+
## Screenshot
5658
![Terminal](doc/tdu_output.png)

doc/tdu.1

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH TDU 1 "2020-06-10" "1.34" "Top Disk Usage manual"
1+
.TH TDU 1 "2021-06-24" "1.36" "Top Disk Usage manual"
22

33
.SH NAME
44
tdu \- get information about largest files and directories
@@ -22,9 +22,7 @@ or at current directory by default.
2222
.br
2323
* Counts empty directories, denied accesses, errors.
2424
.br
25-
* Shows deepest directory path.
26-
.br
27-
* Shows longest file path.
25+
* Shows deepest directory path and longest file path.
2826
.br
2927
* Displays information about the filesystem (type, mount options, size, inodes).
3028

@@ -55,13 +53,18 @@ Number of sockets and named pipes shown (default 0)
5553
Number of file status errors shown (default 0)
5654
.TP
5755
.BR \-\-human
58-
Print sizes in human readable format (default Kb only)
56+
Print sizes in human readable format (default).
57+
.br
58+
Use \-\-human=false to print sizes in kilobytes.
5959
.TP
6060
.BI \-o \ file
6161
Export result to Ncdu JSON format
6262
.br
6363
(https://dev.yorhel.nl/ncdu/jsonfmt)
6464
.TP
65+
.BR \-\-consolemax
66+
Maximizes console window (Windows only, default no)
67+
.TP
6568
.BR \-\-version
6669
Program info and usage
6770
.TP
@@ -76,14 +79,13 @@ Does not cross filesystem boundaries. It behaves like
7679
.B du \-skx
7780

7881
.SH COPYRIGHT
79-
Copyright \(co 2019,2020 Joseph Paul <joseph.paul1@gmx.com>.
82+
Copyright \(co 2019-2021 Joseph Paul <joseph.paul1@gmx.com>.
8083
.br
8184
License GPLv2+: GNU GPL version 2 or later.
8285

8386
.SH WEBSITE
84-
https://bitbucket.org/josephpaul0/tdu
87+
https://github.com/josephpaul0/tdu
8588

8689
.SH "SEE ALSO"
8790
.BR du (1),
8891
.BR ncdu (1)
89-

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/josephpaul0/tdu
2+
3+
go 1.10

tdu.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* Top Disk Usage.
2-
* Copyright (C) 2019 Joseph Paul <joseph.paul1@gmx.com>
3-
* https://bitbucket.org/josephpaul0/tdu
2+
* Copyright (C) 2019-2021 Joseph Paul <joseph.paul1@gmx.com>
3+
* https://github.com/josephpaul0/tdu
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -38,14 +38,14 @@ import (
3838
)
3939

4040
const (
41-
prg_VERSION = "1.34"
41+
prg_VERSION = "1.36"
4242
dft_MAXSHOWNLINES = 15
4343
dft_MAXEMPTYDIRS = 0
4444
dft_MAXDENIEDDIRS = 0
4545
dft_MAXSTATERROR = 0
4646
dft_MAXSTREAMS = 0
4747
dft_MAXDEVICES = 0
48-
dft_MAXBIGFILES = 7
48+
dft_MAXBIGFILES = 8
4949
cst_ENDPROGRESS = "###"
5050
cst_PROGRESSBEAT = 80 // ms
5151
)
@@ -108,6 +108,7 @@ type s_scan struct { // Global variables
108108
export bool // export result to Ncdu's JSON format
109109
tty bool // stdout is on a TTY
110110
humanReadable bool // print sizes in human readable format
111+
consoleMax bool // maximize size of console window (on Windows only)
111112
exportPath string // path to exported file
112113
exportFile *os.File // exported file
113114
deepestPath string // deepest subdirectory reached
@@ -337,13 +338,15 @@ func printFileTypes(sc *s_scan) { // Summary of file types with non-zero counter
337338
fmt.Printf(", Symlink: %d", sc.nSymlinks)
338339
}
339340
if sc.nHardlinks > 0 {
340-
fmt.Printf(", Hardlink: %d", sc.nHardlinks)
341+
fmt.Printf(",\n Hardlink: %d", sc.nHardlinks)
341342
}
342343
if sc.nSockets > 0 {
343344
fmt.Printf(", Socket: %d", sc.nSockets)
344345
}
345346
if sc.nDenied > 0 {
346-
fmt.Printf(", Denied: %d", sc.nDenied)
347+
fmt.Printf(", ")
348+
msg := fmt.Sprintf("Denied: %d", sc.nDenied)
349+
printAlert(sc, msg)
347350
}
348351
if sc.nErrors > 0 {
349352
fmt.Printf(", Error: %d", sc.nErrors)
@@ -609,7 +612,7 @@ func show(sc *s_scan, fi []file, total *file) {
609612
nf := fmt.Sprintf("%%%ds", fmtNameLen+1)
610613
cf := fmt.Sprintf("%%%ds", countDigits(total.diskUsage)+1)
611614
mf := fmt.Sprintf("%%%dd", countDigits(sc.nItems)+1)
612-
var strfmt = "%3d." + nf + "|" + cf + "|%6.2f%%"
615+
var strfmt = "%3d." + nf + "|" + cf + "|%6.2f%%|"
613616
i = 0
614617
for _, f := range fi {
615618
if !f.isDir && sc.nFiles == 0 { // ignore special files
@@ -629,7 +632,7 @@ func show(sc *s_scan, fi []file, total *file) {
629632
}
630633
fmt.Printf(strfmt, i, f.name, fmtSz(sc, f.diskUsage), p)
631634
if f.isDir {
632-
fmt.Printf("|"+mf+" items", f.items)
635+
fmt.Printf(mf+" items", f.items)
633636
}
634637
fmt.Println()
635638
}
@@ -640,8 +643,8 @@ func show(sc *s_scan, fi []file, total *file) {
640643
fmt.Printf(s, "REMAINING", fmtSz(sc, rDiskUsage), p, rItems)
641644
}
642645
strfmt += "\n"
643-
fmt.Printf(strfmt, "TOTAL", fmtSz(sc, total.diskUsage))
644-
fmt.Printf(strfmt, "Apparent size", fmtSz(sc, total.size))
646+
fmt.Printf(strfmt, "DISK SPACE", fmtSz(sc, total.diskUsage))
647+
fmt.Printf(strfmt, "TOTAL SIZE", fmtSz(sc, total.size))
645648
fmt.Println()
646649
printFileTypes(sc)
647650
}
@@ -669,8 +672,8 @@ func changeDir(args []string) (string, error) {
669672
func usage(sc *s_scan) []string {
670673
flag.Usage = func() {
671674
showTitle()
672-
fmt.Println(" Copyright (c) 2020 Joseph Paul <joseph.paul1@gmx.com>")
673-
fmt.Println(" https://bitbucket.org/josephpaul0/tdu")
675+
fmt.Println(" Copyright (c) 2019-2021 Joseph Paul <joseph.paul1@gmx.com>")
676+
fmt.Println(" https://github.com/josephpaul0/tdu")
674677
fmt.Println()
675678
fmt.Printf(" Usage: %s [options] [directory]\n", os.Args[0])
676679
fmt.Println()
@@ -691,7 +694,8 @@ func usage(sc *s_scan) []string {
691694
nm := flag.Bool("max", false, "Show deepest and longest paths")
692695
vs := flag.Bool("version", false, "Program info and usage")
693696
sl := flag.Bool("license", false, "Show the GNU General Public License V2")
694-
hu := flag.Bool("human", false, "Print sizes in human readable format")
697+
hu := flag.Bool("human", true, "Print sizes in human readable format.\nUse --human=false to print in kilobytes instead.")
698+
cm := flag.Bool("consolemax", false, "Maximize console window (on Windows only)")
695699
flag.Parse() // NArg (int)
696700
if *sl {
697701
showLicense()
@@ -736,6 +740,7 @@ func usage(sc *s_scan) []string {
736740
}
737741
sc.showMax = *nm
738742
sc.humanReadable = *hu
743+
sc.consoleMax = *cm
739744
if *ex != "" {
740745
sc.export = true
741746
sc.exportPath = *ex

tdu_bsd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/* Top Disk Usage.
44
* Copyright (C) 2019 Joseph Paul <joseph.paul1@gmx.com>
5-
* https://bitbucket.org/josephpaul0/tdu
5+
* https://github.com/josephpaul0/tdu
66
*
77
* This program is free software; you can redistribute it and/or modify
88
* it under the terms of the GNU General Public License as published by

tdu_export.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* Top Disk Usage.
22
* Copyright (C) 2019 Joseph Paul <joseph.paul1@gmx.com>
3-
* https://bitbucket.org/josephpaul0/tdu
3+
* https://github.com/josephpaul0/tdu
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -79,7 +79,7 @@ func cleanName(s string) string {
7979
rs := []rune(s)
8080
rd := make([]rune, 0, len(s))
8181
for i := 0; i < len(rs); i++ {
82-
if rs[i] <= 31 || rs[i] == 127 {
82+
if rs[i] <= 31 || rs[i] == 34 || rs[i] == 127 {
8383
u := []rune(fmt.Sprintf("\\u00%02X", rs[i]))
8484
rd = append(rd, u...)
8585
} else {

tdu_generic.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/* Top Disk Usage.
66
* Copyright (C) 2019 Joseph Paul <joseph.paul1@gmx.com>
7-
* https://bitbucket.org/josephpaul0/tdu
7+
* https://github.com/josephpaul0/tdu
88
*
99
* This program is free software; you can redistribute it and/or modify
1010
* it under the terms of the GNU General Public License as published by
@@ -34,6 +34,10 @@ func getTtyWidth() int {
3434

3535
func initTty(sc *sc_scan) {} // OS Specific
3636

37+
func printAlert(sc *s_scan, msg string) {
38+
fmt.Printf(msg)
39+
}
40+
3741
func printProgress(sc *s_scan) {
3842
n := sc.nErrors + sc.nItems
3943
fmt.Printf(" [.... scanning... %6d ....]\r", n)

tdu_license.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* Top Disk Usage.
22
* Copyright (C) 2019 Joseph Paul <joseph.paul1@gmx.com>
3-
* https://bitbucket.org/josephpaul0/tdu
3+
* https://github.com/josephpaul0/tdu
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by

tdu_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/* Top Disk Usage.
44
* Copyright (C) 2019 Joseph Paul <joseph.paul1@gmx.com>
5-
* https://bitbucket.org/josephpaul0/tdu
5+
* https://github.com/josephpaul0/tdu
66
*
77
* This program is free software; you can redistribute it and/or modify
88
* it under the terms of the GNU General Public License as published by

tdu_unix.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/* Top Disk Usage.
44
* Copyright (C) 2019 Joseph Paul <joseph.paul1@gmx.com>
5-
* https://bitbucket.org/josephpaul0/tdu
5+
* https://github.com/josephpaul0/tdu
66
*
77
* This program is free software; you can redistribute it and/or modify
88
* it under the terms of the GNU General Public License as published by
@@ -222,6 +222,16 @@ func colorCyan() { fmt.Printf(color_CYAN) }
222222
func colorMagenta() { fmt.Printf(color_MAGENTA) }
223223
func colorAlert() { fmt.Printf(color_ALERT) }
224224

225+
func printAlert(sc *s_scan, msg string) {
226+
if sc.tty {
227+
colorRed()
228+
}
229+
fmt.Printf(msg)
230+
if sc.tty {
231+
colorDefault()
232+
}
233+
}
234+
225235
func printProgress(sc *s_scan) {
226236
if !sc.tty {
227237
return
@@ -360,10 +370,8 @@ func partInfo(sc *s_scan) {
360370
if total > 0 {
361371
avail = uint64(statfs.Ffree)
362372
used = total - avail
363-
fmt.Printf(" Inodes :%11d ", total)
364-
fmt.Printf("Avail:%10d ", avail)
365-
fmt.Printf("Used:%10d (%d%%)", used, used*100/total)
366-
fmt.Println()
373+
fmt.Printf(" Inodes :%10d used (%2d%%) of %10d. Avail:%10d\n",
374+
used, used*100/total, total, avail)
367375
}
368376
total = statfs.Blocks * uint64(statfs.Bsize)
369377
if total > 0 {
@@ -373,13 +381,12 @@ func partInfo(sc *s_scan) {
373381
total /= 1024
374382
avail /= 1024
375383
used /= 1024
376-
fmt.Printf(" Size(kb):%11d ", total)
377-
fmt.Printf("Avail:%10d ", avail)
378-
fmt.Printf("Used:%10d (%d%%)\n", used, used*100/total)
384+
fmt.Printf(" Size(kb):%10d used (%2d%%) of %10d. Avail:%10d\n",
385+
used, used*100/total, int64(total), int64(avail))
379386
} else {
380-
fmt.Printf(" Size :%11s ", fmtSz(sc, int64(total)))
381-
fmt.Printf("Avail:%10s ", fmtSz(sc, int64(avail)))
382-
fmt.Printf("Used:%10s (%d%%)\n", fmtSz(sc, int64(used)), used*100/total)
387+
fmt.Printf(" Size :%10s used (%2d%%) of %10s. Avail:%10s\n",
388+
fmtSz(sc, int64(used)), used*100/total,
389+
fmtSz(sc, int64(total)), fmtSz(sc, int64(avail)))
383390
}
384391
}
385392
fmt.Println()

0 commit comments

Comments
 (0)