English 中文(简体)
如果在弹壳中重新命名时已经存在档案,那么我如何创建新目录,称为重复。
原标题:How do I create a new directory called duplicates if a file already exists when renaming in c shell
  • 时间:2011-10-04 03:21:32
  •  标签:
  • shell
  • csh

I have a script that renames files with.JPEG ext to .jpg but if it renames one and it already exists I need it to create a new directory called duplicates and move the file there instead of overwritting it.

问题回答

我没有对此进行测试:

foreach j (*.JPEG *.JPG)
    set target = $j:r.jpg
    if (-e $target) then
        mkdir -p duplicates  # create directory if it doesn t already exist
        mv $j duplicates/$target
    else
        mv $j $target
    endif
end

But consider whether csh is the best tool for this kind of thing:

这将使你能够测试档案的存在:

test -e img.jpg

你可以测试档案的存在,如果确实存在,则将其移至复制件。 a. 创建一个称为重复的夹:

mkdir duplicates

希望会有所帮助。





相关问题
KornShell- Creating a fixed width text file

I need to create a simple fixed width text file in KornShell (ksh). My current attempt using printf to pad the string isn t working out very well. What s the shortest, cleanest way to create a fixed ...

unix find command

how to use the find command to find files/directories which are not matching the pattern. for eg: find <some options > -name "dontfile.txt" should give me output of all the find whose file ...

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

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

1. 露台式照像

在Windows XP中,没有一时出现指挥时,是否有办法操作一种灰色文字? 我常常需要把“善待”(工作)与“灰色”同起来,即使我的文字没有产出,......

热门标签