Astronomy computer Linux Note


有时候你想在一个目录的所有子目录下批量建立文件夹,并且批量的运行这些子目录内新建立好的文件夹内的 IDL 程序,以下是一种可能的解决途径,如果你有更好的方法,欢迎告诉我

Here are the things I want to do:

  1.  I have a data folder containing many sources, like Arp220, NGC981, etc.. Each of them possesses a folder under the whole data folder (./source/Arp220, ./source/NGC891, …). I want to create a subfolder named “plot” under each sources folder, e.g., ./source/Arp220/plot.
  2. And then I want to copy the IDL routine to each “plot” folder I just created and run all the PRO routines at one time.

Here is a bash script being able to do such things:

for i in $(ls -d */); do mkdir -p $i/'plot'; done
for i in $(ls -d */); do cp ./ $i/'plot'/; done
for i in $(ls -d */); do cd $PWD/$i/'plot';idl -e ".r ./"; cd ../.. ; done

The first line means creating a “plot” folder under all the subfolders under you present folder. And the next line is to copy the IDL routine ( to each “plot” folder you created. The last line runs all the IDL routines.


find ./* -type f|grep X|while read file; do rm "$file"; done

比如你要删除“./you suck/arXiv.pdf“这种文件。上面那句话中 -type f|grep X|while read file 是为了保证有空格的目录也可以被写入到一个变量里面


find ./* -type f -name "*X*" -exec rm {} \;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.