LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 04-01-2015, 09:50 PM   #1
fdzone10
LQ Newbie
 
Registered: Mar 2015
Posts: 12

Rep: Reputation: Disabled
How to list all directories and subdirectories user & group permissions and export to a file


Hi,

I would like to know how to list out all directories and subdirectories' user & group permissions and then export to a file, txt or xls. Thanks.

Last edited by fdzone10; 04-01-2015 at 10:31 PM.
 
Old 04-01-2015, 10:31 PM   #2
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Welcome to LQ!!!

You can simply use ls -alR to get that information.

For exaple:

If you want to list all directories and subdirectories under /home then you can run:

Code:
ls -alR /home >> output.txt
 
Old 04-01-2015, 10:42 PM   #3
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,856
Blog Entries: 36

Rep: Reputation: 456Reputation: 456Reputation: 456Reputation: 456Reputation: 456
This suspiciously looks like a homework question.
 
Old 04-01-2015, 10:46 PM   #4
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
I thought of that but looking at his another post he is engaged in data migration project. So thought he might need a report of the ownership to compare before and after. You have to give benefit of doubt
 
Old 04-01-2015, 10:53 PM   #5
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,856
Blog Entries: 36

Rep: Reputation: 456Reputation: 456Reputation: 456Reputation: 456Reputation: 456
Then I'll ask this of the OP. What is the end goal of doing this type of listing? What is the overall goal you're trying to achieve?

If it's a data migration then I would typically use rsync. First I'd run rsync while users are on the old system. Then I'd use rsync again post migration to copy over any information that may have changed. It also depends on the type of information that is being migrated in this case, so I'm making a lot of assumptions with that blanket statement.

Can you please answer my first two questions, fdzone10?
 
1 members found this post helpful.
Old 04-01-2015, 10:59 PM   #6
fdzone10
LQ Newbie
 
Registered: Mar 2015
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by T3RM1NVT0R View Post
I thought of that but looking at his another post he is engaged in data migration project. So thought he might need a report of the ownership to compare before and after. You have to give benefit of doubt
You're right, I need this info to do the data migration project from Linux to other system platform. Please advise.
 
Old 04-01-2015, 11:05 PM   #7
fdzone10
LQ Newbie
 
Registered: Mar 2015
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sag47 View Post
Then I'll ask this of the OP. What is the end goal of doing this type of listing? What is the overall goal you're trying to achieve?

If it's a data migration then I would typically use rsync. First I'd run rsync while users are on the old system. Then I'd use rsync again post migration to copy over any information that may have changed. It also depends on the type of information that is being migrated in this case, so I'm making a lot of assumptions with that blanket statement.

Can you please answer my first two questions, fdzone10?
List all directories and subdirectories user & group permissions to analyse it and use this information to create the same user & group permissions on other system platform for data migration. Please advise how to do it.
 
Old 04-01-2015, 11:05 PM   #8
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
I have already answered your query. You can get the information you are looking for by running that command and redirecting the output to text file.
 
Old 04-01-2015, 11:06 PM   #9
fdzone10
LQ Newbie
 
Registered: Mar 2015
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sag47 View Post
This suspiciously looks like a homework question.
Not a homework question, just a data migration project.
 
Old 04-01-2015, 11:09 PM   #10
fdzone10
LQ Newbie
 
Registered: Mar 2015
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by T3RM1NVT0R View Post
Welcome to LQ!!!

You can simply use ls -alR to get that information.

For exaple:

If you want to list all directories and subdirectories under /home then you can run:

Code:
ls -alR /home >> output.txt
Thank you. But it cannot show the user & group permissions on each directories, I need to get the info who are owners, who have rwx, rx permission on each directories. please advise.
 
Old 04-01-2015, 11:18 PM   #11
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
The command does show the information about ownership, group assigned, permission assigned to owner, group and others. If you are talking about ACLs then yes it does not show any information about ACLS. For acl you should run the following command:

Code:
getfacl -R /home
The above command will list out ACL (Access Control List) set on each directory / sub directories and effective permission. You can redirect the output to a text file.
 
Old 04-02-2015, 01:49 AM   #12
fdzone10
LQ Newbie
 
Registered: Mar 2015
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by T3RM1NVT0R View Post
The command does show the information about ownership, group assigned, permission assigned to owner, group and others. If you are talking about ACLs then yes it does not show any information about ACLS. For acl you should run the following command:

Code:
getfacl -R /home
The above command will list out ACL (Access Control List) set on each directory / sub directories and effective permission. You can redirect the output to a text file.

Thanks. I just want to get ACL on each directory / sub directories, but not on files. I was wondering how I could do it? Thanks.
 
Old 04-02-2015, 06:56 AM   #13
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,856
Blog Entries: 36

Rep: Reputation: 456Reputation: 456Reputation: 456Reputation: 456Reputation: 456
If you're trying to keep permissions consistent rsync will do that for you. You should use rsync because it was a tool written for data migration.

Code:
rsync -av --rsync-path 'sudo rsync' /local/path/ user@somehost:/remote/path/
You should disable password on sudo for the rsync command during the migration on the remote host (add an entry to /etc/sudoers or /etc/sudoers.d). That command will migrate everything, preserving the permissions and other metadata. See the man page for rsync to see what rsync -a does.
 
1 members found this post helpful.
Old 04-02-2015, 02:49 PM   #14
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
sag47 is right about rsync suggestion. However, if you really want the output for record purpose then you can run the following command:

Code:
ls -alR /home | grep d >> output.txt
In the above command I am listing only the contents which has got d (directory) flag set as on. Remember that the output will contain . and .. directory listing as well. You can do a invert match for them using the following command:

Code:
ls -alR /home/ | grep d | egrep -v '(\.)|(\..)'
However, this will leave any directory which starts with "." as well. So you have to make a choice here how you want it to be.

Edit: There is a drawback to
Code:
ls -alR /home | grep d >> output.txt
it will also show any file which have d in the name. Instead you can use
Code:
ls -alR /home | grep '^d' >> output.txt
. Thanks to sag47 for pointing it out! Still it will show . and .. directories for that you can follow:
Code:
ls -alR /home/ | grep '^d' | egrep -v '(\.)|(\..)'

Last edited by T3RM1NVT0R; 04-02-2015 at 07:52 PM.
 
1 members found this post helpful.
Old 04-10-2015, 12:12 AM   #15
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,856
Blog Entries: 36

Rep: Reputation: 456Reputation: 456Reputation: 456Reputation: 456Reputation: 456
How has your migration gone? Have you tried rsync?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
List files/directories by user permissions dizwell Linux - Security 6 07-03-2012 07:43 PM
[SOLVED] Enforce user and group ownership in subdirectories of a Samba share jillges Linux - Server 1 12-29-2011 03:55 PM
Sort Many Files in Subdirectories into Directories by File Type garyozzy Programming 5 02-15-2011 03:18 PM
Giving user/group permissions to read&write Windows partitions? zaqwe Slackware 3 08-26-2007 11:07 AM
set file permissions for 100 directories & its files cevjr Linux - Security 6 01-06-2005 10:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 04:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration