I need to change the timestamp of about 5000 files.
Typing touch file1.txt
, touch file2.txt
will take me forever.
Is there a way to do something in the lines of touch -R *
?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this communityYou can use find
command to find all your files and execute touch
on every found file using -exec
find . -type f -exec touch {} +
If you want to filter your result only for text files, you can use
find . -type f -name "*.txt" -exec touch {} +
-exec
's +
terminator (instead of \;
). This will chain multiple arguments onto each touch
instance (up to the system argument limit) and will therefore fork out much less (and probably be faster).
-exec touch {} +
part, and it'll print to your terminal what it would have affected.
find . -type f -exec touch {} +
find
suggests it is more secure to use -execdir
rather than -exec
as -execdir
runs each command from the directory in which the find
result is located. It also says that when invoked from a shell, "[the curly brace pair] should be quoted (for example, '{}') to protect it from interpretation by shells".
Jan 24, 2020 at 21:55
touch file{1..3}.txt
?touch **/*
is convenient.