Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

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
...
share|improve this answer
    
bash: tree: command not found...sorry I am actually running on RedHat! –  Cheetah May 1 '13 at 15:38
    
I assumed you know how to install additional software. If I remember correctly, RH uses yum as its package manager. –  grawity May 1 '13 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 May 1 '13 at 15:42

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.

share|improve this answer
    
bash: tree: command not found...sorry I am actually running on RedHat! –  Cheetah May 1 '13 at 15:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.