====== Quick Command Set Daily Life ====== ==== grab configure script from php installatio ==== php -i | grep configure | tr -d \' ==== find the disk usage for all the listed files/foldere ==== du -sckh * | sort -n ==== find uniq ip from file ==== cat /etc/sitemap | awk '{print $2}' | xargs -n 1 ping -c 1 -t 1 | grep PING | awk '{print $3}' | sort | uniq ==== do something based on file list ==== while read k2;do $k2;done < file ==== add text to end of each line ==== sed -i "s/$//" file ==== add text to start of each line ==== sed -i "s/^//" file ==== set terminal to color ==== TERM=xterm-color; export TERM ==== Break huge line based on character number ==== (specifically used for SSL) sed 's/\(.\{64\}\)/\1\n/g' file ==== Search file and replace string ==== find ./ -name ".htaccess"|xargs perl -pi -e 's/original/newstring/g' --OR-- find . -type f -print0|xargs -0 perl -pi -e 's/mysql_connect \(\"pqr.k2patel.com/mysql_connect \(\"xyz.k2patel.com/g' --OR-- for file in *; do [[ $file = remove ]] && continue; fgrep -vf remove "$file" > k2.tmp ; mv k2.tmp "$file"; done ==== Load LVM Disk ==== vgscan --mknodes //load the nodes in /etc vgchange -ay //activate the nodes lvscan //scan and check the status mkdir /mnt/somename //directory to mount mount /dev/VolGroup00/LogVol00 /mnt/somename //mount on directory ==== general variable goes to .htaccess ==== php_admin_flag safe_mode Off //put this in the httpd.conf if nothing works php_flag safe_mode Off php_value safe_mode "0" php_flag register_globals off php_flag display_errors off DirectoryIndex index.php index.shtml ErrorDocument 404 / ErrorDocument 403 / ErrorDocument 500 / ErrorDocument 302 / ErrorDocument 403 http://www.k2patel.com Redirect 301 / http://k2patel.com/show.php?m=1895&st=1&sid=65 php_flag log_errors on php_flag safe_mode Off php_flag register_globals on php_value session.save_path /srv/www/apache/tmp ==== SSL redirect for https ==== RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} ==== Redirect all except one ==== RewriteEngine on RewriteCond $1 !^the/pathto/the/directory RewriteRule (.*) http://www.newsite.com/$1 [R=301,L] OR RewriteEngine on RewriteRule !^the/pathto/the/directory - [C] RewriteRule (.*) http://www.newsite.com/$1 [R=301,L] ==== lock file for no edit ==== chflags noschg -- unlock chflags schg -- lock ==== remove ^M from file ==== VI : %s/^M//g (To get the ^M hold the control key, press V then M (Both while holding the control key) and the ^M will appear.) -OR- sed 's/'"$(printf '\015')"'$// -OR- tr -d '\r' new.file ==== change file permission if it is not own by specific user ==== find . ! -user tiffany | xargs chown tiffany:tiffany ==== remove folder name `5 "` with find ==== find . -type d -name '5 "' -exec rm -Rv "{}" \; ==== add / remove IP alias ==== ifconfig fxp0 inet netmask alias -- add ifconfig fxp0 inet netmask -alias -- remove ==== manipulate one file based on source and pattern ==== while read -r k2 ; do sed -e 's!\$k2!'"$k2"'!g' < site.cnf ; done < sitelist.cnf > site.all.cnf ==== Line by Line two file merge ==== # -d used as delimiter in example it is space " ". paste -d " " file1 file2 >"outputfile1" ==== find and command combination ==== for i in `find . -type f` ; do mv $i /home/yahoo/Photos/ ;done ==== how to download recursively folder / file using FTP ==== wget -r --no-clobber --continue --user=USERNAME --password=PASSWORD ftp://hostname --OR-- ncftget -R ftp://ftp.mydomain.com source dest ==== one line loop in linux ==== for i in `jot 251 4`; do echo xx.yy.pp.$i; done --OR-- for ((i=4; i<=254; i++)); do echo "xx.yy.pp.$i"; done --OR-- for i in {4..254}; do echo "xx.yy.pp.$i"; done ==== Move file if it contain following text ==== find . -type f -exec grep -q '*POSSIBLE SPAM*' {} \; -exec echo mv {} /home \; --OR-- grep -rl 'POSSIBLE SPAM' |while read f; do mv "${f##*/}" "${DEST}"; done --OR-- find . -type f -exec grep -Fq '*POSSIBLE SPAM*' -exec mv {} /home/ + #maybe, or \; ==== How to set date on linux/unix System ==== date yymmddhhss ==== netstat with name of process only work on linux ==== netstat -tlpn ==== Get IP of the domains in the list ==== sed -e 's#.*#nslookup & |awk '"'"'/^Name/{n=$2}/^Address/{a=$2}($2=="canonical"){c=sprintf("%s%s",c,$1)}END{print "& "n" "c" "a}'"'"'#' hostlist.txt|sh ==== How to connect to serial connection ==== cu -l /dev/cuaa0 ttyd0 "/usr/libexec/getty std.9600" vt100 on secure ttyd0 "/usr/libexec/getty std.9600" dialup off secure ==== How to find Scripts on pages ==== find /srv/www/html -name '*.php' -o -name '*.htm*' -print0| xargs -0 grep -i '