Date: Wed, 25 Aug 2004 03:54:30 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Joachim Dagerot <freebsd@dagerot.nu> Cc: freebsd-questions@freebsd.org Subject: Re: Bash programming, copy only onefile? Message-ID: <20040825005430.GA27797@gothmog.gr> In-Reply-To: <20040824231510.GS3767@gentoo-npk.bmp.ub> References: <000001c489ff$1ab67f10$4b592650@yd5esbzvskxjc0a> <200408242216.i7OMGIp05050@thunder.trej.net> <20040824231510.GS3767@gentoo-npk.bmp.ub>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2004-08-24 17:15, Nathan Kinkade <nkinkade@ub.edu.bz> wrote: > On Wed, Aug 25, 2004 at 12:16:17AM +0200, Joachim Dagerot wrote: > > A quiz easy to write, hard to answer? > > > > In bash, how can I write a command that moves the oldest file in a > > directory to a new direction? > > Here is one possible way, certainly there are many others: > > # ls -t /path/to/dir | tail -n 1 | xargs -i{} cp {} /path/to/location In FreeBSD 5.X there's also stat(1) which can print the modification time of files in a numeric format and can be used in pipes like this: % stat -f '%m %N' * | sort -n | head -1 | cut -d ' ' -f 2- This should print the filename of the file with the oldest modification time. Access time or creation time can also be shown using the -f 'fmt' argument of stat(1) but details about that can be found in the stat(1) manpage. - Giorgos
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040825005430.GA27797>