LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-07-2012, 10:05 PM   #1
erudite
LQ Newbie
 
Registered: Mar 2012
Posts: 12

Rep: Reputation: Disabled
what are the commands used to see a list showing username and their filename


Hi there..I am completely new to Linux.I am doing internship in a company where my team expects me to do Shdell scripting..I have just started learning.MY first assignment is that in the login server..in a particulao directory, a folder has certain files.when i give "ls -ltr" command it shows the username,filename,time it was created.
All i want to know is that I want to see the list which shows username and their corresponding filename.

What are the commands that are used to do this?
Suggestions would b appreciated.

Thanks
 
Old 03-07-2012, 10:22 PM   #2
elfenlied
Member
 
Registered: Dec 2004
Posts: 83

Rep: Reputation: 8
Code:
for i in `ls`; do echo "$i `stat -c %U $i`"; done
That will output in the following format:
filename owner
 
1 members found this post helpful.
Old 03-07-2012, 10:40 PM   #3
erudite
LQ Newbie
 
Registered: Mar 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
I dont understand this? whats i? whats 'for'..it says "for:command not found" when i executed

Last edited by erudite; 03-07-2012 at 10:47 PM.
 
Old 03-07-2012, 11:03 PM   #4
elfenlied
Member
 
Registered: Dec 2004
Posts: 83

Rep: Reputation: 8
Where are you running this? There is no single command that will just give you those two bits of information, there are several ways to do what you're after but you have to combine several commands to give you the required output.

What operating system are you running ?

Also to answer your questions, "i" is a variable. The for command is a conditional bash statement. It's fairly standard an should work on most *nix shells that I know of.

Last edited by elfenlied; 03-07-2012 at 11:06 PM.
 
Old 03-08-2012, 12:15 AM   #5
erudite
LQ Newbie
 
Registered: Mar 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
this is on the linux server.we use bash shell

'for i in ls -ltr'---> when we use this command the value for i will be the no.of files in the directory?will it automaticallly b set?
 
Old 03-08-2012, 07:01 AM   #6
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
To shorten the command: there is no need to use the ls command for the arguments of the for loop, an asterisk would assemble the same list of files. And as stat accepts more than one file as argument, this can be used directly:
Code:
$ stat -c "%U %n" *
Both ways might have the flaw to fail, if the command line gets to long due to the number of files inside the directory.
 
1 members found this post helpful.
Old 03-16-2012, 08:33 AM   #7
devinwhite717
LQ Newbie
 
Registered: Mar 2012
Posts: 10

Rep: Reputation: 1
linux commands

Here you can find the most used linux commands
 
Old 03-18-2012, 08:35 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
See also
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

Given your original qn, you've been thrown in the deep end.
You really need to start reading those links; use the 1st (Rute tutorial) as a guide, and use the other 2 a references for any cmds mentioned.
 
Old 03-19-2012, 07:05 AM   #9
SecretCode
Member
 
Registered: Apr 2011
Location: UK
Distribution: Kubuntu 11.10
Posts: 562

Rep: Reputation: 102Reputation: 102
To further your learning of bash ...

elfenlied's original command would fail if there are file names with spaces in them. Direct use of stat as suggested by Reuti would address this, but if you wanted to use a for loop this will do it - note the in * and the quotes around $i in the stat command:
Code:
for i in *; do echo "$i `stat -c %U "$i"`"; done
Another solution would be to use find.
Code:
find . -type f -printf "%u %f\n"
This is not as good a solution to your specific requirement, but a very good thing to learn!
 
  


Reply



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
showing the number of strings in the output filename udiubu Programming 3 11-08-2011 12:28 PM
showing emacs filename/buffer in kde panel? lublum1 Linux - General 6 09-21-2008 04:26 AM
Sendmail /try smtp username showing @localdomain ? davidedwardgill Linux - Server 2 06-26-2008 11:39 AM
prstat and ps -ef showing different username binary_0011 Solaris / OpenSolaris 3 11-01-2006 01:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:45 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
Open Source Consulting | Domain Registration