M HYPE SPLASH
// general

How to update timestamp when moving files

By John Campbell

In source directory, I have multiple files which all has dot (.) to it.

So, when I move I can give like below

mv *.* /destination/

But my issue is I want to give timestamp to all the files in destination folder for identification.

1

2 Answers

While pLumo's solution is technically OK, it may be a bit confusing. You can achieve the same goal with two separate commands, first touching the files to update the access time, followed by the move command:

touch *.*
mv *.* /destination/

The reason to do it in this particular order is to not update the access times of files that may already be located in the /destination/ folder.

It may be worth noting that the wildcard pattern *.* does not match hidden files, which are marked by a leading dot on Unix systems (use ls .* to list them). It's up to you to decide if that's what you want to achieve or not.

Use xargs to touch and mv:

printf '%s\0' *.* | xargs -0 sh -c 'touch "$@" && mv "$@" /destination/' xargs-sh

This has also the benefit of preventing "too many arguments" error, as xargs takes care of that.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy