View Full Version : [SOLVED] Get author name of files / folders

May 23rd, 2011, 10:23 PM
I am trying to implement "ls" program in C/C++ and wondering how to reflect "--author" option. I have to include the author name of the file when using it with "-l" option. I searched for it but didn't find anything much helpful. Is this always be the same with current user name (I think not necessarily) which could be easily determined. What should I do or look into?


For all the cases I have tested with standard "ls -l --author", I found that, the user name, group name and author name fields are always same for a specific file. Is it so?

May 24th, 2011, 12:08 AM
Well the user may not be necessarily the same as the group. A user 'foo' may be easily in group 'bar' or even 'root'.

A small snippet from my terminal to illustrate the point:

roccivic@roccivic-pc:~$ mkdir foo
roccivic@roccivic-pc:~$ cd foo
roccivic@roccivic-pc:~/foo$ echo abd > file
roccivic@roccivic-pc:~/foo$ ls -l
total 12
-rw-r--r-- 1 roccivic roccivic 4 2011-05-24 00:22 file
roccivic@roccivic-pc:~/foo$ sudo chown roccivic:root file
[sudo] password for roccivic:
roccivic@roccivic-pc:~/foo$ ls -l
total 12
-rw-r--r-- 1 roccivic root 4 2011-05-24 00:22 file

June 2nd, 2011, 05:17 PM
Yes, I've also discovered that later as well, but what can I do?

June 12th, 2011, 04:21 PM
Sorry to bump, but any idea? anyone? Thanks... :popcorn:

June 12th, 2011, 05:40 PM
Take a look at the ls source code. It may help you. It is in the coreutils package.

June 12th, 2011, 07:16 PM
Take a look at this -> http://www.gnu.org/s/hello/manual/libc/Attribute-Meanings.html

June 19th, 2011, 05:04 AM
still no luck :(

June 19th, 2011, 06:42 AM
Finally, digging through the ls source code I've found that, but got disappointed to see what that does :(

line #3000

if (print_author)
p += format_user (p, f->stat.st_author);
line #2904

format_user (char *buffer, uid_t u)
char const *name = (numeric_ids ? NULL : getuser (u));
if (name)
sprintf (buffer, "%-8s ", name);
sprintf (buffer, "%-8lu ", (unsigned long) u);
return strlen (buffer);
}I wasted much time wondering where it comes from :popcorn: