Finding the modified timestamp of files from the piped output of du command | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Finding the modified timestamp of files from the piped output of du command

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-14-2013
kraljic kraljic is offline
Registered User
 
Join Date: Oct 2011
Last Activity: 7 July 2014, 1:30 AM EDT
Posts: 69
Thanks: 64
Thanked 1 Time in 1 Post
Finding the modified timestamp of files from the piped output of du command

Version Info
+++++++++++++++

RHEL 5.4


Since ls command lists file sizes in Bytes which can be long I use du command like below.

I have run the du command for the below files as shown below.
But I want pipe this output to ls command just to see the modified timestamp for these files.
How can I do this ?





Code:
$ du -sh *.dmp
1.4G    expdp_src_message_01.dmp
1.5G    expdp_src_message_02.dmp
1.5G    expdp_src_message_03.dmp
9.7M    exp_metadata_2013_05_10.dmp
1.5M    exp_OAT_270513_01.dmp
1.7G    exp_OAT_270513_02.dmp
456M    exp_OAT_270513_03.dmp
1.3G    exp_OAT_2705131_01.dmp
57M     exp_OAT_2705131_02.dmp
902M    exp_OAT_2705131_03.dmp
372K    RFDNS_BRNT_HK_OAT_01-codes.dmp
388K    RFDNS_BRNT_HK_OAT_01-TABLES-CodeSJune7.dmp
1.7M    RFDNS_BRNT_HK_OAT_01-TABLES.dmp
1.7M    RFDNS_BRNT_HK_OAT_01-TABLESNV.dmp
151M    TABLES-CodeSJune7.dmp

Sponsored Links
    #2  
Old 06-14-2013
hergp hergp is offline Forum Advisor  
Problem Eliminator
 
Join Date: Jan 2010
Last Activity: 22 July 2014, 4:07 AM EDT
Location: Vienna, Austria
Posts: 789
Thanks: 18
Thanked 167 Times in 149 Posts
Why not use the -h option of the ls command? It gives you the size in "human readable form", for example:


Code:
$ ls -lh
total 122M
-r--r--r--. 1 install install 60M Jul 13  2012 VMwareTools-8.6.0-446312.tar.gz
-r--r--r--. 1 install install 63M Dec 20 15:23 VMwareTools-9.0.0-782409.tar.gz

The Following User Says Thank You to hergp For This Useful Post:
kraljic (06-14-2013)
Sponsored Links
    #3  
Old 06-14-2013
kraljic kraljic is offline
Registered User
 
Join Date: Oct 2011
Last Activity: 7 July 2014, 1:30 AM EDT
Posts: 69
Thanks: 64
Thanked 1 Time in 1 Post
Thank You hergp.
Just didn't think of -h option. I always thought h option in ls gives the output in MB.

Regarding my original question :
In future, If i want to pipe the second column of the output to another command as shown in du command's output above , what should I do ?
    #4  
Old 06-14-2013
hergp hergp is offline Forum Advisor  
Problem Eliminator
 
Join Date: Jan 2010
Last Activity: 22 July 2014, 4:07 AM EDT
Location: Vienna, Austria
Posts: 789
Thanks: 18
Thanked 167 Times in 149 Posts
One way would be

Code:
some_command | awk '{ print $2 }' | another_command

The Following User Says Thank You to hergp For This Useful Post:
kraljic (06-14-2013)
Sponsored Links
    #5  
Old 06-14-2013
kraljic kraljic is offline
Registered User
 
Join Date: Oct 2011
Last Activity: 7 July 2014, 1:30 AM EDT
Posts: 69
Thanks: 64
Thanked 1 Time in 1 Post
Sorry to bring this thread back again for this trivial thing.
I was testing the awk command you mentioned to pipe the second column of the du output to ls command.

awk command returned the correct dumpfiles (second column) as shown above.

Code:
$ du -sh *.dmp | awk '{ print $2 }'
expdp_src_message_01.dmp
expdp_src_message_02.dmp
expdp_src_message_03.dmp
exp_metadata_2013_05_10.dmp
exp_OAT_270513_01.dmp
exp_OAT_270513_02.dmp
exp_OAT_270513_03.dmp
exp_OAT_2705131_01.dmp
exp_OAT_2705131_02.dmp
exp_OAT_2705131_03.dmp
RFDNS_BRNT_HK_OAT_01-codes.dmp
RFDNS_BRNT_HK_OAT_01-TABLES-CodeSJune7.dmp
RFDNS_BRNT_HK_OAT_01-TABLES.dmp
RFDNS_BRNT_HK_OAT_01-TABLESNV.dmp
TABLES-CodeSJune7.dmp

But when I piped it to ls command , it was returning lots of files which weren't expected like .log files, .dmp.gz file,..etc

Code:
du -sh *.dmp | awk '{ print $2 }' | ls -alrt

Sponsored Links
    #6  
Old 06-14-2013
Scott's Avatar
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 25 July 2014, 12:23 AM EDT
Location: Zürich
Posts: 8,421
Thanks: 328
Thanked 1,028 Times in 899 Posts
ls doesn't read it's input from standard input in that way. For that you would need to use xargs or a loop. But why is all of that different than just ls -lrt *.dmp ? i.e. what purpose does du serve here?
The Following User Says Thank You to Scott For This Useful Post:
kraljic (06-14-2013)
Sponsored Links
    #7  
Old 06-14-2013
kraljic kraljic is offline
Registered User
 
Join Date: Oct 2011
Last Activity: 7 July 2014, 1:30 AM EDT
Posts: 69
Thanks: 64
Thanked 1 Time in 1 Post
Thanks Scott.
Yes. hergp already advised me to use ls with -h option for this.
But I just wanted to see how the output for awk command can used as an input for ls command.

Thank you hergp. Thank you all.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Can't Output Piped Perl In-line command to a File ConcealedKnight Shell Programming and Scripting 2 02-14-2013 11:29 PM
How to get a filename modified by attaching modified timestamp Ruks Shell Programming and Scripting 16 06-03-2009 08:46 AM
Finding files which are modified few mins ago rajus19 Shell Programming and Scripting 3 08-16-2007 08:32 AM
Finding out the last modified time for files kumariak Shell Programming and Scripting 3 10-18-2005 02:11 PM
Finding modified files rhayabusa UNIX for Dummies Questions & Answers 2 12-16-2004 12:48 PM



All times are GMT -4. The time now is 01:15 AM.