Skip to content

Commit 5ace7e3

Browse files
committed
Transformation from diskusage to DUCK
1 parent 48a5479 commit 5ace7e3

33 files changed

+589
-1130
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"folders": [
3-
{
4-
"path": ".."
5-
}
6-
]
2+
"folders": [
3+
{
4+
"path": ".."
5+
}
6+
]
77
}

.vscode/launch.json

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,28 @@
55
"version": "0.2.0",
66
"configurations": [
77
{
8-
"name": "Launch Package",
8+
"name": "DUCK_A DEBUG",
99
"type": "go",
1010
"request": "launch",
1111
"mode": "auto",
12-
"program": "${fileDirname}",
13-
"args": ["--depth", "1", "-limit", "3"]
14-
}
12+
"program": "C:\\_goprojects\\diskusage\\cmd\\duck_a\\main.go",
13+
"args": ["--path", "c:\\_goprojects", "--depth", "0", "-hr"]
14+
},
15+
{
16+
"name": "DUCK_A TO FILE",
17+
"type": "go",
18+
"request": "launch",
19+
"mode": "auto",
20+
"program": "C:\\_goprojects\\diskusage\\cmd\\duck_a\\main.go",
21+
"args": ["--path", "c:\\_goprojects", "--depth", "0", "-hr"]
22+
},
23+
{
24+
"name": "DUCK_F DEBUG",
25+
"type": "go",
26+
"request": "launch",
27+
"mode": "auto",
28+
"program": "C:\\_goprojects\\diskusage\\cmd\\duck_f\\main.go",
29+
"args": ["< ", "${workspaceFolder}\\stdout\\stdout.txt", "--depth", "3", "--top", "15"]
30+
},
1531
]
1632
}

README.md

