Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-08-2006, 03:31 AM   #16
Registered: May 2006
Location: North England
Distribution: Mandriva
Posts: 64

Original Poster
Rep: Reputation: 15

Originally Posted by timmeke
echo "Current user is: $user";
should do it.
whoami prints the eUID (effective User ID). So, when you "su" to impersonate someone else, the whoami output changes too.

To get the name of the user who owns the file, is slightly different.
You can use your version of "stat" to get the UID and username (if available) (cfr your post of "man stat").

Hi m8,

Thanks for the Info, I need to insert the name on the same line as OWNER so what I plan to do is create a variable based on UID and then in my first SED substitution instead of getting rid of the first "-" regular file symbol of the output from ls -l completely I will replace I it with the variable, that way its on the right line to start with and my second AWK print can be{print "OWNER " $1, $2, $3, $4 }and should look like this.


Thanks for the info.

Old 06-08-2006, 04:47 PM   #17
Registered: May 2006
Location: North England
Distribution: Mandriva
Posts: 64

Original Poster
Rep: Reputation: 15
Hi temmeke, took your advice and came up with this script:

# script to determine permission that owner, group
# and everybody has of a file passed to it
echo "Hello $USER, which file would you like to see permissions on?"
read FILE
stat $FILE |
awk '/Uid:/ {print $2, $5}' |
sed -e 's/[0-9]//g;s/)//g;s/\///g;s/(//g; #Extract Uid and permissions
s/-//1;                                   #then convert permissions
1,9s/x/YES /g;                            #into readable form
1,9s/w/YES /g;                            #and pipe to AWK
1,9s/-/NO /g;                             #to format fields
1,9s/r/YES /g' |                          #and display relevant output
awk 'BEGIN {print "                             READ\t WRITE\t EXECUTE" "\n"}
{print "OWNER   "$10,      "            "$2"\t",$3"\t",$4"\t"}
{print "GROUP   USERS                   "$4"\t",$5"\t",$6"\t"}
{print "EVERYBODY                       "$7"\t",$8"\t",$9"\n"}'
and now I get this

Hello michael.kelly, which file would you like to see permissions on?
                                READ     WRITE   EXECUTE

OWNER   michael.kelly           YES      YES     YES
GROUP   USERS                   YES      NO      YES
EVERYBODY                       YES      NO      YES

[michael.kelly@unix michael.kelly]$

Not bad for a n00b who couldnt even append a line of text to a file a week ago eh?

Works fine, thanks for you help!


Last edited by mike9287; 06-08-2006 at 04:51 PM.


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
Bash shell script - variable magic needed (no idea how to approach this) arrenlex Programming 8 03-02-2006 06:41 PM
permissions - is this the best approach? Chinook Linux - Security 3 01-19-2006 06:38 PM
Best upgrade approach oxman Fedora - Installation 2 12-24-2004 03:08 PM
backup approach ulaoulao Linux - Software 0 10-05-2004 08:03 AM
How do i approach those security advisories vavoem Linux - Security 1 09-11-2004 08:24 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:49 AM.

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