For example this path below it has the sharp "#"
key:
/usr/dfiles/$line/Tasks/#msgs/
cp "/usr/dfiles/$line/Tasks/#msgs/*.eml" "/mnt/NAS/Tasks1/line/"
Even though the path is enclosed by quotation marks, Linux
system will show "No such file or directory".
Since the system is unable to find the "#msgs"
directory.
As a work around in this issue is to append "--"
double dash before the cp command and everything will work fine.
So, this command below will work.
cp --
"/usr/dfiles/$line/Tasks/#msgs/*.eml"
"/mnt/NAS/Tasks1/line/"
Copying one folder is quite practical to do it by hand rather by script.
But if you are copying hundreds or thousands of folders, doing it manually is quite painful.
To copy hundreds or thousands of folders to another folder the practical way, is to do it the lazy way.
Scripting is a lazy task; you let the system do it for you.
Lazy but it is a smart and a powerful way of doing things.
Script below will read the list of folders from
"filename.txt" and the actual folder name will be replaced on the
variable "$line".
Here's the script below, try it first via test folders
before rolling out to production.
Anyway, since the script will just copy files it won't do any harm. But of course, it will fill up space.
#====================================
#!/bin/bash
while IFS='' read -r line || [[ -n "$line" ]]; do
cp -- "/usr/dfiles/$line/Tasks/#msgs/*.eml" "/mnt/NAS/Tasks1/$line/"
done < "$1"
#====================================
Make the script executable by chmod command.
chmod +x xx.sh
Syntax to run the script:
Script plus the filename.txt
Filename.txt contains the list of folder where the files will be copied.
./xx.sh filename.txt
You can append -v to cp to show what's going on or what files are being copied.
cp -v -- "/usr/dfiles/$line/Tasks/#msgs/*.eml" "/mnt/NAS/Tasks1/$line/"
Cheers..till next time.. Enjoy Linux..
================================
Free Android Apps:
Click on links below to find out more:
Multiplication Table for early learners
Catholic Rosary Guide for Android:
Pray the Rosary every day, countless blessings will be showered upon your life if you recite the Rosary faithfully.
https://play.google.com/store/apps/details?id=com.myrosaryapp
https://play.google.com/store/apps/details?id=com.myrosaryapp
Comments
Post a Comment