UNIX command to display Owner,Group,Root and Subdirectories list

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers UNIX command to display Owner,Group,Root and Subdirectories list
# 1  
Old 03-19-2016
UNIX command to display Owner,Group,Root and Subdirectories list

Hi Team,

Am a newbie to Unix. As I would like to see the Server Name,Owner Name ( not numeric form), Group Name ( not numeric ID), ROOT path.

I would like to send this list as an attachment to my personal mail. Can any one please help me out to to resolve this .

Here is the sample result which am expecting
Code:
Eg :   Server_Name   OWNER    Group     Path ( which shows the entire path)
        --------------------------------------------------------------------------------
           hgr0218        INF         ABC       /home/abc
           hgr0218        NHC        HBC      /home/abc/config
           hgr0218        INF         ABC      /home/abc/bin
....

Thanks,
Vasuv

---------- Post updated at 08:29 PM ---------- Previous update was at 07:56 PM ----------

Code:
find . -type d -exec ls -ld {} \; | awk '{print $3,$4,$9}' | egrep  -v "^oasitqtc"


using this commad am able to see the list but unable to copy the entire list. Can any one advise how to coy the entire list and how can I this copies to list to my mail.

Please advise.

Last edited by Scrutinizer; 03-19-2016 at 01:46 PM.. Reason: Additional code tags
# 2  
Old 03-19-2016
Copy to where? To mail it, pipe it into the mail command.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 03-19-2016
Hi , I am able to see the list. as it's a big list ( around 10k lines) i am not sure how to copy the entire result set.

So I would like to create a file "Test.txt' and would like to move this result set to test.txt and need to send the test.txt file to my mail.

Please advise.

Thanks

---------- Post updated at 10:42 PM ---------- Previous update was at 10:28 PM ----------

Hi Rudi,

Here is the command am using to find the list
Code:
find . -type d -exec ls -ld {} \; | awk '{print $3,$4,$9}' | egrep  -v "^oasitqtc"

here is the output am getting
Code:
etlndw etlndw ./inform/ndw/ExtLdr/NULOGX
 etlndw etlndw ./inform/ndw/ExtLdr/QAR
 etlndw etlndw ./inform/ndw/ExtLdr/PFSS
 etlndw etlndw ./inform/ndw/ExtLdr/OAR
 etlndw etlndw ./inform/ndw/ExtLdr/SLSTRNS
 inf91etf informat ./inform/ndw/ExtLdr/MDM
 etlndw etlndw ./inform/ndw/ExtLdr/TPM
 etlndw informat ./inform/ndw/ExtLdr/DSHPD
 etlndw informat ./inform/ndw/ExtLdr/MDMSIPS
...................

like this I have 10k records

I would like to copy this list into an excel sheet/.txt by giving file name as "TEST.txt/Test.xlsx" and send this file as an attachment to my Mail.

Please advise.
# 4  
Old 03-19-2016
Quote:
Originally Posted by vasuvv
I would like to copy this list into an excel sheet/.txt by giving file name as "TEST.txt/Test.xlsx" and send this file as an attachment to my Mail.
As RudiC already has told you: pipe it into mail! There is no need for an intermediary file:

Code:
find <...your complete command...> | mail -s "Subject Text" recipient@host

This will generate the list, put it into a mail, label the mail with the subject text "Subject Text" and send it to recipient@host.

But i would like to go over your command itself, because it is unnecessary complicated and will tax your system a lot more than it should.

First:
Code:
<..> | awk '{print $3,$4,$9}' | egrep  -v "^oasitqtc"

The egrep is completely unnecessary because awk can do that itself:

Code:
<..> | awk '! /^oasitqtc/ {print $3,$4,$9}'

Instead of producing all lines first and filter out the ones you are not interested in you start with only the ones you are interested in in first place.

Next:
Code:
find . -type d -exec ls -ld {} \; | <...>

This makes find first produce a list of directory names and then invoke the ls command once for every directory found that way. There is a built-in functionality in find which does about the same:

Code:
find . -type d -ls | <...>

The format is a little different (it is like ls -ails) which means you will have to modify the awk-command following a little bit. But this will definitely save the system some thousands of unnecessary calls to ls.

Next:
Code:
find . -type d -exec ls -ld {} \; | awk '{print $3,$4,$9}' | egrep  -v "^oasitqtc"

As i take it you are searching for directories owned (or, in your case: NOT owned) by a specific user ("oasitqtc"). For this find also has a built-in provision: the -user clause. It takes a user name (or user ID) and presents only the files/directories found that are owned by that user. For instance:

Code:
find . -type d -name "abc*" -user myuser

will find in the current directory all directories with names starting with "abc" and owned by user "myuser". You will have to reverse that, which is also possible (notice the "!", which is a logical NOT), and you do neither awks ability to filter out lines nor egrep to do the same:

Code:
find . -type d ! -user oasitqtc -ls | awk '{print ...... }'

