---
title: "我常用的shell 命令"
author: "bocai2015"
date: "2011-04-01T10:25:37Z"
tags: ["F#", "J#", "Linux", "PHP", "Perl"]
categories: ["编程语言"]
slug: "shell"
draft: false
lastmod: "2011-04-01T10:49:07Z"
id: 982684
url: "https://bocai2015.iteye.com/blog/982684"
---

for j in *.JPG; do echo `echo mv $j ${j%%.*}.jpg`; done

下面是修改文件名大写为小写的一个命令：

　　for i in $*

　　do

　　mv $i `echo $i | tr A-Z a-z`

　　done

for file in *.*;do newname=`echo $file | tr "[A-z]" "[a-z]"`;mv -f $file $newname 2>/dev/null;done

1.查找当前目录下文件扩展名为"JPG"的文件数量

 

find . -type f -name '*.JPG' | wc -l

 

2.把当前目录下文件中的大写英文字母更改为小写

for file in *.*;do newname=`echo $file | tr "[A-Z]" "[a-z]"`;mv -f $file $newname 2>/dev/null;done

 

3.查找当前目录下扩展名为"JPG"的文件并修改为"jpg"

find . -type f -name '*.JPG' -exec rename 'JPG' 'jpg' {} \;


最近工作用到批量替换的命令（linux）
2010年 5月9日 阅读：640 发表于 : 日志 发表评论 批量替换文件名a文件：
find -name 'a.php' -exec cp /a.php {} -f \;批量拷贝file.php到目录名为B的文件夹：
find -name B -type d -exec cp /file.php {} -f \;高级用法加perl，批量替换文件名为file.php的文件里面的某些内容：
find -name 'file.php' | xargs perl -pi -e "s|原内容|要替换的内容|g"批量删除文件名为file.php的文件夹：
find -name 'file.php' | xargs rm -rf
find -type f -name '*.jad' -exec rename 's/jad/java/' {} \;
find -type f -name '*.jad' -exec rename.ul 'jad' 'java' {} \;