I am new in shell, I tried to transfer file in field-1 into specific folder according to specific path in field-3 and I hope you can help me.
我是shell的新手,我试图根据field-3中的特定路径将field-1中的文件传输到特定文件夹中,我希望你能帮助我。
this is my text file:
这是我的文本文件:
deleted_files.txt
ohdah1.sql 5075 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\
sourcetreeconfig 1066 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\.git\
commit-msg.sample 896 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\.git\hooks\
post-receive.sample 552 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\.git\hooks\
pre-commit.sample 1704 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\.git\hooks\
pre-push.sample 1348 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\.git\hooks\
pre-rebase.sample 4951 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\.git\hooks\
prepare-commit-msg.sample 1239 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\.git\hooks\
update.sample 3611 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\.git\hooks\
HEAD 821 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\.git\logs\
master 821 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\.git\logs\refs\heads\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\cache\
autoload.php 3256 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\config\
constants.php 1598 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\config\
database.php 3288 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\config\
doctypes.php 1152 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\config\
foreign_chars.php 1844 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\config\
migration.php 1322 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\config\
mimes.php 4559 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\config\
routes.php 2909 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\config\
smileys.php 3360 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\config\
device.php 18797 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\controllers\
get_password.php 1632 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\controllers\
gfp.php 2958 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\controllers\
user.php 5374 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\controllers\
my_model.php 2316 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\core\
error_404.php 1221 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\errors\
error_general.php 1208 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\errors\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\errors\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\helpers\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\hooks\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\language\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\language\english\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\libraries\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\logs\
trusteeship_m.php 1147 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\models\
user_m.php 3048 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\models\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\third_party\
email_check.php 924 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\
gp_form.php 1167 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\
pageNotFound.php 2090 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\
add.php 5059 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\car\
carTabs.php 1725 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\car\
conf.php 2909 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\car\
handit.php 1971 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\car\
viewU.php 3016 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\car\
add.php 3525 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\device\
conf.php 2563 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\device\
confR.php 3259 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\device\
deviceTabs.php 1720 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\device\
handit.php 1662 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\device\
viewU.php 2807 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\device\
add.php 3457 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\gis\
conf.php 2548 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\gis\
confR.php 3042 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\gis\
gisTabs.php 1642 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\gis\
handit.php 1603 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\gis\
viewU.php 2816 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\gis\
view.php 1810 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\search\
header.php 929 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\templates\
add.php 6606 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\user\
changePassword.php 2681 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\user\
userTabs.php 1043 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\application\views\user\
bootstrap-theme.min.css 13191 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\assets\css\
dataTables.bootstrap.css 7088 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\assets\css\
green.png 2219 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\assets\css\
green@2x.png 4524 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\assets\css\
style.css 7590 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\assets\css\
sweet-alert.css 14949 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\assets\css\
sweet-alert.html 754 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\assets\css\
glyphicons-halflings-regular.ttf 41280 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\assets\fonts\
back_enabled.jpg 833 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\assets\images\
forward_enabled.jpg 878 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\assets\images\
icheck.min.js 4957 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\assets\js\
sweet-alert.js 21768 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\assets\js\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\
Benchmark.php 3066 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\core\
Common.php 13980 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\core\
Controller.php 1628 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\core\
Exceptions.php 4887 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\core\
Hooks.php 4944 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\core\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\core\
Lang.php 3792 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\core\
Model.php 1246 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\core\
Router.php 12915 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\core\
Utf8.php 3748 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\core\
DB.php 4351 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\
DB_cache.php 4572 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\
DB_utility.php 10217 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\
cubrid_forge.php 7346 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\cubrid\
cubrid_result.php 4707 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\cubrid\
cubrid_utility.php 2978 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\cubrid\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\cubrid\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\mssql\
mssql_driver.php 15502 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\mssql\
mssql_result.php 3541 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\mssql\
mssql_utility.php 2065 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\mssql\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\mysql\
mysql_driver.php 18149 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\mysql\
mysql_result.php 3798 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\mysql\
mysql_utility.php 4819 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\mysql\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\mysqli\
mysqli_driver.php 18184 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\mysqli\
mysqli_result.php 3814 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\mysqli\
mysqli_utility.php 2070 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\mysqli\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\oci8\
oci8_forge.php 5857 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\oci8\
oci8_utility.php 2015 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\oci8\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\odbc\
odbc_driver.php 14530 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\odbc\
odbc_forge.php 6382 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\odbc\
odbc_utility.php 2362 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\odbc\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\pdo\
pdo_utility.php 2339 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\pdo\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\postgre\
postgre_forge.php 7648 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\postgre\
postgre_result.php 3605 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\postgre\
postgre_utility.php 1942 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\postgre\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\sqlite\
sqlite_driver.php 14712 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\sqlite\
sqlite_result.php 3727 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\sqlite\
sqlite_utility.php 2244 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\sqlite\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\sqlsrv\
sqlsrv_forge.php 6144 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\sqlsrv\
sqlsrv_result.php 3584 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\sqlsrv\
sqlsrv_utility.php 2066 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\database\drivers\sqlsrv\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\fonts\
array_helper.php 2627 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\helpers\
captcha_helper.php 6414 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\helpers\
cookie_helper.php 2693 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\helpers\
directory_helper.php 2141 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\helpers\
download_helper.php 2853 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\helpers\
email_helper.php 1544 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\helpers\
html_helper.php 9231 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\helpers\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\helpers\
inflector_helper.php 5569 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\helpers\
language_helper.php 1466 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\helpers\
number_helper.php 1934 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\helpers\
path_helper.php 1850 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\helpers\
security_helper.php 2802 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\helpers\
smiley_helper.php 6746 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\helpers\
string_helper.php 6739 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\helpers\
typography_helper.php 2331 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\helpers\
xml_helper.php 1858 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\helpers\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\
calendar_lang.php 1487 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\arabic\
car_lang.php 677 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\arabic\
db_lang.php 2301 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\arabic\
email_lang.php 1730 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\arabic\
form_validation_lang.php 1847 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\arabic\
ftp_lang.php 1302 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\arabic\
imglib_lang.php 2034 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\arabic\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\arabic\
migration_lang.php 727 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\arabic\
profiler_lang.php 1141 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\arabic\
unit_test_lang.php 832 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\arabic\
upload_lang.php 1640 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\arabic\
calendar_lang.php 1487 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\english\
db_lang.php 2301 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\english\
email_lang.php 1730 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\english\
form_validation_lang.php 1847 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\english\
ftp_lang.php 1302 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\english\
imglib_lang.php 2034 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\english\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\english\
migration_lang.php 727 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\english\
profiler_lang.php 1141 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\english\
unit_test_lang.php 832 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\english\
upload_lang.php 1640 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\language\english\
Calendar.php 13141 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\
Driver.php 5564 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\
Javascript.php 20987 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\
Log.php 2809 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\
Migration.php 8322 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\
Pagination.php 9392 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\
Profiler.php 19856 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\
Sha1.php 5245 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\
Table.php 11899 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\
Unit_test.php 8582 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\
Upload.php 28684 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\
Cache.php 4778 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\Cache\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\Cache\
Cache_apc.php 3342 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\Cache\drivers\
Cache_dummy.php 2690 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\Cache\drivers\
Cache_file.php 4187 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\Cache\drivers\
Cache_memcached.php 5121 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\Cache\drivers\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\Cache\drivers\
index.html 123 C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\system\libraries\javascript\
</b>
and this is my script
这是我的剧本
my script:
for i in cat deleted_files.txt;
do file = ls | cut -f1 -d' ' $i;
path = cut -f3 -d' ' $i;
mv -r $file $path;
done
2 个解决方案
#1
0
Maybe this script is you want to do.
也许这个脚本是你想做的。
#!/bin/bash
while read -r line
do
file=$(echo $line | cut -d' ' -f1)
path=$(echo $line | cut -d' ' -f3)
## If file exists, then move to path
[[ -f $file ]] && mv $file $path
done < deleted_files.txt
By the way, column_3 looks like Windows path format. Does your system recognize C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\
is path format? If not, file name will change "ohdah1.sql" to C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\
.
顺便说一句,column_3看起来像Windows路径格式。您的系统是否识别C:\ Users \ TALAL \ Desktop \ backup_ohdah \ 26 \ ohdah \是路径格式?如果没有,文件名将“ohdah1.sql”更改为C:\ Users \ TALAL \ Desktop \ backup_ohdah \ 26 \ ohdah \。
#2
0
You might want something like this, assuming you're in the current directory containing the files listed in "deleted_files.txt".
假设您位于包含“deleted_files.txt”中列出的文件的当前目录中,您可能需要这样的东西。
while read -r i
do echo "$i"
file=$(echo "$i"|cut -d' ' -f1)
echo "file is $file"
path=$(echo "$i"|cut -d' ' -f3)
echo "path is $path"
mv "$file" "$path"
done < tst
There are several echo's thrown in there to make sure it'll do what you want (try it without the mv
first to make sure).
有几个echo在那里抛出,以确保它会做你想要的(尝试没有mv首先确保)。
And I'm not sure why you were doing the ls
, maybe to verify that the file exists first? Could use bash's "[[
compound command and the test
and [
builtin commands to test file attributes" with "-a file
True if file exists."
而且我不确定你为什么要做ls,也许是为了验证文件是否存在?可以使用bash的“[[复合命令和测试和[内置命令来测试文件属性”与“-a文件如果文件存在则为真”。
#1
0
Maybe this script is you want to do.
也许这个脚本是你想做的。
#!/bin/bash
while read -r line
do
file=$(echo $line | cut -d' ' -f1)
path=$(echo $line | cut -d' ' -f3)
## If file exists, then move to path
[[ -f $file ]] && mv $file $path
done < deleted_files.txt
By the way, column_3 looks like Windows path format. Does your system recognize C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\
is path format? If not, file name will change "ohdah1.sql" to C:\Users\TALAL\Desktop\backup_ohdah\26\ohdah\
.
顺便说一句,column_3看起来像Windows路径格式。您的系统是否识别C:\ Users \ TALAL \ Desktop \ backup_ohdah \ 26 \ ohdah \是路径格式?如果没有,文件名将“ohdah1.sql”更改为C:\ Users \ TALAL \ Desktop \ backup_ohdah \ 26 \ ohdah \。
#2
0
You might want something like this, assuming you're in the current directory containing the files listed in "deleted_files.txt".
假设您位于包含“deleted_files.txt”中列出的文件的当前目录中,您可能需要这样的东西。
while read -r i
do echo "$i"
file=$(echo "$i"|cut -d' ' -f1)
echo "file is $file"
path=$(echo "$i"|cut -d' ' -f3)
echo "path is $path"
mv "$file" "$path"
done < tst
There are several echo's thrown in there to make sure it'll do what you want (try it without the mv
first to make sure).
有几个echo在那里抛出,以确保它会做你想要的(尝试没有mv首先确保)。
And I'm not sure why you were doing the ls
, maybe to verify that the file exists first? Could use bash's "[[
compound command and the test
and [
builtin commands to test file attributes" with "-a file
True if file exists."
而且我不确定你为什么要做ls,也许是为了验证文件是否存在?可以使用bash的“[[复合命令和测试和[内置命令来测试文件属性”与“-a文件如果文件存在则为真”。