如何使用Mac OS X Terminal将目录中的最旧或最新文件移动到另一个文件 [英] How do I move the oldest or newest file in a directory to another with Mac OS X Terminal

查看:382
本文介绍了如何使用Mac OS X Terminal将目录中的最旧或最新文件移动到另一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Mac OSX 10.6终端上尝试向我们提供以下命令,但是它不起作用..知道我可能做错了什么吗?

I'm trying to us the following command on Mac OSX 10.6 Terminal but it does not work..Any idea what I may be doing wrong?

这些工作...

列出最新文件:

ls -l -t | head -2

列出最早的文件:

$ ls -gt | tail -1

但是当我尝试移动最旧的文件时,此操作将无效:

But when I try to Move the oldest file, with this it doesn't work:

mv `ls -tr |tail -1` newdirname

任何想法或技巧都值得赞赏!!并且,请保持绅士风度,我在命令行方面还不那么擅长; )

Any ideas or tips are appreciated!! And please be gentle guys, I'm not so good at this command line stuff yet ; )

谢谢

杰西

Ps.

当我输入此内容时:

mv `ls -tr |tail -1` DropBox

我明白了:mv: rename Test.txt to DropBox/Test.txt: No such file or directory

推荐答案

假设您要移动的文件位于当前目录中

Assuming the files you are moving are in the current directory:

mv "`ls -1t | tail -1`" dir_to_move_to

对文件名中的空格使用引号帮助,但我认为我的答案不是优雅的,还有更优雅的解决方案吗?

the quote help for spaces in filename, but I don't think my answer is elegant, any more elegant solution?

这篇关于如何使用Mac OS X Terminal将目录中的最旧或最新文件移动到另一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