Please note, this is a STATIC archive of website www.javatpoint.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
Javatpoint Logo
Javatpoint Logo

Kali Linux Tree Command

In Kali Linux as well as MS-DOS and Microsoft Windows, tree means a recursive directory listing program that generates a depth-indented listing of files. Without any arguments, tree lists the files in the current directory. When directory parameters are used, the tree lists all of the files or directories found in each of the specified directories one by one.

Tree provides the total number of files and directories after listing all files and directories found. There are options for changing the output characters and using color output.

Syntax

The following is the syntax of the tree command:

Tree Command Options

In tree command, there are various options:

  1. Listing options
  2. File options
  3. Sorting options
  4. Graphics options
  5. XML/HTML/JSON options
  6. Input options
  7. Miscellaneous options

1. Listing Options

There are various options for listing:

  • -a: - This option is used to list all files.
  • -d: - This option is used to only list directories.
  • -l: - Follow symbolic links such as directories.
  • -f: - Using this option, we can print the complete path prefix for each file.
  • -x: - We used this option to stay on the current filesystem only.
  • -L level: - Descend only level directories deep.
  • -R: - This option rerun tree when max dir level is reached.
  • -P pattern: - Using this option, we can list only those files which match the pattern given.
  • -I pattern: - Do not list files that match the given pattern.
  • --ignore-case: - This option ignores case when pattern matching.
  • --matchdirs: - Include directory names in -P pattern matching.
  • --noreport: - Turn off file/directory count at the end of tree listing.
  • charset X: - Use charset X for terminal/HTML and indentation line output.
  • --filelimit #: - Do not descend dirs with more than # files in them.
  • --timefmt <f>: - We used this option to print and format time according to the format <f>.
  • -o filename: - Output the file rather than stdout.

2. File Options

The following are the file options:

  • -q: - This option prints non-printable characters as '?'.
  • -N: - This option prints non-printable characters as is.
  • -Q: - This option is used to quote filenames with double-quotes.
  • -p: - This option prints the protections for each file.
  • -u: - We used this option to display the file owner or UID number.
  • -g: - We used this option to display the group owner or GID number.
  • -h: - We used this option to print the size in a more readable format.
  • --si: - This option is like -h, but we use this option in SI units (powers of 1000).
  • -D: -This option is used to print the date of the last modifications or (-c) status change.
  • -F: - Appends '/', '=', '*', '@', '|' or '>' as per ls -F.
  • --inodes: - This option is used to print the inode number of each file.
  • --device: - This option is used to print the device ID number to which each file belongs.

3. Sorting Options

The following are the sorting options:

  • -v: - This option is used to sort files alphanumerically by version.
  • -t: - This option is used to sort files by last modification time.
  • -c: - This option is used to sort files by last status change time.
  • -U: - Leave files unsorted.
  • -r: - We used this option to reverse the order of the sort.
  • --dirsfirst: - This option is used to leave files unsorted.
  • --sort X: - Select sort: name, version, size, mtime, ctime.

4. Graphics options

The following are the graphics options:

  • -i: - Don't print indentation lines.
  • -A: - This option is used to print ANSI line graphic indentation lines.
  • -S: - This option is used to print with CP437 (console) graphics indentation lines.
  • -n: - Turn colorization off always (-C overrides).
  • -C: - Turn colorization on always.

5. XML/HTML/JSON Options

The following are the XML/HTML/JSON options:

  • -X: - This option is used to print out an XML representation of the tree.
  • -J: - This option is used to print out a JSON representation of the tree.
  • -H baseHREF: - This option is used to print out HTML format with baseHREF as the top directory.
  • -T string: - This option is used to replace the default HTML title and H1 header with string.
  • -- nolinks: - This option is used to hyperlinks in HTML output.

6. Input Option

The following is the Input option:

  • --Fromfile: - Read paths from files (.=stdin).

7. Miscellaneous Options

The following are the miscellaneous options:

  • --version: - This option is used to print version and exit.
  • --help: - Print usage and this help message and exit.

How to Install the Tree Command

In Kali Linux, installing the tree command-line utility is so simple via the apt-get command. In order to install a tree command, we have to open our kali Linux terminal and enter the following command.


Kali Linux Tree Command

After the tree is installed, we can use the following command in order to check the version number and see if the installation was successful:

Kali Linux Tree Command

We recommend executing the following command before each install so that we can get the most recent version of the software in the online repositories:

Kali Linux Tree Command

How to Use Tree Command in Kali Linux

We will go through some tree command examples below so that we cannot only learn how to utilize it but also master it.

Basic Tree Output

The tree command can be used in several ways, the most fundamental of which is:


Kali Linux Tree Command

The output displays a tree structure of our current directory, showing all the folders, sub-folders and files.

Display Contents of a Specific Directory

If we wish to list the files and subfolders of a certain directory rather than the current directory. In that case, we may use the following syntax to determine the path or directory name:

Example:

The following command will list all the files and sub-folders in the Pictures directory if any exist:


Kali Linux Tree Command

Display Only Directory Listing Through Tree

If we simply want to see the directory listing rather than the underlying files, we can use the "d" flag with the tree command:


Kali Linux Tree Command

Display Full Path Prefix of Files and Folders Using Tree

Using the "f" flag, we can customize the tree flag to show the complete path as a prefix for all the files and folders listed.


Kali Linux Tree Command

Display Size of Files and Folders Using Tree

Using the "s" flag, we can make the tree command print the size of all the files and folders in our directory in bytes.


Kali Linux Tree Command

This helps us determine which items are taking a lot of space on our system and remove the ones that is not needed.

Display read-write Permissions of Files and Folders Using Tree Command

We can view the read, write and delete permissions on the listed files and folders using the "p" flag in our tree command:


Kali Linux Tree Command

So, before we need to perform an operation on a file or folder, we should first understand and maybe alter the permissions we have on that item.

List Folder Content till a Content Level/depth Through Tree

We can use the tree command in order to display the tree to a specific level or depth instead of listing all of the items in our directory. For example, level 1 in the tree command will only display the list of the given folder rather than any of its subfolders. The following is an example of how to use the syntax:

Example

With the "-d" parameter, the following command will only show the subdirectories of the current directory rather than the entire tree.


Kali Linux Tree Command

Tree Help

The tree command is much more useful than the usage we have described. We can learn more about the command by viewing the help of the tree command as follows:


Kali Linux Tree Command

With the help of the flags, we described and also by using combinations of these flags, we can master the tree command even more!







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA