How to copy/move files from multiple directories to multiple subfolders
NB: filenames should not contain blank spaces or special characters (e.g. &, %, !, (, etc)
Step 1 : Extract list of filenames
command | description
cd | change directory to source directory (drag folder from Finder screen to terminal screen)
pwd | provides full path of current location (source directory)
find | to find all files within the current directory,
“-iname” means not case-sensitive
to search only your user directory, type "~/"
save results to text file (i.e. filenames.txt)
dmcguest$ find ~/ -iname "*.*" >>filenames.txt
Step 2 : Get path to destination directories
command | description
cd | change directory to destination folder (drag folder from Finder screen to terminal screen)
ls | outputs simple list of folders
pwd | provides full path of current location (destination)
Step 3 : Create commands
In excel: Create table with following columns
column
|
value
|
description
|
1st
|
cp
|
copy command (to move files instead of copy, replace cp with mv)
|
2nd
|
Source path/filenames
|
Data from step 1 : drag filenames.txt to MS Excel icon to open
(note 1)
|
3rd
|
Destination path/sub folder
|
Path to destination directory plus name of object folder. (from Step 2)
|
4th
|
|
|
Pipe symbol (for all rows except last)
|
Note 1: Since Find command (in Step 1) is for all files (*.*) this may result in system files/folders being included in the list. Therefore may need to remove these sorts of files before proceeding. TIP: use =RIGHT() excel function to sort list by file type.
Step 4 : Clean up spacing
In MS word
Copy data from Step 3 to MS word (paste special > unformatted text)
Remove any hard returns (search and replace tabs ^t with single space)
Edit/Select All
Step 5 : Run commands
Open terminal (top level)
paste commands
NOTE: in this example, the full path is included for both source and destination locations, so do not need to navigate to any particular directory before executing commands.
TIP: as proof of concept recommend first testing single command and confirm file has been copied as excepted
Figure: Paste multi-commands directly to terminal using pipe symbol to separate
Step 6 : Verify
Spot check using finder
Figure: folder wrc02806 contains transferred files (*.jpg)
Comments (0)
You don't have permission to comment on this page.