我以前没有编程经验。我知道这个问题以前曾被问过,或者答案就在那里,但我一生都找不到它。我在谷歌上搜索了几个小时试图弄清楚这一点。我正在一台 Red Hat Linux 计算机上工作,它使用的是 bash。
我在/directory/中有一个包含文件 0-500 的目录。
它们是这样命名的, /directory/filename_001、/directory/filename_002 等等。
对我的研究进行分析后,我有一个包含我感兴趣的数字的 listofnumbers.txt(txt 文件,每一行都是一个新数字)。例如,
015
124
187
345
412
A) 从文件列表中运行命令 从数字列表中的文件?我们的代码如下所示:
g09slurm filename_001.com filename_001.log
有没有办法写这样的东西:
find value (row1 of listofnumbers.txt) then g09slurm filename_row1value.com filename_row1value.log
find value (row2 of listofnumbers.txt) then g09slurm filename_row2value.com filename_row2value.log
find value (row3 of listofnumbers.txt) then g09slurm filename_row3value.com filename_row2value.log
等等等等
B) 将所选文件从列表移动到新目录,以便我可以按顺序重命名它们,然后运行连续编号命令?
谢谢。
最佳答案
首先,将文件列表读入数组:
readarray myarray < /path/to/filename.txt
接下来,我们将根据这些数字获取所有文件名,并移动它们
cd /path/to/directory
mv -t /path/to/new_directory "${myarray[@]/#/filename_}"
在此之后...老实说,我感到无聊。 Stack Overflow 旨在帮助人们在问题上取得良好的开端,而您在解决这个问题方面所做的工作为零(除了写下“我保证我尝试过 google”)。
我根本不明白什么
Run a command from the list of files the files from the list of numbers
的意思是。
要按顺序重命名它们(移动它们后),您需要根据以下代码执行某些操作:
for i in $(ls); do
*your stuff here*
done
你应该能够研究并解决问题。您可能需要学习一些 bash 教程,here's a reasonable starting place
关于linux - 将非连续文件移动到新目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50994804/