Skip to content

Commit

Permalink
Version 1.36
Browse files Browse the repository at this point in the history
    * [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
  • Loading branch information
josephpaul0 committed Jun 24, 2021
1 parent c50db70 commit 3703ded
Show file tree
Hide file tree
Showing 13 changed files with 589 additions and 73 deletions.
10 changes: 10 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
2021-06-24 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

2020-06-10 Version 1.34
* Add manual in PDF
* Add support for FreeBSD 11
Expand Down
339 changes: 338 additions & 1 deletion LICENSE

Large diffs are not rendered by default.

46 changes: 24 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,56 @@ This command-line tool estimates the disk space occupied by all files in a
given path. It displays a sorted list of the biggest items. The estimation
method is similar to the `du -skx` command from GNU Coreutils package.

##Program usage
## Program usage
```
Usage: tdu [options] [directory]
-b n Number of big files shown (default 7)
-b n Number of big files shown (default 7)
-l n Number of depth1 items shown (default 15)
-l n Number of depth1 items shown (default 15)
--max Show deepest and longest paths
--max Show deepest and longest paths
-o file Export result to Ncdu JSON format
(https://dev.yorhel.nl/ncdu/jsonfmt)
-o file Export result to Ncdu JSON format
(https://dev.yorhel.nl/ncdu/jsonfmt)
-e n Number of empty directories shown (default 0)
-e n Number of empty directories shown (default 0)
-d n Number of access denied directories shown (default 0)
-d n Number of access denied directories shown (default 0)
-f n Number of character and block devices shown (default 0)
-f n Number of character and block devices shown (default 0)
-t n Number of sockets and named pipes shown (default 0)
-t n Number of sockets and named pipes shown (default 0)
-s n Number of file status errors shown (default 0)
-s n Number of file status errors shown (default 0)
--human Print sizes in human readable format
--version Program info and usage
--license Show the GNU General Public License V2
--help Program help
--human Print sizes in human readable format (default yes)
--human=false Print sizes in kilobytes
--consolemax Maximize console window (on Windows only, default no)
--version Program info and usage
--license Show the GNU General Public License V2
--help Program help
```
##Quick start guide for end users
## Quick start guide for end users
- 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/
- On the "Downloads" page, you will find packages for:
- Linux (386, Amd64, Armv6), including Raspberry Pi.
- Windows 7, 8, 10 (386, Amd64)
- FreeBSD 11 (386, Amd64)
- FreeBSD (386, Amd64)

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

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

##Project information:
## Project information:
- Author: Joseph Paul
- Homepage: https://bitbucket.org/josephpaul0/tdu
- Homepage: https://github.com/josephpaul0/tdu
- License: GNU General Public Licence version 2.

##Screenshot
## Screenshot
![Terminal](doc/tdu_output.png)
18 changes: 10 additions & 8 deletions doc/tdu.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH TDU 1 "2020-06-10" "1.34" "Top Disk Usage manual"
.TH TDU 1 "2021-06-24" "1.36" "Top Disk Usage manual"

.SH NAME
tdu \- get information about largest files and directories
Expand All @@ -22,9 +22,7 @@ or at current directory by default.
.br
* Counts empty directories, denied accesses, errors.
.br
* Shows deepest directory path.
.br
* Shows longest file path.
* Shows deepest directory path and longest file path.
.br
* Displays information about the filesystem (type, mount options, size, inodes).

Expand Down Expand Up @@ -55,13 +53,18 @@ Number of sockets and named pipes shown (default 0)
Number of file status errors shown (default 0)
.TP
.BR \-\-human
Print sizes in human readable format (default Kb only)
Print sizes in human readable format (default).
.br
Use \-\-human=false to print sizes in kilobytes.
.TP
.BI \-o \ file
Export result to Ncdu JSON format
.br
(https://dev.yorhel.nl/ncdu/jsonfmt)
.TP
.BR \-\-consolemax
Maximizes console window (Windows only, default no)
.TP
.BR \-\-version
Program info and usage
.TP
Expand All @@ -76,14 +79,13 @@ Does not cross filesystem boundaries. It behaves like
.B du \-skx

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

.SH WEBSITE
https://bitbucket.org/josephpaul0/tdu
https://github.com/josephpaul0/tdu

.SH "SEE ALSO"
.BR du (1),
.BR ncdu (1)

3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/josephpaul0/tdu

go 1.10
31 changes: 18 additions & 13 deletions tdu.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Top Disk Usage.
* Copyright (C) 2019 Joseph Paul <joseph.paul1@gmx.com>
* https://bitbucket.org/josephpaul0/tdu
* Copyright (C) 2019-2021 Joseph Paul <joseph.paul1@gmx.com>
* https://github.com/josephpaul0/tdu
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -38,14 +38,14 @@ import (
)

const (
prg_VERSION = "1.34"
prg_VERSION = "1.36"
dft_MAXSHOWNLINES = 15
dft_MAXEMPTYDIRS = 0
dft_MAXDENIEDDIRS = 0
dft_MAXSTATERROR = 0
dft_MAXSTREAMS = 0
dft_MAXDEVICES = 0
dft_MAXBIGFILES = 7
dft_MAXBIGFILES = 8
cst_ENDPROGRESS = "###"
cst_PROGRESSBEAT = 80 // ms
)
Expand Down Expand Up @@ -108,6 +108,7 @@ type s_scan struct { // Global variables
export bool // export result to Ncdu's JSON format
tty bool // stdout is on a TTY
humanReadable bool // print sizes in human readable format
consoleMax bool // maximize size of console window (on Windows only)
exportPath string // path to exported file
exportFile *os.File // exported file
deepestPath string // deepest subdirectory reached
Expand Down Expand Up @@ -337,13 +338,15 @@ func printFileTypes(sc *s_scan) { // Summary of file types with non-zero counter
fmt.Printf(", Symlink: %d", sc.nSymlinks)
}
if sc.nHardlinks > 0 {
fmt.Printf(", Hardlink: %d", sc.nHardlinks)
fmt.Printf(",\n Hardlink: %d", sc.nHardlinks)
}
if sc.nSockets > 0 {
fmt.Printf(", Socket: %d", sc.nSockets)
}
if sc.nDenied > 0 {
fmt.Printf(", Denied: %d", sc.nDenied)
fmt.Printf(", ")
msg := fmt.Sprintf("Denied: %d", sc.nDenied)
printAlert(sc, msg)
}
if sc.nErrors > 0 {
fmt.Printf(", Error: %d", sc.nErrors)
Expand Down Expand Up @@ -609,7 +612,7 @@ func show(sc *s_scan, fi []file, total *file) {
nf := fmt.Sprintf("%%%ds", fmtNameLen+1)
cf := fmt.Sprintf("%%%ds", countDigits(total.diskUsage)+1)
mf := fmt.Sprintf("%%%dd", countDigits(sc.nItems)+1)
var strfmt = "%3d." + nf + "|" + cf + "|%6.2f%%"
var strfmt = "%3d." + nf + "|" + cf + "|%6.2f%%|"
i = 0
for _, f := range fi {
if !f.isDir && sc.nFiles == 0 { // ignore special files
Expand All @@ -629,7 +632,7 @@ func show(sc *s_scan, fi []file, total *file) {
}
fmt.Printf(strfmt, i, f.name, fmtSz(sc, f.diskUsage), p)
if f.isDir {
fmt.Printf("|"+mf+" items", f.items)
fmt.Printf(mf+" items", f.items)
}
fmt.Println()
}
Expand All @@ -640,8 +643,8 @@ func show(sc *s_scan, fi []file, total *file) {
fmt.Printf(s, "REMAINING", fmtSz(sc, rDiskUsage), p, rItems)
}
strfmt += "\n"
fmt.Printf(strfmt, "TOTAL", fmtSz(sc, total.diskUsage))
fmt.Printf(strfmt, "Apparent size", fmtSz(sc, total.size))
fmt.Printf(strfmt, "DISK SPACE", fmtSz(sc, total.diskUsage))
fmt.Printf(strfmt, "TOTAL SIZE", fmtSz(sc, total.size))
fmt.Println()
printFileTypes(sc)
}
Expand Down Expand Up @@ -669,8 +672,8 @@ func changeDir(args []string) (string, error) {
func usage(sc *s_scan) []string {
flag.Usage = func() {
showTitle()
fmt.Println(" Copyright (c) 2020 Joseph Paul <joseph.paul1@gmx.com>")
fmt.Println(" https://bitbucket.org/josephpaul0/tdu")
fmt.Println(" Copyright (c) 2019-2021 Joseph Paul <joseph.paul1@gmx.com>")
fmt.Println(" https://github.com/josephpaul0/tdu")
fmt.Println()
fmt.Printf(" Usage: %s [options] [directory]\n", os.Args[0])
fmt.Println()
Expand All @@ -691,7 +694,8 @@ func usage(sc *s_scan) []string {
nm := flag.Bool("max", false, "Show deepest and longest paths")
vs := flag.Bool("version", false, "Program info and usage")
sl := flag.Bool("license", false, "Show the GNU General Public License V2")
hu := flag.Bool("human", false, "Print sizes in human readable format")
hu := flag.Bool("human", true, "Print sizes in human readable format.\nUse --human=false to print in kilobytes instead.")
cm := flag.Bool("consolemax", false, "Maximize console window (on Windows only)")
flag.Parse() // NArg (int)
if *sl {
showLicense()
Expand Down Expand Up @@ -736,6 +740,7 @@ func usage(sc *s_scan) []string {
}
sc.showMax = *nm
sc.humanReadable = *hu
sc.consoleMax = *cm
if *ex != "" {
sc.export = true
sc.exportPath = *ex
Expand Down
2 changes: 1 addition & 1 deletion tdu_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* Top Disk Usage.
* Copyright (C) 2019 Joseph Paul <joseph.paul1@gmx.com>
* https://bitbucket.org/josephpaul0/tdu
* https://github.com/josephpaul0/tdu
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
4 changes: 2 additions & 2 deletions tdu_export.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Top Disk Usage.
* Copyright (C) 2019 Joseph Paul <joseph.paul1@gmx.com>
* https://bitbucket.org/josephpaul0/tdu
* https://github.com/josephpaul0/tdu
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -79,7 +79,7 @@ func cleanName(s string) string {
rs := []rune(s)
rd := make([]rune, 0, len(s))
for i := 0; i < len(rs); i++ {
if rs[i] <= 31 || rs[i] == 127 {
if rs[i] <= 31 || rs[i] == 34 || rs[i] == 127 {
u := []rune(fmt.Sprintf("\\u00%02X", rs[i]))
rd = append(rd, u...)
} else {
Expand Down
6 changes: 5 additions & 1 deletion tdu_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

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

func printAlert(sc *s_scan, msg string) {
fmt.Printf(msg)
}

func printProgress(sc *s_scan) {
n := sc.nErrors + sc.nItems
fmt.Printf(" [.... scanning... %6d ....]\r", n)
Expand Down
2 changes: 1 addition & 1 deletion tdu_license.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Top Disk Usage.
* Copyright (C) 2019 Joseph Paul <joseph.paul1@gmx.com>
* https://bitbucket.org/josephpaul0/tdu
* https://github.com/josephpaul0/tdu
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion tdu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* Top Disk Usage.
* Copyright (C) 2019 Joseph Paul <joseph.paul1@gmx.com>
* https://bitbucket.org/josephpaul0/tdu
* https://github.com/josephpaul0/tdu
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
29 changes: 18 additions & 11 deletions tdu_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

func printAlert(sc *s_scan, msg string) {
if sc.tty {
colorRed()
}
fmt.Printf(msg)
if sc.tty {
colorDefault()
}
}

func printProgress(sc *s_scan) {
if !sc.tty {
return
Expand Down Expand Up @@ -360,10 +370,8 @@ func partInfo(sc *s_scan) {
if total > 0 {
avail = uint64(statfs.Ffree)
used = total - avail
fmt.Printf(" Inodes :%11d ", total)
fmt.Printf("Avail:%10d ", avail)
fmt.Printf("Used:%10d (%d%%)", used, used*100/total)
fmt.Println()
fmt.Printf(" Inodes :%10d used (%2d%%) of %10d. Avail:%10d\n",
used, used*100/total, total, avail)
}
total = statfs.Blocks * uint64(statfs.Bsize)
if total > 0 {
Expand All @@ -373,13 +381,12 @@ func partInfo(sc *s_scan) {
total /= 1024
avail /= 1024
used /= 1024
fmt.Printf(" Size(kb):%11d ", total)
fmt.Printf("Avail:%10d ", avail)
fmt.Printf("Used:%10d (%d%%)\n", used, used*100/total)
fmt.Printf(" Size(kb):%10d used (%2d%%) of %10d. Avail:%10d\n",
used, used*100/total, int64(total), int64(avail))
} else {
fmt.Printf(" Size :%11s ", fmtSz(sc, int64(total)))
fmt.Printf("Avail:%10s ", fmtSz(sc, int64(avail)))
fmt.Printf("Used:%10s (%d%%)\n", fmtSz(sc, int64(used)), used*100/total)
fmt.Printf(" Size :%10s used (%2d%%) of %10s. Avail:%10s\n",
fmtSz(sc, int64(used)), used*100/total,
fmtSz(sc, int64(total)), fmtSz(sc, int64(avail)))
}
}
fmt.Println()
Expand Down
Loading

0 comments on commit 3703ded

Please sign in to comment.