Useful use of pgrep
To list the PIDs of all running process_name, instead of ps ax|grep process_name|grep -v grep|awk '{print $1}' do pgrep process_name To kill all running process_name, instead of for p in `ps ax|grep...
View ArticleCompare binary files with bash
While I was working on a reverse-engineering project trying to find out the structure of a data file, I wrote this simple BASH script to do the job: #!/bin/bash # script to compare two binary files...
View ArticleA few useful BASH shortcuts
Here are some of the shortcuts that I use quite often: $_ ( $_ is the last argument of the last command ) Example 1: ls /a/very/deep/and/not/easy/to/find/folder/ (once confirm that’s the folder I want,...
View ArticleDiff text file remotely with local file
Found a pretty neat solution at http://www.genlinux.org/2009/04/remote-diff-in-linux.html for comparing remote and local files. For example, if I want to compare the file remote_ip:~/myscript.sh with...
View ArticleChange Centos ssh shell color
When trying to ssh to Cento servers (Versions 5.X, haven’t tried other versions yet), the default directory color blue doesn’t work well with terminals such as Mac OSX Terminal using dark-background...
View ArticleA few wget tips
In *nix world, wget is a very handy tool to download files from remote ftp or http servers. This post will present a few wget tips that I use quite often in my (mostly Bash) scripts: 1) use –quiet...
View Articlecrontab editor
To use your favoriate editor to modify user’s crontab, here’s how: 1) Quick and dirty solutions EDITOR=vim crontab -e or export EIDTOR=vim crontab -e 2) Permanent solution: add the following line to...
View ArticleReplace if … then … fi with && and || in Bash
&& and || are the shorthand of if … then … fi in Bash. They are very useful in writing simple scripts, for example: 1. Run script based on day of week: [ $(date +%w) -eq 6 ] && echo "do...
View ArticleCombine regular expression and conditional statements in BASH
As we all know we can use conditional statements in BASH. For example, show usage if number of arguments is 0: #!/usr/bin/env bash if [ $# -eq 0 ]; then echo "Usage: $0 start|stop|restart" exit 0 fi...
View ArticlePrint color in shell terminal
Sometimes you might want to print something with color in a text terminal (by color I mean something other than the default text color). Put the following shell function to your ~/.bash_profile and you...
View Article
More Pages to Explore .....