
linux复制文件到另一个文件夹方法如下:
*** 作设备:xshell。
设备系统:linux系统。
*** 作软件:linux服务器。
1、打开xshell软件连接上linux服务器。
3、如果在文件夹中已经有相同名字的文件,会提示是否覆盖。输入y回车确认。
4、如果想要复制的时候强制覆盖不提示,则使用【\cp文件目标文件夹】。
5、复制文件夹需要使用参数-r递归复制整个文件夹【\cp -r文件夹目标文件夹】。
在xshell窗口中点击xftp按钮或按组合键:Ctrl + Alt + F打开xftp后,输入get filename1 filename2 ...
把filename1 filename2下载到当前默认的C:\Program Files (x86)\NetSarang\Xshell 4目录下。
如果要把文件上传服务器,则用put命令,xftp会打开一个文件浏览窗口,让你选择要上传的文件。点击确定后,文件开始传输。传输完成,文件就位于你所登录的用户目录下。
#!/bin/bashrp=$(pwd)
echo rootpath-----------------:${rp}
# function
moveFile(){
# get dirs
ls -F | grep "/$" > temp_dirs.txt
cat temp_dirs.txt | while read d
#for d in $(cat temp_dirs.txt)
#while read d
do
cp=$(pwd)/${d}
cd ${cp}
echo currentPath----------------------:${cp}
ls -al | grep "^-" > temp_files.txt
cat temp_files.txt | while read f
#for f in $(cat temp_files.txt)
#while read f
do
fileName="${f##* }"
echo filename--------------------:${fileName}
newFileName=${rp}/${d%*/}-${fileName}
echo newfilename---------------------:${newFileName}
fullPath=${cp}${fileName}
echo fullPath-------------------------:${fullPath}
mv ${fullPath} ${newFileName}
done
#< <(ls -al | grep "^-")
# delete temp file
test -a temp_files.txt && rm -rf temp_files.txt
#
moveFile
test -a temp_dirs.txt && rm -rf temp_dirs.txt
cd ..
done
# < <(ls -F | grep "/$")
}
# exec
echo 'start move files ...'
moveFile
rm -rf *temp_dirs.txt
rm -rf *temp_files.txt
echo 'move files end'
技术有限,此代码效率不高;在linux测试没问题,mac上没测,你可以先测一下;文件移到根目录会被重命名为它原先所在的文件夹加上短杠加上它原先的名称
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)