Arhivarea documente in functie de data

Configurare noua (How To)

Situatie

Vrem sa arhivam documentele in functie de data modificarii.

Solutie

Pasi de urmat

Mai intaii trebuie sa afisam fisierele din director.
$ls -ahl
-rw-r–r– 1 root root 0 Feb 12 17:02 test194.txt
-rw-r–r– 1 root root 0 Feb 12 17:02 test193.txt
-rw-r–r– 1 root root 0 Feb 12 17:02 test192.txt
-rw-r–r– 1 root root 0 Feb 12 17:02 test191.txt
-rw-r–r– 1 root root 0 Feb 12 17:02 test190.txt
-rw-r–r– 1 root root 0 Feb 12 17:02 test189.txt
-rw-r–r– 1 root root 0 Feb 12 17:02 test188.txt
-rw-r–r– 1 root root 0 Feb 12 17:02 test187.txt
-rw-r–r– 1 root root 0 Feb 12 17:02 test186.txt
-rw-r–r– 1 root root 0 Feb 12 17:02 test185.txt
-rw-r–r– 1 root root 0 Feb 12 17:02 test184.txt
-rw-r–r– 1 root root 0 Feb 12 17:02 test183.txt
-rw-r–r– 1 root root 0 Feb 12 17:02 test182.txt
-rw-r–r– 1 root root 0 Feb 12 17:02 test181.txt
-rw-r–r– 1 root root 0 Feb 12 17:02 test180.txt
-rw-r–r– 1 root root 0 Feb 12 17:02 test179.txt
-rw-r–r– 1 root root 0 Feb 12 17:02 test178.txt
-rw-r–r– 1 root root 0 Feb 12 17:02 test177.txt

Putem vedea ca fisierele au data de 12 feb 2017.

Pentru a arhiva fisiere vom crea o lista de fisisere de arhiva:
$ls -trlh | grep “Feb 12″|awk ‘{print$NF}’ > arhiva.txt
ls -trlh – listeaza in forma de tabel
grep – cauta text in tabel
awk – aranjeaza rezultatul cautarii anterioare
> – varsa rezultatul intr-un fisier text

Odata ce avem o lista de fisiere putem sa le arhivam.
Pentru acesta vom folosi comanda:
$tar -cvf fisiere.tar -T arhiva.txt

tar -cvf = creara o arhiva de tip tarball(fara compresie)

fisiere.tat = numele arhive – ar fii mai util sa o denumim cu data

-T arhiva.txt = ii spune lui tar sa foloseasca fisierul text pentru a afla ce fisiere sunt de arhivat

Tip solutie

Permanent

Voteaza

(13 din 25 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?