请稍侯

常用的终端命令

10 July 2018

常用的终端命令

文件重命名

批量改文件: for i in *; do mv $i $i.mp3; done;
去掉多余的mp3后缀: for i in *; do mv $i ${i/.mp3.mp3/.mp3}; done;
*文件名全改成小写: for i in *; do mv $i ` echo "print '$i'.lower()" | python `; done;
for i in *; do mv $i ` echo "print '$i'.downcase()" | ruby `; done;
for i in *; do mv $i ` perl -e "print lc('$i');" `; done;
for i in *; do mv $i ` php -r "print strtolower('$i');" `; done;
for i in *; do mv $i ` echo "$i" | awk '{ print tolower($1) }' `; done;

文件名全改成大写:for i in *; do mv $i ` echo "print '$i'.upper()" | python `; done;
for i in *; do mv $i ` echo "print '$i'.upcase()" | ruby `; done;
for i in *; do mv $i ` perl -e "print uc('$i');" `; done;
for i in *; do mv $i ` php -r "print strtoupper('$i');" `; done;
for i in *; do mv $i ` echo "$i" | awk '{ print toupper($1) }' `; done;
按升序重命名:num=0;for i in *; do mv "$i" "$(printf '%03d' $num).${i#*.}"; ((num++)); done;

参考:https://stackoverflow.com/questions/2264428/how-to-convert-a-string-to-lower-case-in-bash

Python HTTPServer 和 FTPServer

HTTPServer: python -m SimpleHTTPServer 80
FTPServer: python -m pyftpdlib -p 21

SCP

从本地拷贝到远程 scp ./.gitignore luowei@wodedata.com:/var/www/music.wodedata.com/.gitignore

从远程拷贝到本地
scp luowei@wodedata.com:~/aaaa.txt ./aaaa.txt

scp 文件夹加上 -r 参数
scp -r ./xxx uowei@wodedata.com:~/xxx

文件及磁盘大小

查看文件大小
显示总量:du -sh
分别显示每个文件大小:du -h

查看磁盘空间大小命令:df -hdf -hl

压缩与解压

zip压缩 zip -r -e myfile.zip someThing
-e:表示压缩文件需要加密 或 直接加密:zip -r -P Password01! aaaa.zip SomeDir

unzip解压 unzip aaaa.zipunzip -P Password01! aaaa.zip 在指定目录/tmp下解压缩,如果已有相同的文件存在,要求unzip命令不覆盖原先的文件:unzip -n aaaa.zip -d /tmp 查看压缩文件目录,但不解压:unzip -v aaaa.zip