[实践OK]在Linux的Shell系统下的Date/date函数用法,以及用format格式化获取昨天、明天或多天前的日期输出的用法~
Unix/LinuxC技术 jack 2017-7-20 16:51
背景:经常一些应用爱搞一天一个目录,天数多了里面文件也大了,磁盘也占满了,怎么办?得每天删除1个月的日志。于是一个月的时间就得用上了。
Mysql删除七天前的,搬过来:
我要的是这个:
一、Linux的Shell系统下的Date/date函数用法:
Egg: cat /root/del_catalina.sh
In Bash:
get year-month-day from date
DATE=`date +%Y-%m-%d`
get year-month-day hour:minute:second from date
DATE=`date +%Y-%m-%d:%H:%M:%S`
二、获取昨天、明天或多天前的日期:
在Linux中可以通过date命令获取昨天、明天、上个月、下个月、上一年和下一年
# 获取昨天
date -d 'yesterday' # 或 date -d 'last day'
# 获取明天
date -d 'tomorrow' # 或 date -d 'next day'
# 获取上个月
date -d 'last month'
# 获取下个月
date -d 'next month'
# 获取上一年
date -d ’last year'
# 获取下一年
date -d 'next year'
此外你可以获取多天前,多天后,多个月前,多个月后,多年前或多年后
# 三年前
date -d '3 year ago'
# 五年后
date -d '-5 year ago'
# 两天后
date -d '-2 day ago'
# 一个月前
date -d '1 month ago'
来自:https://my.oschina.net/aiguozhe/blog/57835
Mysql删除七天前的,搬过来:
我要的是这个:
一、Linux的Shell系统下的Date/date函数用法:
Egg: cat /root/del_catalina.sh
In Bash:
get year-month-day from date
DATE=`date +%Y-%m-%d`
get year-month-day hour:minute:second from date
DATE=`date +%Y-%m-%d:%H:%M:%S`
二、获取昨天、明天或多天前的日期:
在Linux中可以通过date命令获取昨天、明天、上个月、下个月、上一年和下一年
# 获取昨天
date -d 'yesterday' # 或 date -d 'last day'
# 获取明天
date -d 'tomorrow' # 或 date -d 'next day'
# 获取上个月
date -d 'last month'
# 获取下个月
date -d 'next month'
# 获取上一年
date -d ’last year'
# 获取下一年
date -d 'next year'
此外你可以获取多天前,多天后,多个月前,多个月后,多年前或多年后
# 三年前
date -d '3 year ago'
# 五年后
date -d '-5 year ago'
# 两天后
date -d '-2 day ago'
# 一个月前
date -d '1 month ago'
来自:https://my.oschina.net/aiguozhe/blog/57835
Linux下查找并删除大于多少天的文件
Unix/LinuxC技术 jack 2017-7-12 20:55
find . -mtime +90 -exec sh -c "rm -rf {}" \;
[实践OK] unzip 解压文件到指定的目录-d,zip和unzip是两个不同的rpm包。
Unix/LinuxC技术 jack 2017-7-12 11:24
背景:在打包时,需要对源文件是ZIP格式的,给unzip解压文件到指定的打包目录$RPM_BUILD_DIR,查了下,也就是得用到unzip的-d参数。
yum install zip -y
yum install unzip -y
来源 :http://blog.csdn.net/ljchlx/article/details/8028672
yum install zip -y
yum install unzip -y
来源 :http://blog.csdn.net/ljchlx/article/details/8028672
tar -xzvf mysql-5.6.15.tar.gz -C ./mysql-5.6.15 --strip-components 1
实践:
man tar
tar --strip-components = NUMBER
...skipping...
--strip-components=NUMBER
strip NUMBER leading components from file names on extraction
tar -zxvf codes.doc.qr.cntv.net.tar.gz -C abc/. --strip-components 1
打包来自:codes.doc.qr.cntv.net codes.doc.qr.cntv.net.tar.gz
再看解压后的目录无codes.doc.qr.cntv.net外层目录了:
tree -L 1 abc/
abc/
├── Application
├── index.php
├── netchkrs
├── Public
├── showdoc.sql
├── test.php
├── Text
└── ThinkPHP
实践来自:http://www.cnblogs.com/zxiaozhou/p/6068867.html
实践:
man tar
tar --strip-components = NUMBER
...skipping...
--strip-components=NUMBER
strip NUMBER leading components from file names on extraction
tar -zxvf codes.doc.qr.cntv.net.tar.gz -C abc/. --strip-components 1
打包来自:codes.doc.qr.cntv.net codes.doc.qr.cntv.net.tar.gz
再看解压后的目录无codes.doc.qr.cntv.net外层目录了:
tree -L 1 abc/
abc/
├── Application
├── index.php
├── netchkrs
├── Public
├── showdoc.sql
├── test.php
├── Text
└── ThinkPHP
实践来自:http://www.cnblogs.com/zxiaozhou/p/6068867.html
在secureCRT使用vim,alt键映射(alt+b,alt+f在shell里是前后一个单词)都被secureCRT占用了,能屏蔽吗?
Unix/LinuxC技术 jack 2017-7-12 09:45
背景:在secureCRT使用vim,alt键映射都被secureCRT占用了,导致设置alt开头的快捷键都不能用,这很不方便 有办法解决这一问题吗?
option -> session options -> termianl -> emulation -> use alt as meta key
vim依然无法正确识别到alt键。
解决了,设置xterm方式就好了。
问题描述:SecureCRT通过ssh登陆一台linux,alt键映射(alt+b,alt+f在shell里是前后一个单词)都被secureCRT占用了。
解决办法 secureCRT -> 选项 -> 会话选项 -> 仿真 -> 映射键; 勾上backspace发送delete。
secureCRT
-> 选项 -> 会话选项 -> 仿真->emacs;勾上use alt as meta key
SecureCRT最常用的的:alt+b打开一个目录(下一堆IP)和一个IP的,就没法用了,但是提高了操作Shell出现错误的速度。这个打开IP的操作并不常用。
但是那个切换Alt+1,Alt+2...,切换标签的不好使了,艹。后来放弃为了实现alt+b,alt+f在shell里是前后一个单词的理想了,有Ctrl+f,Ctrl+b一个一个跳也成,姑且算是习惯了,得了。
From:https://www.zhihu.com/question/21608031
快捷方式之 securecrt/SecureCRT的delete键向后删除键变为Backspace键之解决办法:
http://jackxiang.com/post/9342/
option -> session options -> termianl -> emulation -> use alt as meta key
vim依然无法正确识别到alt键。
解决了,设置xterm方式就好了。
问题描述:SecureCRT通过ssh登陆一台linux,alt键映射(alt+b,alt+f在shell里是前后一个单词)都被secureCRT占用了。
解决办法 secureCRT -> 选项 -> 会话选项 -> 仿真 -> 映射键; 勾上backspace发送delete。
secureCRT
-> 选项 -> 会话选项 -> 仿真->emacs;勾上use alt as meta key
SecureCRT最常用的的:alt+b打开一个目录(下一堆IP)和一个IP的,就没法用了,但是提高了操作Shell出现错误的速度。这个打开IP的操作并不常用。
但是那个切换Alt+1,Alt+2...,切换标签的不好使了,艹。后来放弃为了实现alt+b,alt+f在shell里是前后一个单词的理想了,有Ctrl+f,Ctrl+b一个一个跳也成,姑且算是习惯了,得了。
From:https://www.zhihu.com/question/21608031
快捷方式之 securecrt/SecureCRT的delete键向后删除键变为Backspace键之解决办法:
http://jackxiang.com/post/9342/
Linux下使cp命令不提示覆盖文件,cp的代表什么意思呢
Unix/LinuxC技术 jack 2017-7-11 17:17
实践如下:
\cp -r * ../gpac/extra_lib
查找下原因:
实际上cp默认是会覆盖的,出现你这种情况是因为cp被alias成cp -i了,可以通过alias命令查看。
\cp则是告诉shell不要去查alias,直接执行原本的cp
目前,我得知有四种方法:
1.在调用cp的时候加入绝对路径(可通过whereis cp命令得到),如
/bin/cp -f file dir
2.通过直接执行下面的语句调用系统原始的命令:
\cp -f file dir
3.在~/.bashrc里面注释掉 Alias cp='cp -i'
4.unalias cp ,然后再使用cp,但使用后还原alias cp='cp -i'
来自:http://www.oschina.net/question/1588291_166511
\cp -r * ../gpac/extra_lib
查找下原因:
实际上cp默认是会覆盖的,出现你这种情况是因为cp被alias成cp -i了,可以通过alias命令查看。
\cp则是告诉shell不要去查alias,直接执行原本的cp
目前,我得知有四种方法:
1.在调用cp的时候加入绝对路径(可通过whereis cp命令得到),如
/bin/cp -f file dir
2.通过直接执行下面的语句调用系统原始的命令:
\cp -f file dir
3.在~/.bashrc里面注释掉 Alias cp='cp -i'
4.unalias cp ,然后再使用cp,但使用后还原alias cp='cp -i'
来自:http://www.oschina.net/question/1588291_166511
Linux下编译源代码时注意一下加上那个Include和Lib路径。
Unix/LinuxC技术 jack 2017-7-11 14:35
Mplayer Error: yasm not found, use --yasm='' if you really want to compile without
背景:就是想把博文里的一些链接给批量替换一下,如:justwinit.cn 替换为jackxiang.com, 这样式的。
二)如对博客里涉及到的HostIP进行替换:
遇到这么个情况:
比如:
Msql里面的某个表的某个字段里面存储的是一个人的地址,有一天这个地址的里面的某个地
名变了,那么他的地址也就要变:
比如:
原来是:
现在这个成都市变为了 “天府”市···
所以,addr字段里面的所有的值,都要把成都市改为 天府市
解决方法:
sql语句:
[sql] view plain copy
update 表名 set 字段名=REPLACE (字段名,'原来的值','要修改的值')
当然,也可以添加条件:
最后的效果:
[sql] view plain copy
number addr
01 四川省天府市XXXXXX街道05号
02 四川省天府市XXXXXX街道07号
03 四川省天府市XXXXXX街道09号
04 四川省天府市XXXXXX街道04号
来自:http://blog.csdn.net/yuekunge/article/details/14170055
二)如对博客里涉及到的HostIP进行替换:
遇到这么个情况:
比如:
Msql里面的某个表的某个字段里面存储的是一个人的地址,有一天这个地址的里面的某个地
名变了,那么他的地址也就要变:
比如:
原来是:
现在这个成都市变为了 “天府”市···
所以,addr字段里面的所有的值,都要把成都市改为 天府市
解决方法:
sql语句:
[sql] view plain copy
update 表名 set 字段名=REPLACE (字段名,'原来的值','要修改的值')
当然,也可以添加条件:
最后的效果:
[sql] view plain copy
number addr
01 四川省天府市XXXXXX街道05号
02 四川省天府市XXXXXX街道07号
03 四川省天府市XXXXXX街道09号
04 四川省天府市XXXXXX街道04号
来自:http://blog.csdn.net/yuekunge/article/details/14170055
Linux 下进入含空格的目录(以及文件夹名开头为`(`)
Unix/LinuxC技术 jack 2017-7-9 21:10
[root@zhang ~]# cd my document
cd 一个含空格的目录,会被视为俩个目录,而有优先进入第一个目录(如果两个目录都存在的话):
使用单引号
[root@zhang ]# cd 'my document'
对空格转义
[root@zhang ~]# cd my\ document
在第一个单词之后按下 tab 键也是一样的处理方法,即对空格进行转义;
使用 * 进行匹配
[root@zhang ~]# cd my*document
对于文件夹名开头为(的情况
同样,要么使用单引号,要么使用\,进行转义;
来自:http://blog.csdn.net/lanchunhui/article/details/51211165
参考:http://www.cnblogs.com/wjyHIT2011/p/6801727.html
cd 一个含空格的目录,会被视为俩个目录,而有优先进入第一个目录(如果两个目录都存在的话):
使用单引号
[root@zhang ]# cd 'my document'
对空格转义
[root@zhang ~]# cd my\ document
在第一个单词之后按下 tab 键也是一样的处理方法,即对空格进行转义;
使用 * 进行匹配
[root@zhang ~]# cd my*document
对于文件夹名开头为(的情况
同样,要么使用单引号,要么使用\,进行转义;
来自:http://blog.csdn.net/lanchunhui/article/details/51211165
参考:http://www.cnblogs.com/wjyHIT2011/p/6801727.html
说明:linux系统下会有一个hash表,当你刚开机时这个hash表为空,每当你执行过一条命令时,hash表会记录下这条命令的路径,就相当于缓存一样。第一次执行命令shell解释器默认的会从PATH路径下寻找该命令的路径,当你第二次使用该命令时,shell解释器首先会查看hash表,没有该命令才会去PATH路径下寻找。
hash表的作用:大大提高命令的调用速率。
hash的参数:
[root@redhat ~]# hash //输入hash或hash -l 可以查看hash表的内容,我刚开机所以为空
hash: hash table empty
[root@redhat ~]# hash -l
hash: hash table empty
当我执行过2条命令后再看:
[root@redhat ~]# hash //hash表会记录下执行该命令的次数,以及命令的绝对路径
hits command
1 /bin/cat
1 /bin/ls
[root@redhat ~]# hash -l //加参数-l既可以看到hash表命令的路径,也可以看到它的名字,说不定会有别名哦
builtin hash -p /bin/cat cat
builtin hash -p /bin/ls ls
[root@redhat ~]# hash -p /bin/ls bb //添加hash表,可以看到我把ls命令重新写了一遍,改名为bb
[root@redhat ~]# bb //当我执行bb时就是执行ls命令
anaconda-ks.cfg icmp_echo_ignore_aly~ pub.key
dead.letter icmp_echo_ignore_alz~ rpmbuild
icmp_echo_ignore_all~ install.log RPM-GPG-KEY-useradd
icmp_echo_ignore_alw~ install.log.syslog RPM-GPG-KEY-westos
icmp_echo_ignore_alx~ passwd
[root@redhat ~]# hash -t ls //-t参数可以查看hash表中命令的路径,要是hash表中没有怎么办?
/bin/ls
[root@redhat ~]# hash -t df //我没使用过df,执行hash,就会提示找不到该命令
-bash: hash: df: not found
[root@redhat ~]# hash -r //清楚hash表,清楚的是全部的
[root@redhat ~]# hash -l
hash: hash table empty
[root@redhat ~]# hash -l
builtin hash -p /bin/cat cat
builtin hash -p /bin/ls ls
[root@redhat ~]# hash -d cat //清楚其中的某一条
[root@redhat ~]# hash -l
builtin hash -p /bin/ls ls
From:http://www.cnblogs.com/linux-super-meng/p/3788739.html
hash表的作用:大大提高命令的调用速率。
hash的参数:
[root@redhat ~]# hash //输入hash或hash -l 可以查看hash表的内容,我刚开机所以为空
hash: hash table empty
[root@redhat ~]# hash -l
hash: hash table empty
当我执行过2条命令后再看:
[root@redhat ~]# hash //hash表会记录下执行该命令的次数,以及命令的绝对路径
hits command
1 /bin/cat
1 /bin/ls
[root@redhat ~]# hash -l //加参数-l既可以看到hash表命令的路径,也可以看到它的名字,说不定会有别名哦
builtin hash -p /bin/cat cat
builtin hash -p /bin/ls ls
[root@redhat ~]# hash -p /bin/ls bb //添加hash表,可以看到我把ls命令重新写了一遍,改名为bb
[root@redhat ~]# bb //当我执行bb时就是执行ls命令
anaconda-ks.cfg icmp_echo_ignore_aly~ pub.key
dead.letter icmp_echo_ignore_alz~ rpmbuild
icmp_echo_ignore_all~ install.log RPM-GPG-KEY-useradd
icmp_echo_ignore_alw~ install.log.syslog RPM-GPG-KEY-westos
icmp_echo_ignore_alx~ passwd
[root@redhat ~]# hash -t ls //-t参数可以查看hash表中命令的路径,要是hash表中没有怎么办?
/bin/ls
[root@redhat ~]# hash -t df //我没使用过df,执行hash,就会提示找不到该命令
-bash: hash: df: not found
[root@redhat ~]# hash -r //清楚hash表,清楚的是全部的
[root@redhat ~]# hash -l
hash: hash table empty
[root@redhat ~]# hash -l
builtin hash -p /bin/cat cat
builtin hash -p /bin/ls ls
[root@redhat ~]# hash -d cat //清楚其中的某一条
[root@redhat ~]# hash -l
builtin hash -p /bin/ls ls
From:http://www.cnblogs.com/linux-super-meng/p/3788739.html
securecrt/SecureCRT的delete键向后删除键变为Backspace键之解决办法。
Unix/LinuxC技术 jack 2017-7-7 16:24
securecrt 在vt100/ANSI模式下会delete键和backspace键功能一样,都是删除前面的内容,要调整向后删除需要设置下:会话选项--终端--仿真--终端里选择linux模式或xterm即可。
From:http://soige.blog.51cto.com/512568/1323479/
相关之在secureCRT使用vim,alt键映射(alt+b,alt+f在shell里是前后一个单词)都被secureCRT占用了,能屏蔽吗?
http://jackxiang.com/post/9354/
From:http://soige.blog.51cto.com/512568/1323479/
相关之在secureCRT使用vim,alt键映射(alt+b,alt+f在shell里是前后一个单词)都被secureCRT占用了,能屏蔽吗?
http://jackxiang.com/post/9354/
FN+找到笔记本的Insert/Numlk键,按一下(在笔记本键盘的右上角一侧)
https://jingyan.baidu.com/article/ca00d56c981cc0e99eebcf92.html
https://jingyan.baidu.com/article/ca00d56c981cc0e99eebcf92.html
[实践OK]Linux下查看某一个程序或进程所使用的内存和所有进程前十名内存占用的方法,,及其查看Linux下某个进程占用内存和cpu的多少。
Unix/LinuxC技术 jack 2017-7-5 16:46
在 Linux 上进行开发和运营维护的时候,免不了要查看某一个程序所占用内存的情况。有很多个命令都可以达到我们的需求,这里给大家列举几个:
一)直接看某个进程的内存情况:
看下Nginx:
cat /proc/2821/status|grep VmRSS
VmRSS: 8776 kB
来自:http://www.jb51.net/LINUXjishu/66604.html
二)整体从系统层面看内存和cpu占用:
查看某个进程占用内存和cpu的多少:
找出消耗内存最多的前10名进程
找出使用CPU最多的前10名进程
# ps -auxf | sort -nr -k 3 | head -10
来自:http://blog.chinaunix.net/uid-20492804-id-265809.html
一)直接看某个进程的内存情况:
看下Nginx:
cat /proc/2821/status|grep VmRSS
VmRSS: 8776 kB
来自:http://www.jb51.net/LINUXjishu/66604.html
二)整体从系统层面看内存和cpu占用:
查看某个进程占用内存和cpu的多少:
找出消耗内存最多的前10名进程
# ps -auxf | sort -nr -k 4 | head -10
找出使用CPU最多的前10名进程
# ps -auxf | sort -nr -k 3 | head -10
来自:http://blog.chinaunix.net/uid-20492804-id-265809.html
PHP7高可用全球开发者大会的点滴记录片段~
Php/Js/Shell/Go jack 2017-7-3 20:40
goto 性能好,但编译时间长。
技术一定要伴随需求的,有一个场景的。
工程师的社会责任。
做技术还是要懂业务。
Opcache回收问题:负载高的问题。影响稳定性。
Kafka
PHP-FPM能否解决数据库连接池的问题:
1)定时重启的机制。
2)Php-FPM重启一下。
3)要规避一下。(业务时间点)
粗放、性能高,内存搞得很精细,也很耗时。
Mysql的连接池,Kafka~
返回值在后面:Grep。(指函数返回值和C不一样)
autoconf版本太底~
makefile也是为了提高效率。
掌握知识不同,用的方法不同,本质是一样的。
关注生成这个扩展能否写出来,再看Autoconf,再看编译系统。
学一个语言成了研究这个编辑器的问题,要Forcus在那个点上。
做一件事表非常难非常难的时候,你得怀疑这样做对不对?
脖子肌肉不够强。
高性能PHP7~
终端用户的真实体验,才是应用性能是否良好的最终标准。
技术一定要伴随需求的,有一个场景的。
工程师的社会责任。
做技术还是要懂业务。
Opcache回收问题:负载高的问题。影响稳定性。
Kafka
PHP-FPM能否解决数据库连接池的问题:
1)定时重启的机制。
2)Php-FPM重启一下。
3)要规避一下。(业务时间点)
粗放、性能高,内存搞得很精细,也很耗时。
Mysql的连接池,Kafka~
返回值在后面:Grep。(指函数返回值和C不一样)
autoconf版本太底~
makefile也是为了提高效率。
掌握知识不同,用的方法不同,本质是一样的。
关注生成这个扩展能否写出来,再看Autoconf,再看编译系统。
学一个语言成了研究这个编辑器的问题,要Forcus在那个点上。
做一件事表非常难非常难的时候,你得怀疑这样做对不对?
脖子肌肉不够强。
高性能PHP7~
终端用户的真实体验,才是应用性能是否良好的最终标准。
[实践OK]bad substitution的原因是用了sh不是bash导致的,Dockerfile批量替换里面的内容,cp filename{,bak} , find /var/www/ -name file -exec cp {}{,.bak} ; 递归备份文件,大括号扩展:cp和mv搭配{,}在shell作用,cp 快速备份 bash{} 扩展。
Unix/LinuxC技术 jack 2017-7-2 19:32
去掉没有用的扩展名:
mv /home/pi/.config/autostart/my.desktop.bak /home/pi/.config/autostart/my.desktop的shell花括号扩展简写:
拷贝新非后追加的文件名:
用Sed进行Dockerfile批量替换里面的内容:
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
-n, --quiet, --silent
这样感觉没有直接用shell 替换来得方便好写,如下:
和Sed不一样,没有最后一个斜杠:
${string/needreplace/placedstr}
$ a=abcdefg123
$ a=${a/123/456}
$ echo $a
abcdefg456
注意:不能是花括号里面有$,会报错:
bad substitution的原因是用了sh不是bash导致的:
在文件头里加上:
#!/bin/bash 替掉:#!/bin/sh
sh -x test.sh第3行总出现bad substitution提示信息,这与linux shell使用的是/bin/sh,还是/bin/bash有关系。我的脚本中指定使用的是/bin/bash shell,但是我在调试的时候使用的是sh shell,因此调试时导致错误提示信息。
原文链接:https://blog.csdn.net/u013516897/article/details/77965333
实战:
对docker tag 进行实践:
来自:https://jackxiang.com/post/9922/
先是打印出内容,然后再静默替换,然后再不区分大小写输入替换后的那行:echo filename|grep -i from;
xargs 的使用:
echo nginx-1.14.2/Dockerfile|xargs grep -i from
FROM registry.qr.xxxx.net/irdc_irdcops/alpine:3.10.0
要查找一个指定后缀文件里有没有一些指定字符串,显示出文件和行号等,还是用 xargs方便,如下:
上面一句顶exec两句,如下:
零.批量替换文件:
find . -type f -exec sed -n 's#S:"Username"=#S:"Username"=xiangdong#p' {} \;
一.
find /var/www/ -name file -exec cp {}{,.bak} \; 递归备份文件
1).
cp filename{,.bak}
quickly backup or copy a file with bash
2).
目录会自动omit删除掉; 目录不会复制;
来自:https://www.douban.com/note/422847745/
二.
cp filename{,.bak}
这个命令是用来把filename备份成filename.bak的
等同于命令
cp filename filename.bak
这里利用的是bash的brace expansion(大括号扩展)功能
按照bash手册(man bash)所述
bash支持{a,b,c}这样的扩展
比如a{d,c,b}e会被扩展成ade ace abe
所以
filename{,.bak}被扩展成filename filename.bak也就好理解了
同理可得:
tar cvfz leo{-20170202.tgz,}=tar cvfz leo-20170202.tgz leo
来自:http://leomars.blog.51cto.com/683246/1894566
三.
cp filename{,.bak} //注意花括号边并没有空格,否则就不 是扩展了,变成拷贝为{,.bak}文件了。
这个命令是用来把filename备份成filename.bak,等同于命令
cp filename filename.bak
这里利用的是bash的brace expansion(大括号扩展)功能,
按照bash手册(man bash)所述:
bash支持{a,b,c}这样的扩展,比如a{d,c,b}e 会被扩展成ade ace abe
所以
filename{,.bak}被扩展成filename filename.bak也就好理解了
原文http://www.haw-haw.org/node/1507
mv /home/pi/.config/autostart/my.desktop.bak /home/pi/.config/autostart/my.desktop的shell花括号扩展简写:
拷贝新非后追加的文件名:
用Sed进行Dockerfile批量替换里面的内容:
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
-n, --quiet, --silent
这样感觉没有直接用shell 替换来得方便好写,如下:
和Sed不一样,没有最后一个斜杠:
${string/needreplace/placedstr}
$ a=abcdefg123
$ a=${a/123/456}
$ echo $a
abcdefg456
注意:不能是花括号里面有$,会报错:
bad substitution的原因是用了sh不是bash导致的:
在文件头里加上:
#!/bin/bash 替掉:#!/bin/sh
sh -x test.sh第3行总出现bad substitution提示信息,这与linux shell使用的是/bin/sh,还是/bin/bash有关系。我的脚本中指定使用的是/bin/bash shell,但是我在调试的时候使用的是sh shell,因此调试时导致错误提示信息。
原文链接:https://blog.csdn.net/u013516897/article/details/77965333
实战:
对docker tag 进行实践:
来自:https://jackxiang.com/post/9922/
先是打印出内容,然后再静默替换,然后再不区分大小写输入替换后的那行:echo filename|grep -i from;
xargs 的使用:
echo nginx-1.14.2/Dockerfile|xargs grep -i from
FROM registry.qr.xxxx.net/irdc_irdcops/alpine:3.10.0
要查找一个指定后缀文件里有没有一些指定字符串,显示出文件和行号等,还是用 xargs方便,如下:
上面一句顶exec两句,如下:
零.批量替换文件:
find . -type f -exec sed -n 's#S:"Username"=#S:"Username"=xiangdong#p' {} \;
一.
find /var/www/ -name file -exec cp {}{,.bak} \; 递归备份文件
1).
cp filename{,.bak}
quickly backup or copy a file with bash
2).
目录会自动omit删除掉; 目录不会复制;
来自:https://www.douban.com/note/422847745/
二.
cp filename{,.bak}
这个命令是用来把filename备份成filename.bak的
等同于命令
cp filename filename.bak
这里利用的是bash的brace expansion(大括号扩展)功能
按照bash手册(man bash)所述
bash支持{a,b,c}这样的扩展
比如a{d,c,b}e会被扩展成ade ace abe
所以
filename{,.bak}被扩展成filename filename.bak也就好理解了
同理可得:
tar cvfz leo{-20170202.tgz,}=tar cvfz leo-20170202.tgz leo
来自:http://leomars.blog.51cto.com/683246/1894566
三.
cp filename{,.bak} //注意花括号边并没有空格,否则就不 是扩展了,变成拷贝为{,.bak}文件了。
这个命令是用来把filename备份成filename.bak,等同于命令
cp filename filename.bak
这里利用的是bash的brace expansion(大括号扩展)功能,
按照bash手册(man bash)所述:
bash支持{a,b,c}这样的扩展,比如a{d,c,b}e 会被扩展成ade ace abe
所以
filename{,.bak}被扩展成filename filename.bak也就好理解了
原文http://www.haw-haw.org/node/1507
[实践OK]如何在 CentOS 7 中安装或升级最新的内核
Unix/LinuxC技术 jack 2017-7-2 01:39
移步:https://jackxiang.com/post/8457/
====================================
[root@iz2ze0upl89i15wngnott5z tmp]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[root@iz2ze0upl89i15wngnott5z tmp]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
Retrieving http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:elrepo-release-7.0-2.el7.elrepo ################################# [100%]
[root@iz2ze0upl89i15wngnott5z tmp]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
elrepo-kernel | 2.9 kB 00:00:00
elrepo-kernel/primary_db | 1.7 MB 00:00:25
Loading mirror speeds from cached hostfile
* elrepo-kernel: ftp.ne.jp
Available Packages
kernel-lt.x86_64 4.4.75-1.el7.elrepo elrepo-kernel
kernel-lt-devel.x86_64 4.4.75-1.el7.elrepo elrepo-kernel
kernel-lt-doc.noarch 4.4.75-1.el7.elrepo elrepo-kernel
kernel-lt-headers.x86_64 4.4.75-1.el7.elrepo elrepo-kernel
kernel-lt-tools.x86_64 4.4.75-1.el7.elrepo elrepo-kernel
kernel-lt-tools-libs.x86_64 4.4.75-1.el7.elrepo elrepo-kernel
kernel-lt-tools-libs-devel.x86_64 4.4.75-1.el7.elrepo elrepo-kernel
kernel-ml.x86_64 4.11.8-1.el7.elrepo elrepo-kernel
kernel-ml-devel.x86_64 4.11.8-1.el7.elrepo elrepo-kernel
kernel-ml-doc.noarch 4.11.8-1.el7.elrepo elrepo-kernel
kernel-ml-headers.x86_64 4.11.8-1.el7.elrepo elrepo-kernel
kernel-ml-tools.x86_64 4.11.8-1.el7.elrepo elrepo-kernel
kernel-ml-tools-libs.x86_64 4.11.8-1.el7.elrepo elrepo-kernel
kernel-ml-tools-libs-devel.x86_64 4.11.8-1.el7.elrepo elrepo-kernel
perf.x86_64 4.11.8-1.el7.elrepo elrepo-kernel
python-perf.x86_64 4.11.8-1.el7.elrepo elrepo-kernel
[root@iz2ze0upl89i15wngnott5z tmp]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
[root@iz2ze0upl89i15wngnott5z tmp]# yum --enablerepo=elrepo-kernel install kernel-ml
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
elrepo | 2.9 kB 00:00:00
elrepo/primary_db | 427 kB 00:00:04
Loading mirror speeds from cached hostfile
* elrepo: ftp.ne.jp
* elrepo-kernel: ftp.ne.jp
Resolving Dependencies
--> Running transaction check
---> Package kernel-ml.x86_64 0:4.11.8-1.el7.elrepo will be installed
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================================
Package Arch Version Repository Size
========================================================================================================
Installing:
kernel-ml x86_64 4.11.8-1.el7.elrepo elrepo-kernel 41 M
Transaction Summary
========================================================================================================
Install 1 Package
Total download size: 41 M
Installed size: 185 M
Is this ok [y/d/N]: y
Downloading packages:
kernel-ml-4.11.8-1.el7.elrepo.x86_64. 16% [==== ] 67 kB/s | 6.6 MB 00:08:46
vi /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DEFAULT=0
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet net.ifnames=0"
GRUB_DISABLE_RECOVERY="true"
[root@iz2ze0upl89i15wngnott5z tmp]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.11.8-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-4.11.8-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-514.26.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-514.26.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-514.6.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-514.6.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-3c6ff97c6fbe4598b53fd04e08937468
Found initrd image: /boot/initramfs-0-rescue-3c6ff97c6fbe4598b53fd04e08937468.img
done
====================================
[root@iz2ze0upl89i15wngnott5z tmp]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[root@iz2ze0upl89i15wngnott5z tmp]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
Retrieving http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:elrepo-release-7.0-2.el7.elrepo ################################# [100%]
[root@iz2ze0upl89i15wngnott5z tmp]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
elrepo-kernel | 2.9 kB 00:00:00
elrepo-kernel/primary_db | 1.7 MB 00:00:25
Loading mirror speeds from cached hostfile
* elrepo-kernel: ftp.ne.jp
Available Packages
kernel-lt.x86_64 4.4.75-1.el7.elrepo elrepo-kernel
kernel-lt-devel.x86_64 4.4.75-1.el7.elrepo elrepo-kernel
kernel-lt-doc.noarch 4.4.75-1.el7.elrepo elrepo-kernel
kernel-lt-headers.x86_64 4.4.75-1.el7.elrepo elrepo-kernel
kernel-lt-tools.x86_64 4.4.75-1.el7.elrepo elrepo-kernel
kernel-lt-tools-libs.x86_64 4.4.75-1.el7.elrepo elrepo-kernel
kernel-lt-tools-libs-devel.x86_64 4.4.75-1.el7.elrepo elrepo-kernel
kernel-ml.x86_64 4.11.8-1.el7.elrepo elrepo-kernel
kernel-ml-devel.x86_64 4.11.8-1.el7.elrepo elrepo-kernel
kernel-ml-doc.noarch 4.11.8-1.el7.elrepo elrepo-kernel
kernel-ml-headers.x86_64 4.11.8-1.el7.elrepo elrepo-kernel
kernel-ml-tools.x86_64 4.11.8-1.el7.elrepo elrepo-kernel
kernel-ml-tools-libs.x86_64 4.11.8-1.el7.elrepo elrepo-kernel
kernel-ml-tools-libs-devel.x86_64 4.11.8-1.el7.elrepo elrepo-kernel
perf.x86_64 4.11.8-1.el7.elrepo elrepo-kernel
python-perf.x86_64 4.11.8-1.el7.elrepo elrepo-kernel
[root@iz2ze0upl89i15wngnott5z tmp]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
[root@iz2ze0upl89i15wngnott5z tmp]# yum --enablerepo=elrepo-kernel install kernel-ml
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
elrepo | 2.9 kB 00:00:00
elrepo/primary_db | 427 kB 00:00:04
Loading mirror speeds from cached hostfile
* elrepo: ftp.ne.jp
* elrepo-kernel: ftp.ne.jp
Resolving Dependencies
--> Running transaction check
---> Package kernel-ml.x86_64 0:4.11.8-1.el7.elrepo will be installed
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================================
Package Arch Version Repository Size
========================================================================================================
Installing:
kernel-ml x86_64 4.11.8-1.el7.elrepo elrepo-kernel 41 M
Transaction Summary
========================================================================================================
Install 1 Package
Total download size: 41 M
Installed size: 185 M
Is this ok [y/d/N]: y
Downloading packages:
kernel-ml-4.11.8-1.el7.elrepo.x86_64. 16% [==== ] 67 kB/s | 6.6 MB 00:08:46
vi /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DEFAULT=0
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet net.ifnames=0"
GRUB_DISABLE_RECOVERY="true"
[root@iz2ze0upl89i15wngnott5z tmp]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.11.8-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-4.11.8-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-514.26.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-514.26.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-514.6.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-514.6.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-3c6ff97c6fbe4598b53fd04e08937468
Found initrd image: /boot/initramfs-0-rescue-3c6ff97c6fbe4598b53fd04e08937468.img
done
请CentOS 7用户尽快更新:重要Linux Kernel补丁发布
Unix/LinuxC技术 jack 2017-7-2 01:21
基于Red Hat Enterprise Linux 7的自由发布源,CentOS 7分支继承了始终能获得最新内核安全更新的特性。今天,系统团队发布了一个非常重要的补丁,对近期发现的4个漏洞进行了及时修复,并推荐用户尽快安装补丁,升级至kernel-3.10.0-514.10.2.el7。
From:http://www.cnbeta.com/articles/soft/590259.htm
升级步骤:jackxiang.com/post/9319/
From:http://www.cnbeta.com/articles/soft/590259.htm
升级步骤:jackxiang.com/post/9319/




