Unix Shortcuts
find . -name "*.java" -type f
find all the files within a director and its sub-directory ended with .java
rm *~
delete all the files ended with ~
grep setup BotConfigTODO > log
(grep the lines including setup keyword and save it in a file called log)
ps aux | grep 'less Dockerfile'| awk '{print $2}' | head -1 | xargs kill -9
(Kill the first greped process)
docker exec -i cassandra /bin/bash -c "cat -- > InsertStackState.txt" < InsertStackState.txt
docker exec -it cassandra bash
find ./* -iname "pom.xml"
zless dash-container.log.2015-10-13_10.gz
zgrep 19363011 dash-container.log.2015-10-13_10.gz --color
docker stop service_name (restart - if service dint failed already)
u need to be in that node
if it already failed - fleetctl start service_name
head -5 science.txt
tail -5 science.txt
grep -ivc ‘keyword science’ science.txt
-v display those lines that do NOT match
-n precede each matching line with the line number
-c print only the total count of matched lines
netstat -a | grep LISTEN
Check the top 10 memory/cpu eaters
ps aux --sort=-%mem | awk 'NR<=10{print $0}'
Check the default heap size of jvm
java -XX:+PrintFlagsFinal -version | grep HeapSize
Check the access and modification time of a file
stat filename.txt
Run commands in the background
1. command & :command running in the background will be stopped if you close the terminal/session
2. nohup command & : command will still run in the background even if you close the terminal/session
Get unique string from lines in a file
grep -o 'sysToteId.*' IMS.txt | sort -u | cut -f1 -d',' | uniq | less -S | wc -l
zgrep "Broadcasting MoveBinsToInventoryManagementNotification.*MIXED_PRODUCT_PURGING" dash-container.log.2016-05-14_*.gz | grep -o 'sysToteId.*' | sort -u | cut -f1 -d',' | uniq | less -S | wc -l
Or
zgrep "Broadcasting MoveBinsToInventoryManagementNotification.*MIXED_PRODUCT_PURGING" dash-container.log.2016-05-14_*.gz | grep -o 'sysToteId.*,' | grep -o ^[^,]* | uniq | less -S
Check whether disk is full
#!/bin/bash
disk_usage=$(df -h | grep "sda5" | awk '{split($5,p,"%"); print p[1]}')
if [ "$disk_usage" -gt 90 ]; then
echo -e "Disk is full, usage is \e[1;31m$disk_usage%\e[0m"
echo "Disk is full, usage is $disk_usage%" | mailx -r "chi.ronchy.zhang@gmail.com" -s "SUBJECT" "chi.zhang@ocado.com"
Fi
Onsite Version
checkDiskUsage.sh is
#!/bin/bash
export PROFILE=andoverambientCR1
disk_usage=$(df -h | grep "vg-root" | awk '{split($5,p,"%"); print p[1]}')
if [ "$disk_usage" -gt 85 ]; then
echo -e "$PROFILE Disk is full, usage is \e[1;31m$disk_usage%\e[0m"
echo "$PROFILE Disk is full, usage is $disk_usage%" | mailx -s "$PROFILE Disk is full, usage is $disk_usage%" "dash_container@ocado.com"
Fi
Upload the script to the ambient box
crontab -e
add
0 * * * * /app/checkDiskUsage.sh > /dev/null 2>&1
Improved Version
#!/bin/bash
export PROFILE=andoverchillCR1
root_disk_usage=$(df -h | grep "vg-root" | awk '{split($5,p,"%"); print p[1] }')
data_disk_usage=$(df -h | grep "vg-data" | awk '{split($5,p,"%"); print p[1] }')
email_message="$PROFILE Disk is full, root partition usage is $root_disk_usage% and data partition usage is $data_disk_usage%"
if [ "$data_disk_usage" -gt 85 ] || [ "$root_disk_usage" -gt 85 ]; then
echo "$email_message" | mailx -s "$email_message" dash_container@ocado.com,dash_controller@ocado.com
fi
sed
http://www.grymoire.com/Unix/Sed.html#TOC
s Substitute command
A simple example is changing "day" in the "old" file to "night" in the "new" file:
sed s/day/night/ <old >new
Or another way (for UNIX beginners),
sed s/day/night/ old >new
The character after the s is the delimiter. It is conventionally a slash, because this is what ed, more, and vi use. It can be anything you want
The escaped parentheses (that is, parentheses with backslashes before them) remember a substring of the characters matched by the regular expression. You can use this to exclude part of the characters matched by the regular expression. The "\1" is the first remembered pattern, and the "\2" is the second remembered pattern. Sed has up to nine remembered patterns.
echo abcd123 | sed 's/\([a-z]*\).*/\1/'
This will output "abcd" and delete the numbers.
If you want it to make changes for every word, add a "g" after the last delimiter and use the work-around:
sed 's/[^ ][^ ]*/(&)/g' <old >new
With no flags, the first matched substitution is changed. With the "g" option, all matches are changed. If you want to modify a particular pattern that is not the first one on the line, you could use "\(" and "\)" to mark each pattern, and use "\1" to put the first pattern back unchanged. This next example keeps the first word on the line but deletes the second:
sed 's/\([a-zA-Z]*\) \([a-zA-Z]*\) /\1 /' <old >new
Yuck. There is an easier way to do this. You can add a number after the substitution command to indicate you only want to match that particular pattern. Example:
sed 's/[a-zA-Z]* //2' <old >new
You can combine a number with the g (global) flag. For instance, if you want to leave the first word alone, but change the second, third, etc. to be DELETED instead, use /2g:
sed 's/[a-zA-Z]* /DELETED /2g' <old >new
There is one more flag that can follow the third delimiter. With it, you can specify a file that will receive the modified data. An example is the following, which will write all lines that start with an even number, followed by a space, to the file even:
sed -n 's/^[0-9]*[02468] /&/w even' <file
This flag makes the pattern match case insensitive. This will match abc, aBc, ABC, AbC, etc.:
sed -n '/abc/I p' <old >new
p is the print command
If you need to make two changes, and you didn't want to read the manual, you could pipe together multiple sed commands:
sed 's/BEGIN/begin/' <old | sed 's/END/end/' >new
This used two processes instead of one. A sed guru never uses two processes when one can do.
One method of combining multiple commands is to use a -e before each command:
sed -e 's/a/A/' -e 's/b/B/' <old >new
If you have many commands and they won't fit neatly on one line, you can break up the line using a backslash:
sed -e 's/a/A/g' \
-e 's/e/E/g' \
-e 's/i/I/g' \
-e 's/o/O/g' \
-e 's/u/U/g' <old >new
Unix Shortcuts的更多相关文章
- Android 7.1 - App Shortcuts
Android 7.1 - App Shortcuts 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Shortcuts 文中如有纰漏,欢迎大家留言 ...
- Android 7.1 App Shortcuts使用
Android 7.1 App Shortcuts使用 Android 7.1已经发了预览版, 这里是API Overview: API overview. 其中App Shortcuts是新提供的一 ...
- Unix&Linux技术文章目录(2015-12-22更新)
Unix & Linux 方面的博客整理.归纳分类,要坚持不懈的学习Unix &Linux,加油!技术需要累积和沉淀.更需要锲而不舍的精神.持之以恒的毅力!借此下面名句勉励自己! 书上 ...
- C#中DateTime.Ticks属性及Unix时间戳转换
1.相关概念 DateTime.Ticks:表示0001 年 1 月 1 日午夜 12:00:00 以来所经历的 100 纳秒数,即Ticks的属性为100纳秒(1Ticks = 0.0001毫秒). ...
- 《UNIX环境高级编程》笔记——3.文件IO
一.引言 说明几个I/O函数:open.read.write.lseek和close,这些函数都是不带缓冲(不带缓冲,只调用内核的一个系统调用),这些函数不输入ISO C,是POSIX的一部分: 多进 ...
- 《UNIX环境高级编程》笔记——2.标准和实现
随着UNIX各种衍生版本不断发展壮大,标准化工作就十分必要.其实干啥事都是这样,玩的人多了,必须进行标准化. 一.UNIX标准 1.1 ISO C(ANSI C) ANSI:Amerocan Nato ...
- 《UNIX环境高级编程》笔记——1.UNIX基础知识
这一章节侧重一些基本概念和书中用到的一些名词. 一.引言 所有的操作都提供服务,典型的服务包括:执行新程序.打开文件.读写文件.分配存储区以及获得当前时间等. 二.UNIX体系结构 其实linux常见 ...
- UNIX下的LD_PRELOAD环境变量
UNIX下的LD_PRELOAD环境变量 也许这个话题并不新鲜,因为LD_PRELOAD所产生的问题由来已久.不过,在这里,我还是想讨论一下这个环境变量.因为这个环境变量所带来的安全问题非常严重,值得 ...
- Unix网络单词汇总
Chrome开发者工具 Elements(元素).Network(网络).Sources(源代码:调试JS的地方).Timeline(时间线).Profiles(性能分析).Resources(资源: ...
随机推荐
- 老李分享:接电话扩展之uiautomator 2
主要的类就是上面的PhoneReceiver广播接收者.来电的时候,我们记录下电话号码,等该来电挂断以后,立即回拨给对方.配置文件如下: <?xml version="1.0" ...
- 手机自动化测试:Appium源码分析之跟踪代码分析七
手机自动化测试:Appium源码分析之跟踪代码分析七 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.poptest推出手机自 ...
- 3.XML的格式化显示
使用CSS/XSLT格式化XML,可以使XML具有更加多彩的显示效果. 3.1 使用CSS格式化显示XML 使用CSS格式化XML只需要在XML中加上: <?xml-stylesheet typ ...
- C#设计模式:责任链模式
设计模式是面向对象编程的基础,是用于指导程序设计.在实际项目开发过程中,并不是一味将设计模式进行套用,也不是功能设计时大量引入设计模式.应该根据具体需求和要求应用适合的设计模式.设计模式是一个老话题了 ...
- Java 中的 String 类常用方法
字符串广泛应用在Java编程中,在Java中字符串属于对象,String 类提供了许多用来处理字符串的方法,例如,获取字符串长度.对字符串进行截取.将字符串转换为大写或小写.字符串分割等. Strin ...
- 装饰器模式(Decorator)——深入理解与实战应用
本文为原创博文,转载请注明出处,侵权必究! 1.初识装饰器模式 装饰器模式,顾名思义,就是对已经存在的某些类进行装饰,以此来扩展一些功能.其结构图如下: Component为统一接口,也是装饰类和被装 ...
- 京东笔试---通过考试(DP)
题目描述 小明同学要参加一场考试,考试一共有n道题目,小明必须作对至少60%的题目才能通过考试.考试结束后,小明估算出每题作对的概率,p1,p2,...,pn,你能帮他算出他通过考试的概率吗 ...
- jvm的搭建
首先先 说明一下接下来要用到的,环境变量中的path和classpath的区别 1.path路径用来告诉计算机.exe文件的路径,classpath路径是用来告诉计算机.class文件的路径 2.系统 ...
- webrtc学习笔记1(建立连接基本流程)
最近在做一个基于webrtc的视频软件,以下是自己对于上层建立通话连接流程的基本理解,记录于此. 假设A和B要建立视频通话,A为房间创建端,B为加入房间端: 1.A通过http登录.获取其他服务器地址 ...
- 完美实现在同一个页面中使用不同样式的artDialog样式
偶然发现artDialog.js这个插件,就被其优雅的设计及漂亮的效果深深吸引,在做例子时碰到了一些想当然它应该提供但却没有提供的功能,不过这都不影响我对它的喜爱,下面说一下遇到的问题吧! artDi ...