11

I need to save all of the results of the command tree in a txt file. The objective is to save this data in a data base for later work in php and html.

The main objective is to expose the structure on a web page to determine the structure of the folders.

How can I do this? Any ideas?

Update I found this command on Ask Ubuntu: tree > result.list. It's possible to save the data and result of the command tree to a text file. But, do you have any idea how I can use and read on environment web?

muru
  • 193,181
  • 53
  • 473
  • 722
Edgar Oliveira
  • 235
  • 1
  • 2
  • 8
  • @EdgarOliveira Persistence, patience, and google are your friends. – mchid Feb 03 '16 at 23:53
  • @mchid thank you for the support. My level english isn't very good. But I still improve my language and speech. Where do you advice to learn Linux, for example, on Linux Foundation? – Edgar Oliveira Feb 03 '16 at 23:57
  • Where to learn. I don't know. http://www.theunixschool.com has some good information on how to use certain commands. Also, sometimes blogs and videos help to get familiar with things https://www.youtube.com/user/nixiedoeslinux and http://www.webupd8.org/ – mchid Feb 04 '16 at 00:52

2 Answers2

15

All you have to do is run the following command:

tree -H ./ > result.html

The first part of this command, tree -H ./ will run the tree command and will export the output in HTML format by using the option or "flag", -H ./ . The next part, > result.html will save the output to a file named result.html.

The file will be saved to your current directory.

To view the html page using firefox, run the following command:

firefox ./result.html

Using ./ specifies the current directory because that is where the file has been saved.


How did I figure this out?

I ran the following command:

tree --help

Then, I looked for HTML and I saw there was an option for HTML so I used it and sure enough, it worked.

You can pretty much run any command along with the --help flag to see how to use the command.

You can also view the manual for most applications by using the man command like this:

man tree
mchid
  • 42,315
  • 7
  • 94
  • 147
1

The info that you discovered shows a command that uses redirection (>). This command will send the results of the tree command to a file that you name in the command (result.list). This file can be any name that you determine. This file will be saved in the current directory you are working in unless you type a different path as part of the file name. You can then open this file in your favorite text editor (gedit,vi,emacs) and then do whatever you need with it or to it. Attaching this file to web applications/environments simply requires that you know where the file is and that path is used for attaching purposes.

            Hope this helps Craig 
waltinator
  • 35,099
  • 19
  • 57
  • 93
Craig
  • 127
  • 7
  • 1
    thanks! I didn't know this feature, but now I can see many application for my newbie knowledge :D Analyzing the result this command I can repair which all tabs are multiple the four! ;) – Edgar Oliveira Feb 04 '16 at 00:07