I am looking for a bash script example which does the following:

I have files being written under /tmp folder

I do at the xterm prompt, ls -ltr which gives me a list of recent files such as:


I want to move (mv) the most recent ones that were written today to a new folder which is under /home/project/.

I only want to move the ones that were created in /tmp in today's date only to /home/project/

Any example that the community can share will save me time before I re-invent the wheel.

Thanks, Eric

  • What are the % symbols on the front of your filenames? Mar 16, 2022 at 18:12
  • These are just my Linux Xterm prompt.
    – Eric
    Mar 16, 2022 at 18:26
  • LinuxMachine-username% abc_mytest.log LinuxMachine-username% abc_runTimeFailure.scripted.log LinuxMachine-username% myManager.log
    – Eric
    Mar 16, 2022 at 18:28
  • (1) Please don’t use symbols misleadingly.  Your “>>” is confusing, and the shell prompt should appear at the left of the ls command, not at the beginning of every line of output.  (2) Look at find. … … … … P.S.  Why do you believe that your question has anything to do with regular expressions? … … … … … … … … P.P.S. Please do not respond in comments; edit your question to make it clearer and more complete. Mar 16, 2022 at 18:37
  • Your prompt does not appear at the beginning of each line of output. Only when you're being prompted (hence its name). But better is not to include the prompt at all, so that copy'n'paste can work Mar 16, 2022 at 19:01

2 Answers 2


With zsh:

autoload age
mv /tmp/*(.e[age today]) /home/project/

(add the D glob qualifier if you also want to move hidden files last modified today).

Note that /tmp is a temporary directory used by every user of the system including system user. It sounds like a bad idea to try moving files that may potentially not be your own (the system won't let you do it though unless you're doing it as root).

To only consider files that you own, use the U glob qualifier. You could also move only files whose name matches a given pattern like the ones that end in .log:

mv /tmp/*.log(.Ue[age today]) /home/project/

Read man find mv and do something like:

find /tmp -maxdepth 1 -type f -daystart -mtime 0 \
  -exec mv -t /home/project/ {} +

UNTESTED! You must test with echo mv instead of the potentially dangerous mv.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .