Il mio obiettivo
Organizzo i miei progetti in cartelle. Queste cartelle vivono tutte nella mia cartella Completed projects
. Sto iniziando a archiviarli in una cartella Archived Projects
e voglio archiviarli in sottocartelle dal client. Io uso sempre il nome del cliente nel nome della cartella del progetto. Ad esempio, ho cartelle di progetto denominate Appeal [May 2014] - Development
e Identity Package [2014] - Communications
. (I miei clienti interni sono nomi di dipartimento: Academics, Communications, Development ...) Ecco come voglio che vengano archiviati:
Archived Projects >> Development >> Appeal [May 2014] - Development
Archived Projects >> Communications >> Identity Package [2014] - Communications
Ogni cartella di progetto ha anche un set unico di sottocartelle. Voglio preservare quella struttura.
Il mio approccio
Ho selezionato un cliente alla volta, utilizzando questo script:
#!/bin/bash
# Go to the Completed Projects folder.
cd /Volumes/communications/Projects/Completed\ Projects/
# Find a folder with a specified string (e.g. "Academics") in its name.
# Move (not copy) the folder to its corresponding sub-folder of the Archived Projects folder. (e.g. /Academics)
find . -type d | while read folder ; do
if [[ "$folder" = *Academics* ]]; then
echo "Moving $folder";
mv "$folder" /Volumes/communications/Projects/Archived\ Projects/Academics/;
fi
done
Ho chiamato lo script come navigando, nel Terminale, nella directory con i miei script digitando cd ~/Dropbox/scripts
↩ ./move_project_academics.sh
↩
Il mio problema
Il modello di corrispondenza rudimentale funziona, ma mv
genera un errore:
mv: rename /Appeal [May 2014] - Development/SUB1/SUB2 to
/dest/Archived Projects/Development/SUB2: No such file or directory.
Chiaramente gli sto dando le istruzioni sbagliate. (Anche se, stranamente, questo script ha funzionato alcune volte .) SUB2 non appartiene affatto a /dest/Archived Projects/Development/
. SUB2 deve essere nidificato all'interno di SUB1, che deve essere annidato all'interno della cartella del progetto.
Le mie domande
Quale comando di shell sposterebbe una cartella e manterrebbe la sua struttura interna? E come potrebbe selezionare una cartella in base al nome del cliente?
Su richiesta, ecco l'intero output stampato sul terminale:
n$ ./move_project_academics.sh
Moving ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry -
mv: rename ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - to /Volumes/communications/Projects/Archived Projects/Academics/[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry -: No such file or directory
Moving ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Documentation
Moving ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Documentation/Contracts
mv: rename ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Documentation/Contracts to /Volumes/communications/Projects/Archived Projects/Academics/Contracts: No such file or directory
Moving ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Documentation/Correspondence
mv: rename ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Documentation/Correspondence to /Volumes/communications/Projects/Archived Projects/Academics/Correspondence: No such file or directory
Moving ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Documentation/Invoices
mv: rename ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Documentation/Invoices to /Volumes/communications/Projects/Archived Projects/Academics/Invoices: No such file or directory
Moving ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Documentation/Planning Documents
mv: rename ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Documentation/Planning Documents to /Volumes/communications/Projects/Archived Projects/Academics/Planning Documents: No such file or directory
Moving ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Documentation/Quotes
mv: rename ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Documentation/Quotes to /Volumes/communications/Projects/Archived Projects/Academics/Quotes: No such file or directory
Moving ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Drafts
Moving ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Drafts/[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry
mv: rename ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Drafts/[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry to /Volumes/communications/Projects/Archived Projects/Academics/[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry: No such file or directory
Moving ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Drafts/[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry/Audio Files
mv: rename ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Drafts/[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry/Audio Files to /Volumes/communications/Projects/Archived Projects/Academics/Audio Files: No such file or directory
Moving ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Drafts/[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry/Fade Files
mv: rename ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Drafts/[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry/Fade Files to /Volumes/communications/Projects/Archived Projects/Academics/Fade Files: No such file or directory
Moving ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Drafts/[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry/Session File Backups
mv: rename ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Drafts/[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry/Session File Backups to /Volumes/communications/Projects/Archived Projects/Academics/Session File Backups: No such file or directory
Moving ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Final
Moving ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Source Files
Moving ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Source Files/Copy
mv: rename ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Source Files/Copy to /Volumes/communications/Projects/Archived Projects/Academics/Copy: No such file or directory
Moving ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Source Files/Design
mv: rename ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Source Files/Design to /Volumes/communications/Projects/Archived Projects/Academics/Design: No such file or directory
Moving ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Source Files/RAW
mv: rename ./[2013.04.05] - Audio - Academics - Course - Stephanie Hubach - Disability Ministry - /Source Files/RAW to /Volumes/communications/Projects/Archived Projects/Academics/RAW: No such file or directory