0

I have some 500 .txt files from the year 2013 to 2015 placed in a folder and I need to move all the files of the year 2013 and year 2014 to some oher folder.

2 Answers 2

0

Assuming "of the year 2013 and year 2014" means "with modification time in 2013 / 2014", you can get the list of files with:

stat -c '%y %n' * | grep -v '^2015' | cut -d " " -f 4-

What this does:

stat -c '%y %n'

Print last modification time and filename

*

Of all files in the folder

grep -v '^2015'

Exclude those of 2015

cut -d " " -f 4-

Finally strip the timestamp, leaving just the filename (assuming you don't have weird filenames with embedded newlines)

You can then process the files with a tool like xargs, or even a for loop (if characters allow), for moving them to the desired folder.

2
  • I have several files with name -rw-r--r-- 1 root root 20K Nov 10 21:54 20151110.rsiglog
    – Aryan
    Dec 8, 2015 at 21:50
  • The caret means it will only exclude lines beginning with 2015. And the lines start with the date, so the files with 2015 embedded in the filename will be treated properly.
    – Ángel
    Dec 12, 2015 at 0:06
0

If those files have the year in their names it is quite simple. If you are familiar with the terminal, here goes an example.

Let´s say you want to move all the files from 2013 to a folder called '2013files', and their name are something like '2013 stuff.txt' or 'january 2013.txt'

Go to your folder

cd /path/to/your/folder/

Create the folder where you want to move you files

mkdir 2013files

Then move all files with '2013' in their names

rename  ./*2013*.txt  ./2013files

IMPORTANT: before using the 'rename' command, use 'cp' instead, to make sure you didn´t mistype anything, or you may end up with only one file.

IMPORTANT (2): backup your files, always, before anything

You must log in to answer this question.

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