Again: because of the different output format you will have to modify the awk-statement to only leave the necessary information. If you have GNU-find (like if you work on a Linux-System) you could use the -printf-clause and you would not need awk at all.

I hope this helps.

bakunin
These 3 Users Gave Thanks to bakunin For This Post:
# 5  
Old 03-19-2016
Note: technically the -ls option to find is not part of Posix, although it will be an option in most finds...

A good alternative is to use:
Code:
find . -type d -exec ls {} +

Which really is much faster than \;

and this can also be combined with the ! -user option as suggested by Bakunin...
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 03-20-2016
Hi.

Regarding email enclosures and attachments, from a recent security newsletter:

--Malicious Macros in Word Documents
(March 14, 2016)
Malicious macros embedded in Word documents are increasingly being used
as an attack vector. Researchers have now found a variant in which the
documents use fileless malware; in other words, they place malware
directly into the device's memory. The attack was delivered through
targeted spam that contains a malicious document. If the macros are
permitted to run, they use PowerShell to gather information about the
computer. The malware looks for machines where financial transactions
are conducted.


This is a reason I don't look at emails that contain Word, Excel, etc. documents. The OP may be comfortable looking at such email from himself or colleagues, but I would not be. Text is, in my opinion, the best and only kind of attachment allowed.

Best wishes ... cheers, drl
This User Gave Thanks to drl For This Post:
# 7  
Old 03-20-2016
Excel will gladly open .csv files (usually "," delimited) or .txt file (tab) delimited.
drl pointed out why it is a security no-no to try using proprietary windows formats that support embedded program text like VB - that will execute when opened.

For example:

Code:
uuencode file.you.made file.txt | mailx -s 'see attached '  somebody@mycompany.com

This User Gave Thanks to jim mcnamara For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List files whose owner or group is numeric

I want to add a condition is my find command to include files/sub-directory whose owner or group is all numeric number. My current find command is find . \( -user root -o -user soham\) -type f -exec ls -l {} \; 2>&1 ---------- Post updated at 10:20 AM ---------- Previous update was at... (5 Replies)
Discussion started by: Soham
5 Replies

2. Emergency UNIX and Linux Support

To identify the group owner

If I have to identify the group owner of an AIX group, what is the command to be used. Example: there is an mqadm group, how do I find the owner of this group? Please help. (6 Replies)
Discussion started by: ggayathri
6 Replies

3. UNIX for Dummies Questions & Answers

UNIX - command to count number of files in subdirectories

I have a folder named test/ and under that I have multiple directories and in each of the directory I have multiple log files. I want to know how many files exists under each sub directory. test |--quanrantine |--logfile1 |--logfile2 |--spooling |--logfile1 ... (4 Replies)
Discussion started by: ravikirankethe
4 Replies

4. UNIX for Dummies Questions & Answers

Creating a file where the owner and group is not root

Hi, I'm the root user on my computer, but I'm writing a script that does a lot of file handling. Every time I create a file or directory it automatically requires root privileges. Is there a way I can just create a file that the user can access without a password? For example in my script I... (20 Replies)
Discussion started by: jdilts
20 Replies

5. AIX

Unix root directory owner wrong AIX 5.3

The a chown was done and instead of using ./ a / was used and root ownership files got changed. I need to change the ownership of the files/directory back - backups are not working and I am concerned a reboot will not be successful. Can anyone provide the ownership of these files/directories... (6 Replies)
Discussion started by: spike1
6 Replies

6. UNIX for Dummies Questions & Answers

How to display only Owner and directory/sub directory names under particular root

hai, I am new to Unix, I have a requirement to display owner name , directory or sub directory name, who's owner name is not equal to "oasitqtc". (here "oasitqtc" is the owner of the directory or sub directory.) i have a command (below) which will display all folders and sub folders, but i... (6 Replies)
Discussion started by: gagan4599
6 Replies

7. UNIX for Advanced & Expert Users

How UNIX admin set up this? how files of 744 of other owner can be removed by another owner?

Hi all, We have some files are under 744 permissions and the the owner is say owner1 and group1. Now we have another user owner2 of group2, owner2 can remove files of the owner1 and the permission of those files are 744, unix admin told us he did some config at his side so we can do that. ... (14 Replies)
Discussion started by: TheGunMan
14 Replies

8. Shell Programming and Scripting

to parse a directory and its subdirectories and find owner name of files

hi all, i need to capture all the files in a directory and its subdirectories that have owner name different than the root owner. for one file it is " stat -c %U filename " but i need to search for each and every file and record it. thanks in advance (14 Replies)
Discussion started by: vyasa
14 Replies

9. UNIX for Dummies Questions & Answers

ls command to list recursively ONLY subdirectories

:confused: ls -dlRr I've tried different combinations of the ls command using the above-mentioned options but none of them are giving me the output I am looking for. Objective: To get a recursive listing of all subdirectories from a particular starting point. For example, if my starting... (5 Replies)
Discussion started by: HLee1981
5 Replies
Login or Register to Ask a Question