Gangmax Blog

Tree

tree“ is a recursive directory listing command that produces a depth indented listing of files.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Install.
sudo apt-get install tree

# Some options.
-a All files are printed. By default tree does not print hidden files (those beginning with a dot `.'). In no event does tree print the file system con‐
structs `.' (current directory) and `..' (previous directory).
-s Print the size of each file in bytes along with the name.

-h Print the size of each file but in a more human readable way, e.g. appending a size letter for kilobytes (K), megabytes (M), gigabytes (G), terabytes
(T), petabytes (P) and exabytes (E).

-p Print the file type and permissions for each file (as per ls -l).

-D Print the date of the last modification time or if -c is used, the last status change time for the file listed.

-Q Quote the names of files in double quotes.

-F Append a `/' for directories, a `=' for socket files, a `*' for executable files, a `>' for doors (Solaris) and a `|' for FIFO's, as per ls -F

-J Turn on JSON output. Outputs the directory tree as an JSON formatted array.

--du For each directory report its size as the accumulation of sizes of all its files and sub-directories (and their files, and so on). The total amount of used space is also given in the final report (like the 'du -c' command.) This option requires tree to read the entire directory tree before emitting it, see BUGS AND NOTES below. Implies -s.

--timefmt format
Prints (implies -D) and formats the date according to the format string which uses the strftime(3) syntax.

# Print the directory tree info in pure text tree format.
tree /media/test -ashpDQF --du --timefmt '%Y-%m-%dT%H:%M:%S%z' > tree.txt

# Print the directory tree info in JSON format.
tree /media/test -aspDJ --du --timefmt '%Y-%m-%dT%H:%M:%S%z' > tree.json

Comments