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 "[email protected]" -s "SUBJECT" "[email protected]"

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%" "[email protected]"

Fi

  1. Upload the script to the ambient box
  2. crontab -e
  3. 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" [email protected],[email protected]

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

时间: 2024-11-14 23:09:20

Unix Shortcuts的相关文章

【Python】Windows, Linux/UNIX, Mac OS X 下安裝 Python

下載地址:https://www.python.org/downloads/ 下載對應系統.對應位數的版本即可. [Windows] 一般選擇"Windows x86-64 executable installer",即 64 位兼容 32 位的可執行安裝程序. 打開安裝程序,先勾選"Add Python X.X to PATH",代表安裝時將 Python 對應版本目錄添加到 PATH 系統環境變量中,再選擇"Customize installation

ubuntu下matlab快捷键问题 shortcuts

matlab2014 安装说明参照:http://blog.csdn.net/zyh821351004/article/details/42212687 新装了个matlab2014 在ubuntu14.04下.发现快捷键总是出现问题,所以想找到解决重设快捷键的方法, 网上找了百度了会没找到,看到这个链接http://www.douban.com/note/301820026/   但还是不好找到对应位置.. ps:  有问题现在matlab  help 中搜搜看   Define Keyboa

Unix 环境高级编程 (APUE) 之 网络 IPC:套接字

一起学 Unix 环境高级编程 (APUE) 之 网络 IPC:套接字 . . . . . 目录 (一) 一起学 Unix 环境高级编程 (APUE) 之 标准IO (二) 一起学 Unix 环境高级编程 (APUE) 之 文件 IO (三) 一起学 Unix 环境高级编程 (APUE) 之 文件和目录 (四) 一起学 Unix 环境高级编程 (APUE) 之 系统数据文件和信息 (五) 一起学 Unix 环境高级编程 (APUE) 之 进程环境 (六) 一起学 Unix 环境高级编程 (APU

一个基于Unix套接字的注册登录系统

2016/5/5 今天,我参考<Unix网络编程-卷1>第5章的TCP回射客户/服务器程序写了一个简单的注册登录系统,其功能如下:(1)注册.客户端向服务器发送个人信息请求注册,服务器查询MySQL数据库以检查该客户是否已存在,若是则禁止注册,并返回“用户已存在,注册失败”的错误信息,否则将新用户信息添加到MySQL数据库,并返回“注册成功”的信息.(2)登录.客户端向服务器发送个人账号和密码等两项信息,服务器查询MySQL数据库以检查账号是否存在.账号和密码是否匹配,若不存在或不匹配则禁止登

php日期和时间基础知识--Unix时间戳

<?php /*1.取得当前的Unix时间戳 UNIX 时间戳(英文叫做:timestamp)是 PHP 中关于时间与日期的一个很重要的概念,它表示从 1970年1月1日 00:00:00 到当前时间的秒数之和. PHP提供了内置函数 time() 来取得服务器当前时间的时间戳.那么获取当前的UNIX时间戳就很简单了. */ $timer = time(); echo $timer; /*2.取得当前的日期 php内置了date()函数,来取得当前的日期. 函数说明:date(时间戳的格式, 规

六、Linux/UNIX操作命令积累【kill、netstat、df、du】

在使用Linux/UNIX下,经常会使用文本界面去设置系统或操作系统,作者本人在工作的过程也在不断接触这方面的命令,所以为此特酝酿.准备.开始了本文的编写.本文主要记录自己平时遇到的一些Linux/UNIX下操作命令,记录与整理一下,一可加深印象,二可记录分享.希望各位看官,对于不合适的或有歧义的地方,给予指明与说明,以便共同学习与提高. [转载使用,请注明出处:http://blog.csdn.net/mahoking] 023 kill命令:查看进程及杀死进程 查看进程使用ps命令,本例演示

unix 文件属性

在unix下提到文件属性,不得不提的一个结构就是stat,stat结构一般定义如下: struct stat { dev_t st_dev; /* ID of device containing file */ ino_t st_ino; /* inode number */ mode_t st_mode; /* protection */ nlink_t st_nlink; /* number of hard links */ uid_t st_uid; /* user ID of owner

Linux - Unix环境高级编程(第三版) 代码编译

Unix环境高级编程(第三版) 代码编译 本文地址:http://blog.csdn.net/caroline_wendy 时间:2014.10.2 1. 下载代码:http://www.apuebook.com/code3e.html 2. 安装依赖库:sudo apt-get install libbsd-dev  3. 进入下载目录make 4. 复制头文件和动态链接库 sudo cp ./include/apue.h /usr/include/ sudo cp ./lib/libapue

UNIX环境编程学习笔记(6)——文件I/O之判断文件类型

lienhua342014-09-01 1 文件类型 我们平时最常接触的文件类型有普通文件(regular file)和目录(di-rectory file),但是 UNIX 系统提供了多种文件类型: (1) 普通文件(regular file) 这种文件包含了某种形式的数据,这些数据无论是文件还是二进制对于 UNIX 内核而言都是一样的.对普通文件内容的解释有处理该文件的应用程序进行. (2) 目录文件(directory file) 目录文件包含了其他文件的名字以及指向与这些文件有关信息的指