Some one liners and stuff for bash. Config Files without comments or blank lines
alias catconf="grep -v '^$\|^\s*\#'"
DateStampdate +%Y_%m_%d tar czvf Ansible_`date +%Y_%m_%d`.tgz /home/ansible/ --exclude 'ansible.log' tar czvf `hostname`_`date +%Y_%m_%d`.tgz /home/ansible/ --exclude 'ansible.log' Uptime as a datestampdate -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%Y/%m/%d %H:%M" #Determine if it is an odd or even week weeknumber=$(echo "(`date +%d` / 7 + 1)" | bc ) if [ $weeknumber == 1 ]; then echo "don't run on first week of month. exiting" exit fi echo $week if [ $(echo $(( $weeknumber % 2 ))) == 0 ]; then week=even else week=odd fi Backspacestty -a Set backspce stty erase ^? History
Reverse search through history Brace Expansion
Create 2 files for each of the 3 months.
Linux Performance toolshttp://www.youtube.com/watch?v=t0XDEAECObA&feature=player_embedded
CPU
apt-get install bonnie++ prompt
PS1="\[\033[01;37m\]\$? \$(if [[ \$? == 0 ]]; then echo \"\[\033[01;32m\];)\"; else echo \"\[\033[01;31m\];(\"; fi) $(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]\h'; else echo '\[\033[01;36m\]\u@\h'; fi)\[\033[01;35m\] \w \$\[\033[00m\] " TarCreate a gziped tar filetar czvf blah.tgz /home/kevin/ tar czvf Ansible_`date +%Y_%m_%d`.tgz /home/kevin/ --exclude 'ansible.log' --exclude 'sendmailanalyzer-9.0.tar.gz' --exclude '/home/kevin/sendmailanalyzer-9.0' List the contents of a tarball tar -tvf blah.tgz find and replace in multiple files find . -name "run_*" -exec sed -i "s/chmod a/chmod -R a/g" '{}' \; Find a matching line in a file and append the contents of another file to that line for f in * do echo "Processing $f file..." #http://www.grymoire.com/Unix/Sed.html #get the contents of the file and remove spaces to make the following sed work properly filecontents=$(cat $f | sed 's/ //g') #sed -i for inplace #broken into multiple quoted or double quoted sections to handle variables properly #the first backslash is to denote the next character will be the delimiter or underscore in this case #find a line that starts with $f #then add the contents of the file to the end of that line sed -i '\_^'$f"_ s_\$_"$filecontents'_' $tmpserverlist filecontents="" cat $f done SortSort on the first column 15th character
sort -k 1.15 t=$({ time sleep 1 >/dev/null 2>&1;} 2>&1 ) echo $t split substringSplit string based on delimiter in shell But if you would write something useable under many shells, you have to not use bashisms. There is a syntax, used in many shells, for splitting a string accros first or last occurence of a substring: ${var#*SubStr} # will drop begin of string upto first occur of `SubStr` ${var##*SubStr} # will drop begin of string upto last occur of `SubStr` ${var%SubStr*} # will drop part of string from last occur of `SubStr` to the end ${var%%SubStr*} # will drop part of string from first occur of `SubStr` to the end reverse difffind matching lines fgrep -xf file1 file2 netcat ncnc -vz machine port |