English 中文(简体)
• 如何在支部执行海关复印指挥?
原标题:how to execute a custom copy command in linux?

i 必须将一些档案从目录转到另一个目录,但这是一个小.。

这里是我的多重结构。

/var/www/media_test1/media001/001_pm_001.jpg
                              th001_pm_001.jpg

/var/www/media_test1/media002/002_pm_001.jpg
                              th002_pm_001.jpg

/var/www/media_test1/media003/003_pm_001.jpg
                              th003_pm_001.jpg

/var/www/media_test1/media004/004_pm_001.jpg
                              th004_pm_001.jpg

i 基本上想将照片从每个没有<代码>的圆形/代码”的夹带移至另一个目录:

/var/www/media_test2/media001/001_pm_001.jpg
/var/www/media_test2/media002/002_pm_001.jpg
/var/www/media_test2/media003/003_pm_001.jpg
/var/www/media_test2/media004/004_pm_001.jpg

一种想法是,通过使用<代码>ls绘制一份图像清单,列出所有照片和没有<代码>的路径。 -> export that to a file ->building a cp 指挥:

cp /var/www/media_test1/media001/001_pm_001.jpg /var/www/media_test2/media001/001_pm_001.jpg
cp /var/www/media_test1/media002/002_pm_001.jpg /var/www/media_test2/media001/002_pm_002.jpg
...

然后执行指挥。

问题是,我不知道如何写这些指挥。

是否有更好的办法这样做? 有什么想法可以使用?

感谢

最佳回答

你们可以利用这一指挥系统这样做。 • 确保有目的地名录,然后运行:

find /var/www/media_test1/media001/ -type f -not -name "th*" -exec cp {} /var/www/media_test2/media001/ ;

这将找到从“th”开始的所有档案,并将其复制到/var/www/media_test2/media001/。

问题回答

我使用了<代码>mv。 这里指挥。 因为你首先说,“我不得不搬走某些档案”,但你只能将其改成<条码>cp。 两者的结构相同...... <代码><>>>> /代码>在<代码>末时,表示自动执行该代号的文字。 你实际上看不到这封信件,因此我在该职位结束时补充说。 <代码>mkdir-p将核对该名录是否存在,如果该名录确实存在,则该代码将予以核对。 如果<代码>mkdir>失效,则下一个指挥将不予执行。

# use `find  to get the main list of files.. 
# use `sed  to filter when both  NNN s match in: /mediaNNN/NNN...
# `sed  also build and executes the *move* script

basepath1=/var/www/media_test1/
basepath2=/var/www/media_test2/

find $basepath1/media[0-9][0-9][0-9] 
      -type f -name  [0-9][0-9][0-9]*.jpg  |
sed -nr "
s|$basepath1(/media([0-9]{3})/)2.*|
mkdir -p "$basepath21" &&

   mv -n "&" \\

         "$basepath21"|e"

Here is the generated script

mkdir -p "/var/www/media_test2/media001/" &&
   mv -n "/var/www/media_test1/media001/001_pm_001.jpg" 
         "/var/www/media_test2/media001/"
mkdir -p "/var/www/media_test2/media002/" &&
   mv -n "/var/www/media_test1/media002/002_pm_001.jpg" 
         "/var/www/media_test2/media002/"
mkdir -p "/var/www/media_test2/media003/" &&
   mv -n "/var/www/media_test1/media003/003_pm_001.jpg" 
         "/var/www/media_test2/media003/"
mkdir -p "/var/www/media_test2/media004/" &&
   mv -n "/var/www/media_test1/media004/004_pm_001.jpg" 
         "/var/www/media_test2/media004/"




相关问题
Signed executables under Linux

For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

热门标签