Tutorial 5 - Question 10
Moderator: drgrussell
Tutorial 5 - Question 10
ls grep and sort - Use ls -l and grep to find all the files in /etc that were last modified in Jun. Sort this list in descending order of size and send the output to s7.
I am having trouble getting “Passed” this question. My listing shows it’s sorted from the largest to smallest file size and saved in s7 but I am still getting “Failed”. I have tried variations of all the following with no success.
ls –l /etc | grep ‘Jun’. | sort –nrk 5n,5 > s7
ls –l /etc | grep “Jun”. | sort –nrk 5n,5 > s7
ls –l /etc | grep ‘Jun’. | sort –k 5n,5 | tac > s7
ls –a /etc | grep ‘Jun’. | sort –nrk 5n,5 > s7
ls –l /etc | grep ‘Jun’. | grep ‘2014’. | sort –nrk 5n,5 > s7
ls –l /etc | grep ‘Jun’. | grep ‘2014’. | sort –k 5n,5 | tac > s7
Should it be only Jun 2014 or does that not matter? Should hidden files be included?
Any suggestions would be appreciated. Thank you.
I am having trouble getting “Passed” this question. My listing shows it’s sorted from the largest to smallest file size and saved in s7 but I am still getting “Failed”. I have tried variations of all the following with no success.
ls –l /etc | grep ‘Jun’. | sort –nrk 5n,5 > s7
ls –l /etc | grep “Jun”. | sort –nrk 5n,5 > s7
ls –l /etc | grep ‘Jun’. | sort –k 5n,5 | tac > s7
ls –a /etc | grep ‘Jun’. | sort –nrk 5n,5 > s7
ls –l /etc | grep ‘Jun’. | grep ‘2014’. | sort –nrk 5n,5 > s7
ls –l /etc | grep ‘Jun’. | grep ‘2014’. | sort –k 5n,5 | tac > s7
Should it be only Jun 2014 or does that not matter? Should hidden files be included?
Any suggestions would be appreciated. Thank you.
Re: Tutorial 5 - Question 10
I understand your frustration but seems like you are placing the "grep" and the "sort" commands in the wrong places, you most likely would need to switch their positions, and the year is not being asked so you shouldn't worry about it. I mean I don't want to sound too savy on this matter but anyway, try the following:
ls -l /etc | sort -k5nr | grep June > s7
And see what happens with that.
Good luck
ls -l /etc | sort -k5nr | grep June > s7
And see what happens with that.
Good luck
Re: Tutorial 5 - Question 10
I am very sorry but I think I also did it wrong in my last reply. The command should be:
ls -l /etc | grep Jun | sort -k5nr > s7
So please forget my first reply and try this one instead
ls -l /etc | grep Jun | sort -k5nr > s7
So please forget my first reply and try this one instead
Re: Tutorial 5 - Question 10
Also I don't think you need the apostrophes ' ' sourrounding Jun or the dot. at the end of it.
Good luck
Good luck
Re: Tutorial 5 - Question 10
Thank you again! Your suggestion of switching the 2 commands around really helped. I finally got it to work, and the apostrophes and dot weren’t necessary as you suggested. Thanks so much! 

Re: Tutorial 5 - Question 10
Hi
I tried to do it that way (ls -l | grep Jun | sort -k5nr > s7) and it didn't work. My Question is why does it not work that way and why does sort have to come first?
Either i output all files last modified in June and sort them afterwards
or
i sort the list by size first and pick then the ones last modified in June
Isn't it the same or am I missing something? Is there a Hierarchy in using pipes?
I tried to do it that way (ls -l | grep Jun | sort -k5nr > s7) and it didn't work. My Question is why does it not work that way and why does sort have to come first?
Either i output all files last modified in June and sort them afterwards
or
i sort the list by size first and pick then the ones last modified in June
Isn't it the same or am I missing something? Is there a Hierarchy in using pipes?
-
- Site Admin
- Posts: 426
- Joined: Sat Feb 12, 2005 8:57 pm
- Are you a robot or a human?: Human
Re: Tutorial 5 - Question 10
The things sort sorts on generates an order, based on what is around it. If you filter out those things first the order could be slightly different, especially where the order is undefined (such as ordering by size and all are the same size). Ultimately both methods form the right answer, it is simply that the check button expects just one of the possibilities.
Call it a weakness in the check button.
Call it a weakness in the check button.
Who is online
Users browsing this forum: No registered users and 2 guests