LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
Search this Thread
Old 09-29-2011, 05:12 AM   #1
drone01
LQ Newbie
 
Registered: Sep 2011
Posts: 4

Rep: Reputation: Disabled
Unhappy How to sort a list in decending order


Use ls -l and grep to find all the files in /etc that were last modified in 2010. Sort this list in descending order of size and send the output to s7.

#I have spent hours looking for the answer to this.
 
Old 09-29-2011, 05:24 AM   #2
snooly
Member
 
Registered: Sep 2011
Posts: 124

Rep: Reputation: Disabled
If you look at "man ls", you will see that the -t option lets you sort by modification time, and -S is for sorting by file size. You could pipe the results from ls into grep, searching for the pattern 2010.

What is s7?
 
Old 09-29-2011, 05:27 AM   #3
drone01
LQ Newbie
 
Registered: Sep 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by snooly View Post
If you look at "man ls", you will see that the -t option lets you sort by modification time, and -S is for sorting by file size. You could pipe the results from ls into grep, searching for the pattern 2010.

What is s7?
s7 is the name of file to direct the output to. i'll try it now and get bacK asap
 
Old 09-29-2011, 05:28 AM   #4
snooly
Member
 
Registered: Sep 2011
Posts: 124

Rep: Reputation: Disabled
Quote:
Originally Posted by drone01 View Post
s7 is the name of file to direct the output to. i'll try it now and get bacK asap
Okay it sounds like you know what you are doing. I predict success very soon!
 
Old 09-29-2011, 05:34 AM   #5
drone01
LQ Newbie
 
Registered: Sep 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by drone01 View Post
s7 is the name of file to direct the output to. i'll try it now and get bacK asap
i used: ls -lts /etc | grep '2010' | sort -n > s7

still didnt work
 
Old 09-29-2011, 05:35 AM   #6
snooly
Member
 
Registered: Sep 2011
Posts: 124

Rep: Reputation: Disabled
Quote:
Originally Posted by drone01 View Post
i used: ls -lts /etc | grep '2010' | sort -n > s7

still didnt work
"didn't work" isn't enough information. you have to say what happened and in what way it didn't meet your expectations. Also you need to read the ls man page more carefully. -s is not the same as -S.

Last edited by snooly; 09-29-2011 at 05:37 AM.
 
Old 09-29-2011, 05:41 AM   #7
deep27ak
Senior Member
 
Registered: Aug 2011
Location: Bangalore, India
Distribution: rhel 5x,6.0,6.2, centOS 5x,6.0,6.2
Posts: 1,188
Blog Entries: 4

Rep: Reputation: 220Reputation: 220Reputation: 220
Cool

try this command

Quote:
#ls -lS /etc/
this will sort all the files in descending order

Best of Luck
 
Old 09-29-2011, 05:58 AM   #8
drone01
LQ Newbie
 
Registered: Sep 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thumbs up

[QUOTE=deep27ak;4485417]try this command



this will sort all the files in descending order

Best of Luck[/QUOTE



i have used: ls -lS /etc | grep '2010' | sort > s7 &
ls -lts /etc | grep '2010' | sort > s7

works the same magic Thank you very much guys for help. I just have to see the tutor to find out whats happening.
 
Old 09-29-2011, 06:07 AM   #9
snooly
Member
 
Registered: Sep 2011
Posts: 124

Rep: Reputation: Disabled
the ls -S command already sorted the files, so you don't need the last sort command.

ls -lts is just wrong for the problem you're trying to solve.

Last edited by snooly; 09-29-2011 at 06:10 AM.
 
Old 09-29-2011, 06:10 AM   #10
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Most likely you have to specify which is the field to use for sorting (size is usually the 5th field in the output of ls). Take a look at option -k of the sort command. Anyway, you don't need to pipe the results to sort if you already use the -S option of ls, unless you use ls -lR to descend recursively into subdirectories (beware the question is "to find all the files in /etc").
 
  


Reply


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
List 4 names from users list and output them to fbusers in numbered ascending order? fezzie Programming 4 02-10-2010 01:05 PM
Can I use GNU sort to sort one field in order, another in reverse? zombieite Linux - Newbie 4 04-27-2009 12:23 AM
How do I do filtering in Perl (keep sort order and sort again by another means)? RavenLX Programming 9 12-19-2008 10:12 AM
Suggestion: Let's sort them in a,b,c... order fuelinux LQ Suggestions & Feedback 8 01-20-2008 10:35 AM
Sort order in nautilus Patrick K Ubuntu 4 06-12-2007 08:53 PM


All times are GMT -5. The time now is 07:09 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration