Linux Tree CommandIn Linux, a tree is defined as a recursive directory listing program which generates a depth-indented file's list. Without any parameters, the tree lists the files in the present directory. At the time directory parameters are given, the tree alternately lists each file per directory found in the given directories. When the list of each directory and file is complete, then the tree will return the total number of directories and files listed. Various options are available in order to modify the character which is used in the output and to use color. SyntaxOptions:
Install Tree CommandWe have to install the tree command because, by default, it is not installed. In order to install the tree command on RHEL/CentOS/Fedora Linux, we have to type the following command on the terminal: If we want to install the tree command for Debian / Ubuntu Linux / Mint, then we have to type the following command: If we want to install tree command for Apple OS X, type: How to Use Tree CommandA Tree is a program that exists for Unix and Unix-like systems. It is a recursive directory listing program which generates the depth-indented listing of files. Without any parameters, tree lists the files in the present directory. When the directory parameters are given, tree lists each and every files and directories found in the given directory subsequently. When the listing of files and directories are completed, then the tree returns the total number of directories and files listed. Let's see some examples of the tree command that will help you to understand the tree command: Basic Tree OutputThe most general way of using the tree command: When we type the above command on the terminal, then the output displays the tree structure of our current directory, showing all the files, folders, and sub-folders. Display Contents of a Specific DirectoryIf we want to list the files and subfolders of the particular directory instead of that of the present directory, then we are able to determine the path or directory name via the following syntax: Example: If we want to list all the files and sub-folders in the directory named pictures, then we have to write the following command: Display Hidden Files along with Other Files Using TreeIn the tree command, the list of hidden folders and files does not display in ubuntu. Although, we can use the 'a' flag in order to list them as follows. In the tree, the folders and files which are starting from a '.' are the hidden folders and files. Display Only Directory Listing Through TreeWe can use 'd' flag in order to see the listing of directory but not the underlying files. In order to display only directory listing through tree we have to type the following command on the terminal. Syntax: Display Full Path Prefix of Files and Folders Using TreeUsing 'f' flag, we can customize the tree flag in order to show the full path as prefix for every folders and files list. Syntax: It is mainly useful when we need to know what exists where. Display Size of Files and Folders Using TreeUsing flag 's' tree command, can print the size in terms of bytes of all the folders and files in the directory. Syntax: With the help of the 's' flag, we can check which memory items consume more space on our system and getting rid of needless ones. Display Read-Write Permission of Files and Folders Using TreeIf we want to see the delete, read and write permissions on the listed folders and files, then we can use the 'p' flag. Syntax: Thus, before performing operation on a file and folder, we can first see and edit the permissions that exist on a particular item. List Folder Contents till a Certain Level/depth Though TreeRather than listing each content of our directory, we are able to configure the tree command in order to show the tree to a specific level or path. Such as in tree command the level 1 can only display the list of the given folder instead of any of its subfolder. Syntax: Example This command will only show the sub-directories (using -d flag) of the present directory not the additional expanded tree. Tree HelpThe tree command is a lot more useful than what we have defined. We are able to find the command again with the tree command as follows: Next TopicWine Linux |