`

Shell skills take away

 
阅读更多

1. Empty log files in batch

find . -name "*.log" -exec bash -c ">{}" \;

 

2. Copy files in batch

find . -maxdepth 1 -type f -exec grep -q "pattern" '{}' ';' -exec cp '{}' /path/to/destination ';'

 

3. Rename file in batch

for i in `find . -maxdepth 1 -name "*SNAPSHOT*.jar"`; do mv $i `echo $i | sed s/-SNAPSHOT//`;done

 

4. Diff file (Advanced)

diff -r --ignore-all-space --ignore-blank-lines --ignore-matching-lines='#ident' --ignore-matching-lines='# **' --exclude=MANIFEST.MF --exclude="*test*" --exclude="*svn*"

 

5. Usage samples

if [ $# -ne 1 ]

then

        echo "Usage: `basename $0` {INTG|UA}"

        exit -1

else

        INPUT=`echo $1 | tr '[:lower:]' '[:upper:]'`

        if [ "$INPUT" = "UA" ]; then

                DBCONNECT_STRING=$DBCONNECT_STRING_CORP_POS_UAT

        elif [ "$INPUT" = "INTG" ]; then

                DBCONNECT_STRING=$DBCONNECT_STRING_CORP_POS_INTG

        else

                echo "Unkown parameter: $1"

                exit -1

        fi

fi

 

if [ $# -ne 2 ]

then

echo "Usage: `basename $0` {PORT-NUMBER} {MBEAN-NAME}"

exit -1

else 

RET=`expr match $1 "[0-9]*$"`

 

        if [ "$RET" -gt 0 ]; then

                       echo "Port number is: $1"

        else

echo "Invalid port number: $1"

exit -1

               fi

echo "MBean name is: $2"

fi

 

6. SVN revert or delete unversioned files in batch

svn st -u | awk -F "[ ]*" '{print $4}' | xargs svn revert

svn st -u | awk -F "[ \t]*" '{print $2}' | xargs rm -rf 

 

 

7. Remove version number in artifact id

echo ant-1.7.1.jar  | sed -e "s/-[0-9]\+\(\.[0-9]\)*\(_[A-Z][0-9]\)*\(-SNAPSHOT\)\?//g"

 

8. Find big files by du:

du -sh * 2>/dev/null | egrep "[0-9]+G"

du -s --block-size=M *  2>/dev/null| sort -rn

 

9. Check if specific class in jar file:

for i in `ls`; do jar tf $i | grep "ClassName" && echo $i; done

 

10. Collect footprint of CPU/MEM:

top -b  -d 1  -p pid  > stat.txt

 

11. Check the exact start time / running time of a specific process

ps -eo pid,lstart,etime | grep [pid]

 

12. Find PID of process which occupies specified port

/usr/sbin/lsof -i:[port] or netstat -ap | grep [port]

 

13. Find last reboot time of linux server

last reboot

 

 14. .bashrc

HOME=SOME_FOLDER

eval `dircolors ~/.dircolors`

PS1="\[\e[32;1m\][\$(date '+%m-%d %H:%M:%S')]\[\e[32;1m\][\[\e[36;1m\]\u\[\e[33;1m\]@\[\e[35;1m\]\h\[\e[33;1m\]:\[\e[36;1m\]\w\[\e[32;1m\]]$\[\e[0m\] "

 alias ll='ls -ltr --color=tty'

alias p='ps -eo pid,ppid,user,lstart,etime,args --no-headers --sort pid | grep -v $$ | awk '\''BEGIN {format = "\033[32m%5s \033[36m%5s \033[35m%-6s \033[33m%24s \033[36m%12s \033[0m%-s\n"; printf format, "PID", "PPID", "UID", "STARTED", "ELAPSED", "COMMAND"; printf format, "-----", "-----", "------", "------------------------", "------------", "--------------------" }; {printf "\033[32m%5s \033[36m%5s \033[35m%-6s \033[33m%-3s %-3s %-2s %-8s %-4s \033[36m%12s \033[0m", $1, $2, $3, $4, $5, $6, $7, $8, $9; for(i=10;i<NF;i++){printf $i " "}; print $NF}'\'''

function pg() {  

  p | egrep "PID|-----|$1" | grep -v egrep

 

15. Create root user

#useradd -o -u 0 -g 0 -M -d /root -s /bin/bash admin

 

#passwd admin

 

16. Check cron jobs for each user in the system

cat /etc/passwd | cut -d: -f1  | xargs -t -i  crontab -l -u {}

 

17. Create SSH tunnel user

#userdel -r tunneluser

#useradd -M -s /usr/sbin/nologin tunneluser

#useradd -M -s /usr/bin/passwd tunneluser

 

18. Convert command line option to JVM arguments

if [ $# -gt 0 ]; then

    params=( "$@" )

    for param in "${params[@]}"; do

        if [ "`expr \"$param\" : \"--.*=.*\"`" -ne "0" ]; then

            param=${param/--/-D}

            JAVA_OPTIONS="$JAVA_OPTIONS $param"

        fi

    done

fi

分享到:
评论

相关推荐

    Mastering Unix Shell Scripting(Wiley,2ed,2008)

    Each chapter begins with a typical, everyday UNIX challenge, then shows you how to take basic syntax and turn it into a shell scripting solution. Covering Bash, Bourne, and Korn shell scripting, this...

    B shell与 C shell的区别

    B shell与 C shell的区别 ; B shell的详解和C shell 的详解

    英文原版-Mastering Unix Shell Scripting 2nd Edition

    Each chapter begins with a typical, everyday UNIX challenge, then shows you how to take basic syntax and turn it into a shell scripting solution. Covering Bash, Bourne, and Korn shell scripting, this...

    shell shell练习 shell入门

    shell shell练习 shell入门 shell shell练习 shell入门

    Classic Shell Scripting

    Shell scripting skills never go out of style: they're the key to unlocking the real potential of Unix. Shell scripting is essential for Unix users and system administrators; shell scripts let you ...

    shell算法shell算法shell算法

    shell排序shell排序shell排序shell排序shell排序shell排序shell排序

    shell讲义shell讲义

    shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义...

    Shell源码(Shell源码)

    Shell源码Shell源码Shell源码Shell源码Shell源码Shell源码Shell源码Shell源码Shell源码Shell源码

    shell 编程shell 编程

    shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程...

    Learning Linux Shell Scripting 2nd Edition pdf

    Learning Linux Shell Scripting is ideal for those who are proficient at working with Linux and want to learn about shell scripting to improve their efficiency and practical skills. Table of Contents ...

    LinuxShell脚本学习基础视频

    资源名称:Linux Shell脚本学习基础视频资源目录:【】11a00d99b60c4e2eba3440b8aa3a6bdd【】linux_shell脚本编程_01认识shell,如何编写shell脚本和执行【】linux_shell脚本编程_02vivim简单的常用操作【】linux_...

    shell编程指南shell编程指南shell编程指南shell编程指南

    shell编程指南shell编程指南shell编程指南shell编程指南shell编程指南shell编程指南shell编程指南shell编程指南

    Shell Scripting

    A compendium of shell scripting recipes that can immediately be ... Come out of your shell and dive into this collection of tried and tested shell scripting recipes that you can start using right away!

    shell语言编程shell语言编程

    shell shellshellshell shell shell shell

    shell帮助文档shell帮助文档shell帮助文档

    shell帮助文档shell帮助文档shell帮助文档shell帮助文档shell帮助文档shell帮助文档shell帮助文档

    sshshell.zip

    sshshell ssh shell 服务器 远程连接 FTP for mac ssh shell 服务器 远程连接

    Shell.Programming.in.Unix.Linux.and.OS.X.4th.Ed

    After a quick review of Unix utilities, the book’s authors take you step-by-step through the process of building shell scripts, debugging them, and understanding how they work within the shell’s ...

    Mastering UNIX Shell Scripting_Sencond Edition_2008

    Each chapter begins with a typical, everyday UNIX challenge, and then shows you how to take basic syntax and turn it into a shell scripting solution. Throughout the book, you'll also find complete ...

    Shell脚本中获取进程ID的方法

    提问: 我想要知道运行中脚本子shell的进程id。我该如何在shell脚本中得到PID。 当我在执行shell脚本时,它会启动一个叫子shell的进程。作为主shell的子进程,子shell将shell脚本中的命令作为批处理运行(因此称为...

    Mastering UNIX Shell Scripting Sencond Edition

    Each chapter begins with a typical, everyday UNIX challenge, then shows you how to take basic syntax and turn it into a shell scripting solution. Covering Bash, Bourne, and Korn shell scripting, this...

Global site tag (gtag.js) - Google Analytics