################################################### ## ## Code Snippets CLI - Command line code samples ## ################################################### perl -e "print \"@INC\"" # display date as YYYmmdd and remove trailing new line - good for filenaming date +%Y%m%d | tr -d '\n|\r' or datestring=$(date +"%Y%m%d") echo "27 june 2011" | awk '{print "date -d\""$1FS$2FS$3"\" +%Y%m%d"}' | bash echo "Nov 9, 2020" | awk '{print "date -d\""$1FS$2FS$3"\" +%Y%m%d"}' | bash # command line script to diff files # prints the file name in /dir # diffs it with the same file in pwd # the -f9 in the cut command means take the 9th delimited field for i in /dir/* ; do echo $i j=`echo $i|cut -d'/' -f9`; diff -b $i $j; done # editing batch filename on command line for i in `ls`; do echo $i; j=`echo $i | (sed s/pre/post/)`; cp $i $j; done # syntax example of bash "for loop" on command line for i in $(cat centos_packages.txt) ; do echo $i ; done