bash 通过脚本从挂载共享驱动器复制到本地文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15425223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Copying from mount share drive to local folder through script
提问by Mitchell
This is my first time trying to work with Linux Scripts so this may be something obvious.
这是我第一次尝试使用 Linux 脚本,所以这可能很明显。
Here is what I am trying to do:
这是我想要做的:
- Remove all contents from local folder - rm /home/user/Documents/Exercise/
- Copy files from a shared windows network drive - cp smb://server/arc/Exercise%20Files/Word/
- 从本地文件夹中删除所有内容 - rm /home/user/Documents/Exercise/
- 从共享的 Windows 网络驱动器复制文件 - cp smb://server/arc/Exercise%20Files/Word/
So from my understanding my command should look like this
所以根据我的理解,我的命令应该是这样的
rm /home/user/Documents/Exercise/
cp smb://server/arc/Exercise%20Files/Word/ /home/user/Documents/Exercise/
But anytime I try and run either of the above commands I get the following error:
但是每当我尝试运行上述任一命令时,都会出现以下错误:
"rm: cannot remove `/home/user/Documents/Exercise/': Is a directory"
"cp: cannot stat `smb://server/arc/Exercise%20Files/Word/': No such file or directory"
What am I doing wrong?
我究竟做错了什么?
Kind Regards,
亲切的问候,
M
米
采纳答案by fedorqui 'SO stop harming'
Based on your request and your test, let me point what is not written properly:
根据您的要求和您的测试,让我指出写得不好的地方:
Remove all contents from local folder
从本地文件夹中删除所有内容
rm /home/user/Documents/Exercise/
Error says rm: cannot remove /home/user/Documents/Exercise/': Is a directory
错误说rm: cannot remove /home/user/Documents/Exercise/': Is a directory
You should
你应该
rm /home/user/Documents/Exercise/*
which will delete everything inside the directory, but not the directory.
这将删除目录中的所有内容,但不会删除目录。
Copy files from a shared windows network drive
从共享的 Windows 网络驱动器复制文件
cp smb://server/arc/Exercise%20Files/Word/ /home/user/Documents/Exercise/
Error says cp: cannot stat smb://server/arc/Exercise%20Files/Word/': No such file or directory
错误说cp: cannot stat smb://server/arc/Exercise%20Files/Word/': No such file or directory
You should check if route smb://server/arc/Exercise%20Files/Word/is correct. Then, use the following:
您应该检查路线smb://server/arc/Exercise%20Files/Word/是否正确。然后,使用以下内容:
cp smb://server/arc/Exercise%20Files/Word/* /home/user/Documents/Exercise/
回答by Paul Calabro
You can't delete a directory if it has content within it. To delete the content and the directory at the same time, use the following command:
如果目录中有内容,则无法删除该目录。要同时删除内容和目录,请使用以下命令:
rm -r /home/user/Documents/Exercise/
This recursively deletes the directory and any content within it.
这将递归删除目录及其中的任何内容。
To copy the file, I believe you have to mount the directory beforehand, like so:
要复制文件,我相信您必须事先挂载目录,如下所示:
mount -t cifs //server/share /mnt/mount_directory -o user=username
Can you confirm if that works?
你能确认这是否有效吗?
回答by Mitchell
Remove / Delete Command:
rm -rfv /home/user/Documents/Exercise/*
删除/删除命令:
rm -rfv /home/user/Documents/Exercise/*
Copy Command:
cp -rfv /home/user/Documents/ExerciseShare/ExerciseFiles/Word/ /home/user/Documents/Exercise/
复制命令:
cp -rfv /home/user/Documents/ExerciseShare/ExerciseFiles/Word/ /home/user/Documents/Exercise/

