How to move a large number of files using Linux command line
-
I have been searching Google for ways to move a large number of files using the Linux command line.
What I have is several hundred PDF files in a single folder. Each file has a date assigned to it. What I need to do is to create a sub-folder with a year assigned to it. I know I can create multiple folders or directories using the following:
mkdir 2019 2020 2021
What I need to do is move all 2019 files into the 2019 folder, all 2020 files in the 2020 folder, etc.
My Professor recommended I use GREP to display the files, then pipe the output into the Move command.
My understanding was GREP was used for search for text strings within text files and not really for files in a directory.
Can someone please shed some light on this?
Thanks,
Chris -
I cannot tell you this is the most efficient way to do it but it may work and depends on if
find
in your distro has the-newermXY
option.For example:
find /media/storage1/data/ -newermt 20190101 -not -newermt 20200101
the
m
andt
options here are form
odification and reference is intepreted ast
imethen you can use the
mv
as stated by your professor as well.There are more than likely other methods and I should say better methods.