Tree Command not working in some directories
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.
TL;DR
-
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
- Either connect removable media to snap using
-
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 ~/Desktopmkdir ~/Desktop/test
-
mount
works only withsudo
privileges, therefore, runsudo 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
withsudo
privileges using a text editor such asnano
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
.