Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'd like to be able to move a few recent files to a new directory. I can list the most recent files by running ls -t | head, but now I want to be able to move (mv) those files. How can I do that?

share|improve this question

closed as off topic by mikewhatever, con-f-use, John S Gruber, hbdgaf, jokerdino Aug 24 '12 at 3:11

Questions on Ask Ubuntu are expected to relate to Ubuntu within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Homework ...? :~) Anyway, it's probably unrelated to Ubuntu, is it? –  mikewhatever Mar 17 '12 at 20:35
    
@mikewhatever It's not homework, I'm just trying to get better at the command line. I probably could've posted this in the unix SE site, but I am trying to use Ubuntu to do this, so I don't see why it shouldn't be here. –  Jon Apr 1 '12 at 18:26
    
OK, no worries. –  mikewhatever Apr 2 '12 at 9:17

2 Answers 2

up vote 2 down vote accepted

There you go:
ls -t | head | xargs -I files mv files <dest_dir>.
Just replace the <dest_dir> with your target directory.

share|improve this answer
    
Note that this will fail for filenames containing whitespace or quote characters (" '). –  geirha Mar 18 '12 at 10:05

Another option is:

 mv $(ls -t) <dest_dir>

geirha's comment applies here, too--this fails for filenames containing whitespace, etc.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.