0

I want to run a script that will show me all the folders (output to a text file) that the running user can see starting from root, down to the point where it doesn't have the permissions to go any further.

Does anyone have a script for this?

I am running RedHat 6

2 Answers 2

0

Just run tree -d as that user, using either sudo -u or su.

# sudo -u grawity tree -d /run
/run
├── dbus
├── dovecot
├── gdm [error opening dir]
├── httpd
...
3
  • bash: tree: command not found...sorry I am actually running on RedHat!
    – Cheetah
    Commented May 1, 2013 at 15:38
  • I assumed you know how to install additional software. If I remember correctly, RH uses yum as its package manager. Commented May 1, 2013 at 15:40
  • Sorry, I should have mentioned. I want a solution where I don't have to install anything. I work in an environment where it takes forever to get anything installed - hence requesting a script.
    – Cheetah
    Commented May 1, 2013 at 15:42
0

This could be done from the command line using:

tree -d / > textfile.txt 2> /dev/null

while logged into that account. This would provide a long-form directory listing recursively, write the output to textfile.txt and the errors to the blackhole that is /dev/null. If you want to keep the errors remove the 2> redirect. If done from the root account, you can add sudo -u <username> to the beginning of the command to perform the task as another user. If it needs to be a script you could either just drop the command into a shell script, or if you only need to do this yourself and want ease of access, you could make an alias with the command.

Edit: Now that you've added that you're on RHEL, I know of two different ways of handling this. If you don't need to actually draw the tree structure but just want a recursive listing of directories, you can switch tree -d for find / -type d -ls or, were you to have installation priveleges, run yum install tree.

1
  • bash: tree: command not found...sorry I am actually running on RedHat!
    – Cheetah
    Commented May 1, 2013 at 15:39

You must log in to answer this question.

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