Get ownership info from LS


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get ownership info from LS
# 1  
Old 08-19-2009
Get ownership info from LS

Hi,

When I do the ls-ld command for example like this:

# ls -ld /Applications

I get an output like this:

drwxrwxr-x+ 114 root admin 3876 18 Aug 14:04 /Applications

I need to somehow use sed to put the ownership into a format like this:

root:admin

So basically remove everything in the string except for "root admin" and then replace the 2 spaces (I think? It might be one, not sure) between root and admin with a colon. And this needs to work for users other than root/admin, for stuff like this too:

drwx------+ 18 pcwiz staff 612 19 Aug 16:26 /Users/pcwiz/Desktop

Thanks
# 2  
Old 08-19-2009
Quote:
Originally Posted by pcwiz
Hi,

When I do the ls-ld command for example like this:

# ls -ld /Applications

I get an output like this:

drwxrwxr-x+ 114 root admin 3876 18 Aug 14:04 /Applications

I need to somehow use sed to put the ownership into a format like this:

root:admin

So basically remove everything in the string except for "root admin" and then replace the 2 spaces (I think? It might be one, not sure) between root and admin with a colon. And this needs to work for users other than root/admin, for stuff like this too:

drwx------+ 18 pcwiz staff 612 19 Aug 16:26 /Users/pcwiz/Desktop

Thanks


I would use awk...
Code:
# ls -ld /Applications | awk '{ print $3 }'

# 3  
Old 08-19-2009
Quote:
Originally Posted by robsonde
I would use awk...
Code:
# ls -ld /Applications | awk '{ print $3 }'

Or even
Code:
ls -ld /Applications | awk 'BEGIN { OFS=":"}  { print $3,$4 }'

Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Ownership changes

I have 2 Linux servers and 1 windows server. One Linux server has an NSF share which points to the windows server. The other Linux server rsyncs any data to the other Linux server containing the windows share. My issue is that everytime the Linux administrator rsync data to the linux server... (12 Replies)
Discussion started by: Lace0047
12 Replies

2. UNIX for Advanced & Expert Users

retain ownership

Hi, I have a script which transfers files/directories from one HP unix to another HP unix server using SCP but i need to retain ownership of files/folders same as source server my script is as follows cd /sasdata/TR_CNTO328/C0328T07/Dry_Run_1/Macros find . -type d -newer . -exec scp -pr {}... (6 Replies)
Discussion started by: tushar_spatil
6 Replies

3. UNIX for Dummies Questions & Answers

Ownership question

Hi there, Complete Newbie here so any help would be so appreciated! :) I've set up a test directory and am trying to figure out out how to ensure that all new files will remain owned by the directory owner... not the creator of the file?? (3 Replies)
Discussion started by: CasperQuiet
3 Replies

4. UNIX for Dummies Questions & Answers

changing ownership?

how would i change ownership of file1 so the user NATE gets ownership of the file? (1 Reply)
Discussion started by: trob
1 Replies

5. Shell Programming and Scripting

To change the ownership at one shot

i have a directory in which i have Multiple files: Following are they==== -rw-r--r-- 1 root root 886 Jan 21 16:38 trunkn.xsd -rw-r--r-- 1 root root 244 Jan 21 16:38 trunknameCache.xml -rw-r--r-- 1 root root 1240 Jan 21 16:38 subscribercache.xsd -rw-r--r-- 1 root ... (1 Reply)
Discussion started by: Aditya.Gurgaon
1 Replies

6. Shell Programming and Scripting

Why the cp keeps the original ownership?

I want to copy a file from another user to my owner directory, and want to change the ownership to my account. in jung's directory: -rwxr-xr-x 1 jung smart 23 Dec 1 2005 .runme cp /home/jung/runme . under my directory: -rwxr-xr-x 1 jung smart 23 Dec 1... (1 Reply)
Discussion started by: freelong
1 Replies

7. UNIX for Dummies Questions & Answers

precompressing and ownership

I'm looking for a way to create preprocessed .gz files of static pages to serve up to those browsers that can accept them. I know I can use: gzip -c --best index.html > index.html.gz to create the .gz file _and_ keep the original. What's the proper command line way to run that on each... (2 Replies)
Discussion started by: dheian
2 Replies

8. UNIX for Advanced & Expert Users

/etc ownership was changed via chown

Hello all: I have a couple of boxes located in New York, both running SunOS 5.6. I, unfortunately, am located in Pittsburgh and do not have console access to these boxes. A co-worker was attempting to build a user account in one of these boxes, and mistakenly did a: chown username * ... (5 Replies)
Discussion started by: cdunavent
5 Replies

9. Shell Programming and Scripting

help regarding file ownership

hi friends,i have a doubt,if there is a file for which i have only read access then is there any way to execute it,plz reply soon (5 Replies)
Discussion started by: amit007
5 Replies

10. UNIX for Dummies Questions & Answers

ownership of files

Hi, While changing ownerships from the root on a server i'm managing, i typed chown -R username:users * and it changed all ownership to username. Can someone tell me if there is someway I can set things back the way they were before? I can't even su username from the root. Am I going to just... (4 Replies)
Discussion started by: szhu
4 Replies
Login or Register to Ask a Question