Tutorial 5 - Question 10

Problem completing one of the interactive tutorials?

Moderator: drgrussell

Post Reply
churle

Tutorial 5 - Question 10

Post by churle » Sat Mar 14, 2015 10:05 pm

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.

medinita3586

Re: Tutorial 5 - Question 10

Post by medinita3586 » Sun Mar 15, 2015 4:21 am

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

medinita3586

Re: Tutorial 5 - Question 10

Post by medinita3586 » Sun Mar 15, 2015 6:44 am

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

medinita3586

Re: Tutorial 5 - Question 10

Post by medinita3586 » Sun Mar 15, 2015 6:49 am

Also I don't think you need the apostrophes ' ' sourrounding Jun or the dot. at the end of it.

Good luck

churle

Re: Tutorial 5 - Question 10

Post by churle » Mon Mar 16, 2015 2:41 pm

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! :)

medinita3586

Re: Tutorial 5 - Question 10

Post by medinita3586 » Tue Mar 24, 2015 1:08 am

You're welcome!!! :twisted:

Adamosk
Posts: 1
Joined: Sat Aug 27, 2016 10:47 pm
Are you a robot or a human?: Human

Re: Tutorial 5 - Question 10

Post by Adamosk » Sat Aug 27, 2016 10:55 pm

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?

drgrussell
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

Post by drgrussell » Fri Sep 02, 2016 11:45 pm

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests