以下shell在centos下使用.
获取一个压缩软件包的version(版本)
1
2
3
4
|
huwei@huwei:
/work/lnmp
$ ll -a php.
tar
.gz
-rw-rw-r-- 1 huwei huwei 18355694 3月 15 14:32 php.
tar
.gz
huwei@huwei:
/work/lnmp
$
tar
-ztf php.
tar
.gz|
tail
-1|
awk
-F
'/'
'{print $1}'
php-5.6.19
|
随机密码,对于mysql,不方便使用下划线以及特殊符号,使用mysqldump备份会失败.
1
|
passVar=`
cat
/dev/urandom
|
tr
-
dc
"a-zA-Z0-9"
|
fold
-w 20 |
head
-n 1`
|
检查是否存在mysql用户,如果不存在侧创建
1
2
3
4
5
6
|
id
mysql
if
[ $? -
ne
0 ]
then
useradd
mysql -s
/sbin/nologin
/usr/sbin/useradd
mysql -s
/sbin/nologin
fi
|
通过find命令查找大文件
1
2
|
huwei@huwei:~$
sudo
find
/home/huwei/
-
type
f -size +6G -
ls
20319458 6479992 -rw------- 1 huwei huwei 6637486080 3月 2 14:15
/home/huwei/VirtualBox
\ VMs
/test50/Snapshots/
{644badc2-a908-4e74-a2ec-a03f52b21578}.vdi
|
判别系统是32bit还是64bit
1
2
3
4
5
|
if
[[
"`/usr/bin/getconf LONG_BIT`"
-
eq
32 ]];
then
echo
"system is 32bit"
;
elif
[[
"`/usr/bin/getconf LONG_BIT`"
-
eq
64 ]];
then
echo
"system is 64bit"
;
fi
|
查找当前文件夹下后缀名为“.”的文件,重新命令为无后戳
比如2011114411. 命令为2011114411
1
|
ls
*.|
awk
-F
'.'
'{print $1}'
|
xargs
-i -t
mv
{}. {}
|
本文转自 yawei555 51CTO博客,原文链接:http://blog.51cto.com/huwei555/1751310,如需转载请自行联系原作者