I'm using bash.
Suppose I have a log file directory /var/myprogram/logs/
.
Under this directory I have many sub-directories and sub-sub-directories that include different types of log files from my program.
I'd like to find the three newest files (modified most recently), whose name starts with 2010
, under /var/myprogram/logs/
, regardless of sub-directory and copy them to my home directory.
Here's what I would do manually
1. Go through each directory and do ls -lt 2010*
to see which files starting with 2010
are modified most recently.
2. Once I go through all directories, I'd know which three files are the newest. So I copy them manually to my home directory.
This is pretty tedious, so I wondered if maybe I could somehow pipe some commands together to do this in one step, preferably without using shell scripts?
I've been looking into find
, ls
, head
, and awk
that I might be able to use but haven't figured the right way to glue them together.
Let me know if I need to clarify. Thanks.