Print the total bytes of files in a directory grouped by date
ls -l|awk ‘length($6)==3{x[$6″ “$7]+=$5};END{for(i in x)printf”%s:\t%d\n”,i,x[i]}’
Read Morels -l|awk ‘length($6)==3{x[$6″ “$7]+=$5};END{for(i in x)printf”%s:\t%d\n”,i,x[i]}’
Read MoreStop the mysql daemon Restart mysql using the command mysqld_safe –skip-grant-tables Now you should be able to connect as root Once connected run the following: update user set Password=PASSWORD(‘new-password’) where user=’root’; then flush privileges exit mysql restart mysql and you should be able to login with the new password
Read MoreEdit wp-includes/functions.php and add the following add_action(‘after_setup_theme’, ‘remove_admin_bar’); function remove_admin_bar() { if (!current_user_can(‘administrator’) && !is_admin()) { show_admin_bar(false); } } Now the top navbar will only showup for admin users.
Read Morefind /path -type f -exec ls -s {} \; | sort -n | tail -1
Read Morels -s | awk NR!=1 | sort -n | awk ‘{print $2}’ | xargs bzip2 -9v
Read Morenetstat -ntulp displays everything that is listening tcp and udp and the ip that it is listening on
Read MoreTo view web traffic (for example) use tcpdump -s 0 -w – port 80 | tcpdump -r – -A
Read Morecat list-1 list-2 list-3 | sort | uniq > final.list
Read MoreDebugg bash scripts by runing with option -x example bash -x scriptname.sh
Read More#! /bin/bash DIR=$1 for a in `ls $DIR` do fname=`echo $a | tr A-Z a-z` mv $DIR/$a $DIR/$fname done; exit 0
Read More“Yes, I’m paranoid — but am I paranoid enough?” ― David Foster Wallace, Infinite Jest Hardening Public Servers Install system accounting On Debian based systems run ‘apt-get install acct’ then you can use commands lastcomm and sa to see who ran various comands. Also a log file will be writen to /var/log/account/pacct Remove compilers from production severs use the command ‘apt-get –purge remove gcc’ Setup remote logging See http://www.thegeekstuff.com/2012/01/rsyslog-remote-logging/ to find out how Install fail2ban Linux.com has a good intro to fail2ban http://www.linux.com/learn/tutorials/469597-weekend-project-keep-out-repeat-offenders-with-fail2ban-on-linux
Read More# .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin:/sbin export JAVA_HOME=/usr/java/jdk1.6.0_05/bin/java export PATH=$PATH:/usr/java/jdk1.6.0_05/bin export HISTIGNORE=”&” export EDITOR=nano export PATH unset USERNAME alias rm=’rm -i’ alias cp=’cp -i’ alias ls=’ls –color’ alias zf=’zf.sh’ echo -e “\033[36m########################## \033[0m” echo -e “\033[36mServer $HOSTNAME \033[0m” echo -e “\033[36mWelcome back $USER \033[0m” echo -e “\033[36musers loggged in: \033[0m” echo -e “\033[36m `users ` \033[0m” echo -e “\033[36m`uptime` \033[0m” echo […]
Read MoreHere is my typical .bashrc file # .bashrc # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi # append commenads to bash_history (when using more then one window) shopt -s histappend PROMPT_COMMAND=’history -a’ # User specific aliases and functions PATH=$PATH:$HOME/bin:/sbin #export JAVA_HOME=/usr/java/jdk1.6.0_05/bin/java export HISTIGNORE=”&” export EDITOR=nano export PATH unset USERNAME #function PWD { #pwd | awk -F\/ ‘{print $(NF-1),$(NF)}’ | sed ‘s/ /\\//’ #} #export PS1=”\[\033[0;32m\]\u@\h \[\033[33m\]\$(pwd 3)\[\033[0m\] \$ “;
Read Morewatch httpd for connected clients watch “netstat -anpt | grep httpd | grep ESTABLISHED|cut -b45-60 | cut -d’:’ -f1 | sort” OR netstat -plan|grep :80|awk {‘print $5’}|cut -d: -f 1| sort|uniq -c | sort -nk 1
Read More