8

I was learning about virtual environments and projects. While watching videos I encountered 'tree command I installed tree and then run it. But it is not working on other partition of my HDD other than / partition.

When I use tree in ~/Documents, I get desired results

$ tree -d    
.
├── Desktop
└── Fix ‘No WiFi Adapter Found’ for HP Laptops with Ubuntu 18.04 _ UbuntuHandbook_files

2 directories

But when I use it in other partition, I get

sandeep@sandeep-HP-Laptop-15q-ds0xxx:/media/sandeep/sandeep files$ tree -d
. [error opening dir]

0 directories
3
  • 1
    How did you install tree? Is it a snap package?
    – Kulfy
    Commented Oct 5, 2019 at 15:09
  • @Kulfy I installed it by sudo snap install tree Commented Oct 7, 2019 at 11:56
  • could it be an issue of reading rights? tree -d needs reading rights, so if you don't had then -> access denied
    – damadam
    Commented Oct 14, 2019 at 11:11

4 Answers 4

13

I got the same error. Here's what I did to resolve it:

$ sudo snap remove tree
$ rm -rf $HOME/tree
$ sudo apt-get install tree
$ exec -l $SHELL  # <= restart shell

Over time, I've found that snap causes a lot of issues.

This is just one example.

3
  • Shouldn't that be "rm -rf $HOME/snap/tree" ? Commented Oct 25, 2020 at 23:34
  • Thanks. It worked for me.
    – Maf
    Commented Apr 25 at 8:30
  • Restart the shell or it will look for /snap/bin/tree...
    – Martin P.
    Commented 2 days ago
9

TL;DR

  1. If you want to continue using snap version of tree,

    • Either connect removable media to snap using
      snap connect tree:removable-media
      
    • Or change mount point of the device. See below for details
  2. Alternatively use deb version of tree which can be installed using APT.


Longer version:

Whenever a partition/removable media is mounted, the target point is usually /media/USER/UUID. But as per limitations of Snap, Snap applications can't guarantee the access of directories/files outside of current user's $HOME and that include directories such as /media and even /etc. From zyga's post:

  • The $HOME directory of the user must match /home/*. Other directories are not supported yet. In particular /home/subdir/user is also not supported.

  • any installation where the user’s home is not available if they're not logged in, is not yet supported. This includes:

    • installations using automount
    • ecryptfs and similar tech that unencrypt the $HOME directory (or partition) only while the user is logged in

Note here “not supported” does not mean “doesn’t work”. Some things might not work, but also some sequences of events might result in a user not being able to access their data.

However, tree that is installed via APT can access those (DEBs don't have such limitations). So, if you need tree to work in other partitions, either install tree using APT. For that, run

sudo apt install tree

Or mount the partition in $HOME. For mounting a partition, you can use either mount command or edit /etc/fstab.

  • If using, mount,

    • Create a directory in any subdirectory of $HOME, for example, test in ~/Desktop

      mkdir ~/Desktop/test
      
    • mount works only with sudo privileges, therefore, run

      sudo mount /path/of/partition/ ~/Desktop/test
      

      (Replace /path/of/partition/ with the partition/device path, for example, /dev/sda3)

This won't automatically mount partition in that folder. Thus if you mount and unmount partition again and again, the command needs to be re-run.

  • If editing /etc/fstab:

    • Obtain UUID using

      blkid /path/of/partition
      

      (Replace /path/of/partition/ with the partition/device path, for example, /dev/sda3)

    • Open /etc/fstab with sudo privileges using a text editor such as nano and add this line:

      UUID Mount_point Partition_type
      

      where UUID is obtained from the previous command, mount point is ~/Desktop/test (lets say) and partition type is the type of partition such as ntfs or ext4.

This automatically mounts partition in the given mount point even after just a tap in Nautilus.

Once you're done you can use tree with sudo privileges, since both will mount the partition with sudo privileges and hence owner would be root.

0

I'm a novice learning about ubuntu and linux today. My teacher showed me how to make directories using the:

mkdir -p mydir/mysubdir2/mysubdir3

and then using the tree command to get an overview that it was done. However, I didnt have the tree command installed, so I got it installed through "sudo apt install tree" but got the same error as you when I tried "tree mydir" from the directory I created them.

I played around and saw that I forgot an "/" at the end, so if I wrote "tree mydir/" it worked like a charm.

Not sure if that helped, but I hope so! :)

0

sandeep@sandeep-HP-Laptop-15q-ds0xxx:/media/sandeep/sandeep files$ tree -d . [error opening dir]

0 directories

I got the same issue, and used "sudo tree" and it showed all the folders and files, may be some folders in it required root user access to open it. Please try it on.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .