Score:0

How to copy all log files from a particular date to the current date?

qa flag

I want to copy the log files from a particular date, say Nov 18, to the current date. How can I do that?

Hannu avatar
ca flag
school task? `man find` and `man xargs` will give you a lot of options, either with find alone, or in combination with xargs.
Score:2
ca flag

You can use the following find command:

find /path/to/logs/dir -type f -newermt '2022-11-18' -exec cp {} /path/to/copy/dir \;
  • Replace /path/to/logs/dir and /path/to/copy/dir with the paths to the directory where your logs are and the directory you want to copy the logs to, respectively.

  • -type f is used to search for files only.

  • -newermt '2022-11-18' is used to find files that were last modified (this is the mt part of -newermt) after November 18 2022. Time formats are interpreted similarly to date's -d option, so you can use -newermt 'November 18 2022' or any format that date -d can handle. See man date for more.

  • -exec cp {} /path/to/copy/dir is used to copy each found file ({}) to /path/to/copy/dir.

Note that find looks for files recursively, so it will also look for files that satisfy the required criteria inside directories in /path/to/logs/dir too. If you don't want to look recursively for the files, add the -maxdepth 1 option right before -type f.

For more details see man find.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.