PDA

Visualizza la versione completa : cp filtrata


best1980
08-07-2005, 15:48
Ho una directory con migliaia di file. Come faccio a copiare solo quelli da una certa data in poi?

Grazie

cacao74
08-07-2005, 17:20
Un piccolo esempietto...


cacao74@winnie:~/tmp/archivio$ ls
cacao74@winnie:~/tmp/archivio$ for mese in `seq -w 1 12`; do \
touch -d "2004-${mese}-01" mese-${mese}; done
cacao74@winnie:~/tmp/archivio$ ls -l
totale 0
-rw-r--r-- 1 cacao74 cacao74 0 2004-01-01 00:00 mese-01
-rw-r--r-- 1 cacao74 cacao74 0 2004-02-01 00:00 mese-02
-rw-r--r-- 1 cacao74 cacao74 0 2004-03-01 00:00 mese-03
-rw-r--r-- 1 cacao74 cacao74 0 2004-04-01 00:00 mese-04
-rw-r--r-- 1 cacao74 cacao74 0 2004-05-01 00:00 mese-05
-rw-r--r-- 1 cacao74 cacao74 0 2004-06-01 00:00 mese-06
-rw-r--r-- 1 cacao74 cacao74 0 2004-07-01 00:00 mese-07
-rw-r--r-- 1 cacao74 cacao74 0 2004-08-01 00:00 mese-08
-rw-r--r-- 1 cacao74 cacao74 0 2004-09-01 00:00 mese-09
-rw-r--r-- 1 cacao74 cacao74 0 2004-10-01 00:00 mese-10
-rw-r--r-- 1 cacao74 cacao74 0 2004-11-01 00:00 mese-11
-rw-r--r-- 1 cacao74 cacao74 0 2004-12-01 00:00 mese-12
cacao74@winnie:~/tmp/archivio$ touch -d $(date +%D --date '1 year ago') riferimento
cacao74@winnie:~/tmp/archivio$ ls -l riferimento
-rw-r--r-- 1 cacao74 cacao74 0 2004-07-08 00:00 riferimento
cacao74@winnie:~/tmp/archivio$ find ../archivio/ -mindepth 1 -newer riferimento \
-exec ls -l '{}' ';'
-rw-r--r-- 1 cacao74 cacao74 0 2004-08-01 00:00 ../archivio/mese-08
-rw-r--r-- 1 cacao74 cacao74 0 2004-09-01 00:00 ../archivio/mese-09
-rw-r--r-- 1 cacao74 cacao74 0 2004-10-01 00:00 ../archivio/mese-10
-rw-r--r-- 1 cacao74 cacao74 0 2004-11-01 00:00 ../archivio/mese-11
-rw-r--r-- 1 cacao74 cacao74 0 2004-12-01 00:00 ../archivio/mese-12

Al posto di 'ls -l' ovviamente specificherai il comando di copia che ritieni pił opportuno. Anche il file di riferimento, puo' trovarsi in qualunque directory.
Ancora qualche riga:


cacao74@winnie:~/tmp/archivio$ mkdir ../backup
cacao74@winnie:~/tmp/archivio$ find ../archivio/ -mindepth 1 -newer riferimento \
-exec cp '{}' ../backup ';'
cacao74@winnie:~/tmp/archivio$ ls -l ../backup/
totale 0
-rw-r--r-- 1 cacao74 cacao74 0 2005-07-08 17:18 mese-08
-rw-r--r-- 1 cacao74 cacao74 0 2005-07-08 17:18 mese-09
-rw-r--r-- 1 cacao74 cacao74 0 2005-07-08 17:18 mese-10
-rw-r--r-- 1 cacao74 cacao74 0 2005-07-08 17:18 mese-11
-rw-r--r-- 1 cacao74 cacao74 0 2005-07-08 17:18 mese-12


man find

ciao

Loading