Lines changed: 86 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,165 +1,99 @@
1-
[![cover.run](https://cover.run/go/github.com/aleksaan/diskusage.svg?style=flat&tag=golang-1.10)](https://cover.run/go?tag=golang-1.10&repo=github.com%2Faleksaan%2Fdiskusage)
2-
3-
# diskusage
4-
diskusage is an FANTASTIC SPEED utility to find out top largest directories on the disk.
1+
# DUCK - (D)isk(U)sage(CK)
2+
Duck is a very fast utility to find top<N> of largest directories or files
53

6-
## !!! 2021.09.24: Version 2.7.0 is now avaliable !!!
7-
## Assignment input parameters as environment variables (rejection of using diskusage_config.yaml file) for better compatibility with a system level utilities
8-
## Renaming "path" parameter to "pathToScan" to avoid naming conflict with classic windows "PATH" system environment variable
94

10-
```cmd
11-
About:
12-
github/aleksaan/diskusage, 2.7.0, Alexander Anufriev, 2021
13-
14-
Arguments:
15-
pathToScan: d:\_appl\go\src\
16-
limit: 20
17-
units: Gb
18-
depth: 5
19-
filterByObjectType: folders&files
20-
sizeCalculatingMethod: cumulative
21-
toTextFile: diskusage_out.txt
22-
toYamlFile: diskusage_out.yaml
23-
24-
Results:
25-
1.| PATH: github.com | SIZE: 316.65 Mb | DEPTH: 1
26-
2.| PATH: github.com\aws | SIZE: 140.36 Mb | DEPTH: 2
27-
3.| PATH: github.com\aws\aws-sdk-go | SIZE: 140.36 Mb | DEPTH: 3
28-
4.| PATH: golang.org | SIZE: 73.65 Mb | DEPTH: 1
29-
5.| PATH: golang.org\x | SIZE: 73.65 Mb | DEPTH: 2
30-
6.| PATH: github.com\aws\aws-sdk-go\.git | SIZE: 66.13 Mb | DEPTH: 4
31-
7.| PATH: github.com\aws\aws-sdk-go\.git\objects | SIZE: 65.83 Mb | DEPTH: 5
32-
8.| PATH: github.com\aleksaan | SIZE: 63.05 Mb | DEPTH: 2
33-
9.| PATH: github.com\aleksaan\diskusage | SIZE: 60.76 Mb | DEPTH: 3
34-
10.| PATH: github.com\aws\aws-sdk-go\service | SIZE: 48.31 Mb | DEPTH: 4
35-
11.| PATH: golang.org\x\tools | SIZE: 32.83 Mb | DEPTH: 3
36-
12.| PATH: github.com\derekparker | SIZE: 32.60 Mb | DEPTH: 2
37-
13.| PATH: github.com\derekparker\delve | SIZE: 32.60 Mb | DEPTH: 3
38-
14.| PATH: github.com\aleksaan\diskusage\dist | SIZE: 28.30 Mb | DEPTH: 4
39-
15.| PATH: golang.org\x\sys | SIZE: 23.44 Mb | DEPTH: 3
40-
16.| PATH: golang.org\x\tools\.git | SIZE: 23.07 Mb | DEPTH: 4
41-
17.| PATH: golang.org\x\tools\.git\objects | SIZE: 22.94 Mb | DEPTH: 5
42-
18.| PATH: github.com\hajimehoshi | SIZE: 22.04 Mb | DEPTH: 2
43-
19.| PATH: github.com\aws\aws-sdk-go\models | SIZE: 21.92 Mb | DEPTH: 4
44-
20.| PATH: github.com\hajimehoshi\go-mp3 | SIZE: 21.81 Mb | DEPTH: 3
45-
46-
Overall info:
47-
Total time: 6.3016798s
48-
Total dirs: 3674
49-
Total files: 9646
50-
Total links: 0
51-
Total size: 414.98 Mb
52-
Total size (bytes): 435138161
53-
Unaccessible dirs & files: 0
54-
55-
System resources:
56-
Total used memory: 257.12 Mb
57-
```
585
## Features
59-
- A primitive tool for getting folder(s) sizes
60-
- Fantastic speed
61-
- Comfortable setup (yaml config)
62-
- Supports both folders and disks as arguments
63-
- Recursive passes through subfolders
64-
- Calculates size of each folder
65-
- Analyzes on defined depth of subfolders
66-
- Sets limit how much folders will be printed in a results
67-
- Fast
68-
- Saves results to csv-file
69-
70-
## Main cons
71-
- No any dummies protection (also pros)
72-
- No any intelligents features (also pros)
6+
- Gathers directories/files sizes
7+
- Finds top of largest directories/files
8+
- Very fast
9+
- JSON compatible (for a service use)
10+
- Human readable mode of output (for a console use)
11+
- More accuracy than FAR manager
7312

7413
## Releases
75-
7614
Releases available as single executable files – just [download latest release](https://github.com/aleksaan/diskusage/releases) for your platform, unpack and run.
7715

78-
## Simple usage (Windows example)
16+
## How it works
17+
Since version **2.8.0** utility has a two parts:
18+
- ```Duck_a``` duck says **analyse**
19+
- ```Duck_f``` duck says **find**
20+
21+
```Duck_a``` gathers sizes of all directories and files under specific path.
22+
```Duck_f``` takes results of ```Duck_a``` and looking for top of largest objects among them.
23+
24+
You can scanning 1Tb disk only once by ```Duck_a``` (*some minutes*) and then many times looking for largest objects by ```Duck_f``` with different parameters (*some milliseconds*).
25+
26+
## ```Duck_a``` utility
27+
28+
```Duck_a``` calculates sizes of directories or files.
29+
30+
**Parameters**:
31+
- ```-path=c:\temp``` - starting point to analyse
32+
- ```-depth=2``` - depth of analysis (how deep does program come down under directories tree)
33+
- ```-hr``` - human readable results representation (text format), if omit that means JSON format
34+
35+
By default program outputs results to ```console```.
7936

80-
Put ```diskusage.exe``` into analyzed directory, run it and get results in ```diskusage_out.txt```
81-
It will be scanning current folder with a default settings
37+
**Example a.1**. Scanning without limit by depth from c:\temp and saving results in JSON format to ```results_a.txt```
38+
```duck_a.exe -depth=0 -path c:\temp\ > .\results_a.txt```
8239

83-
## Advanced usage (Windows example)
40+
**Example a.2**. Scanning with limit by depth=2 from c:\temp and saving results in human readable format to ```console```
41+
```duck_a.exe -depth=2 -path c:\temp\ -hr```
8442

85-
You may define input parameters of diskusage by two ways:
86-
1. in a cmd|bash session define environment variables (like SET pathToScan=C:\) and run diskusage.exe (CLI MODE)
87-
2. or create .env file near diskusage.exe, fill it up by needed environment variables and run diskusage.exe (USER MODE)
43+
## ```Duck_f``` utility
8844

89-
Example of USER MODE settings in the .env file:
90-
```cmd
91-
pathToScan=D:\_docs
92-
depth=5
93-
limit=20
94-
units=Gb
95-
filterByObjectType=folders&files
96-
sizeCalculatingMethod=cumulative
97-
toTextFile=diskusage_out.txt
98-
toYamlFile=diskusage_out.yaml
45+
```Duck_f``` takes results of ```Duck_a```, iterates over them and finds top largest directories or files
46+
47+
**Parameters**:
48+
- ```-top=20``` - how much directories or files will be founded
49+
- ```-depth=2``` - depth of analysis inside of results ```Duck_a```
50+
- ```-filter=df``` - filter by objects types (```f``` - files only, ```d``` - directories only, ```df``` - both of them)
51+
- ```-size=c``` - method of calculating directories size (```c``` clean size (excludes sizes of subdirectories) or ```f``` - full size (inludes subdirectories))
52+
- ```-path=abc``` - not the same what this parameters means in ```duck_a```. It's a filter by part of the path (will be outputed all rows which path includes this one)
53+
- ```-hr``` - human readable results representation (text format), if omit that will be JSON format
54+
55+
By default program outputs results to ```console```.
56+
57+
**Example f.1**. Searching top-10 largest directories or files on depth 2 and outputing results as JSON to file
58+
```duck_f.exe -depth=2 -size=c -top=10 -filter=df < .\results_a.txt > .\stdout_f.txt```
59+
60+
**Example f.2**. Searching top-12 largest directories or files on depth 3 and outputing results in human readable format to ```console```
61+
```duck_f.exe -depth=3 -size=c -top=12 -filter=d -hr < .\results_a.txt```
62+
63+
**Example f.3**. Like ib ```Example f.2``` but with filtering by path of file (for example, print only dir or files contains `.git` in their path & names)
64+
```duck_f.exe -depth=2 -size=c -top=12 -filter=d -path=.git -hr < .\results_a.txt```
65+
66+
**So it is results of Example f.3**
67+
```-------------------
68+
Arguments:
69+
filter: d
70+
depth: 3
71+
top: 12
72+
hr: true
73+
size: c
74+
-------------------
75+
Results:
76+
1.| PATH: diskusage\.git\hooks | FULL SIZE: 22.89 Kb | CLEAN SIZE: 22.89 Kb | DEPTH: 3
77+
2.| PATH: statusek\.git\hooks | FULL SIZE: 22.89 Kb | CLEAN SIZE: 22.89 Kb | DEPTH: 3
78+
3.| PATH: statusek\.git | FULL SIZE: 114.22 Mb | CLEAN SIZE: 5.22 Kb | DEPTH: 2
79+
4.| PATH: diskusage\.git | FULL SIZE: 22.67 Mb | CLEAN SIZE: 5.08 Kb | DEPTH: 2
80+
5.| PATH: statusek\.git\logs | FULL SIZE: 5.30 Kb | CLEAN SIZE: 2.17 Kb | DEPTH: 3
81+
6.| PATH: diskusage\.git\logs | FULL SIZE: 1.79 Kb | CLEAN SIZE: 741.00 b | DEPTH: 3
82+
7.| PATH: diskusage\.git\info | FULL SIZE: 240.00 b | CLEAN SIZE: 240.00 b | DEPTH: 3
83+
8.| PATH: statusek\.git\info | FULL SIZE: 240.00 b | CLEAN SIZE: 240.00 b | DEPTH: 3
84+
9.| PATH: diskusage\.git\objects | FULL SIZE: 22.64 Mb | CLEAN SIZE: 0.00 b | DEPTH: 3
85+
10.| PATH: diskusage\.git\refs | FULL SIZE: 155.00 b | CLEAN SIZE: 0.00 b | DEPTH: 3
86+
11.| PATH: statusek\.git\objects | FULL SIZE: 114.19 Mb | CLEAN SIZE: 0.00 b | DEPTH: 3
87+
12.| PATH: statusek\.git\refs | FULL SIZE: 196.00 b | CLEAN SIZE: 0.00 b | DEPTH: 3
9988
```
89+
* How you can see results are sorted by ```CLEAN SIZE``` (not included sizes of subdirectories). ```FULL SIZE``` is not sorted and has differents from ```CLEAN SIZE```.
90+
91+
**Note about ```FULL SIZE``` and ```CLEAN SIZE```**
92+
For example, if you have directories:
93+
- ```A (100Mb)\B (70Mb)\C (60Mb)```
94+
95+
then ```CLEAN SIZE``` of this dirs will be:
96+
- ```A``` - ```30Mb``` (exclude size of ```B```)
97+
- ```B``` - ```10Mb``` (exclude size of ```C```)
98+
- ```C``` - ```60Mb``` (the same as ```FULL SIZE``` because no any subdirs inside)
10099

101-
where:
102-
```cmd
103-
pathToScan=D:\_docs
104-
```
105-
is a folder or disk name (required)
106-
107-
```cmd
108-
depth=5
109-
```
110-
is depth of subfolders to analyze (optional)
111-
112-
```cmd
113-
limit=20
114-
```
115-
is how much biggest folders will be printed in the results (optional)
116-
if you set -limit to 0 it means limitless (no one row be cuted from results). Be warned it might be a huge list of files!
117-
```cmd
118-
units=Gb
119-
```
120-
you can choose unit style to representing folder sizes. It can be fixed or dynamic-scaled.
121-
122-
If you omit 'units' it means dynamic-scaled units style.
123-
124-
Fixed scale values: b, Kb, Mb, Gb, Tb, Pb.
125-
126-
You can use "units" in case you want to compare sizes afterward (optional).
127-
128-
```cmd
129-
filterByObjectType=folders&files
130-
```
131-
It is a filter to manage what type of objects will be analyzed.
132-
133-
Possible values:
134-
- files - select only files;
135-
- folders - select only folders;
136-
- folders&files - (default) select both of them.
137-
138-
```cmd
139-
sizeCalculatingMethod=cumulative
140-
```
141-
Possible values (optional):
142-
- cumulative - (default) sizes of subfolders will be included into size of the parent folder
143-
- plain - size of subfolders will not be included into size of the parent folder
144-
145-
For example, if your directory tree seems like that:
146-
```cmd
147-
A(100Mb)\B(90Mb)\C(70Mb)
148-
```
149-
and output limit = 2 then
150-
* if sizeCalculatingMethod=cumulative then you get A(100Mb) and B(90Mb) as largest (by syze with nested subfolders)
151-
* if sizeCalculatingMethod=plain then you get B(20Mb) and C(70Mb) as largest (by size without nested subfolders)
152-
153-
154-
```cmd
155-
toTextFile=diskusage_out.txt
156-
```
157-
158-
File name to save results in human readable format. If value is empty file will not be created and you will see results in console window with prompt to exit at the end.
159-
160-
```cmd
161-
toYamlFile=diskusage_out.yaml
162-
```
163-
File name for saving results in YAML format for best compatibility with others programs.
164-
165-
Run ```diskusage.exe```

cmd/duck_a/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
3+
import (
4+
"github.com/aleksaan/diskusage/pkg/analyzer"
5+
)
6+
7+
func main() {
8+
analyzer.CfgInit()
9+
analyzer.Start()
10+
}

cmd/duck_f/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
3+
import (
4+
"github.com/aleksaan/diskusage/pkg/filter"
5+
)
6+
7+
func main() {
8+
filter.Start()
9+
}

config/component.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

config/config.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

config/default.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)