`
yhz61010
  • 浏览: 552295 次
  • 来自: -
博客专栏
63c13ecc-ef01-31cf-984e-de461c7dfde8
libgdx 游戏开发
浏览量:11999
社区版块
存档分类
最新评论

[原创] Linux Shell 常用代码片断

阅读更多
持续更新中......

序列生成及数字填充
$ for i in $(seq -f "%03g" 1 5);do echo $i;done
001
002
003
004
005

拷贝文件时忽略指定的目录
rsync -av --progress sourcefolder /destinationfolder --exclude="thefoldertoexclude"
说明:thefoldertoexclude 是相对于 sourcefolder 目录的。也就是说忽略 sourcefolder 目录中的 thefoldertoexclude 目录

将当前目录下的所有文件的文件名变成小写字母
$ for i in `find .`;do mv $i `echo $i |tr [A-Z] [a-z]`;done


后台运行程序,将结果输出到 /dev/null 中,并将标准出错重定向到标准输出
nohup java -jar you-java.jar > /dev/null 2>&1 &


克隆网站到本地目录,可实现本地访问
https://askubuntu.com/a/512897
wget --mirror -p --convert-links -P ./LOCAL-DIR WEBSITE-URL
Options:
--mirror turns on options suitable for mirroring.
-p downloads all files that are necessary to properly display a given HTML page.
--convert-links after the download, convert the links in document for local viewing.
-P ./LOCAL-DIR saves all the files and directories to the specified directory.

获取 Shell 脚本的第一个参数和最后一个参数
#!/bin/bash
numArgs="$#"
echo "Number of args: $numArgs"

firstArg="$1"
echo "First arg: $firstArg"

lastArg="${!#}"
echo "Last arg: $lastArg"

allArgs="$@"
echo "All arguments: $allArgs"

allArgsExeptLastOne="${@:1:$(($#-1))}"
echo "All arguments except last one: $allArgsExeptLastOne"

测试结果如下:
$ ./test.sh a b c d e f
Number of args: 6
First arg: a
Last arg: f
All arguments: a b c d e f
All arguments except last one: a b c d e

0
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics