| by Scott Kilroy

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]}’

Share Button
Read More
| by Scott Kilroy

Optimize and repair all mysql tables

mysqlcheck -o -u root -p –all-databases

Share Button
Read More
| by Scott Kilroy

Reset the mysql root password

Stop 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

Share Button
Read More
| by Scott Kilroy

See all open ports

lsof -i TCP| fgrep LISTEN

Share Button
Read More
| by Scott Kilroy

Remove top navbar from wordpress

Edit 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.

Share Button
Read More
| by Scott Kilroy

Find the largest file in a directory tree

find /path -type f -exec ls -s {} \; | sort -n | tail -1

Share Button
Read More
| by Scott Kilroy

Compress the contents current directory, but compress the smallest files first

ls -s | awk NR!=1 | sort -n | awk ‘{print $2}’ | xargs bzip2 -9v

Share Button
Read More
| by Scott Kilroy

Using netstat

netstat -ntulp displays everything that is listening tcp and udp and the ip that it is listening on

Share Button
Read More
| by Scott Kilroy

View network traffic (by port number)

To view web traffic (for example) use tcpdump -s 0 -w – port 80 | tcpdump -r – -A

Share Button
Read More
| by Scott Kilroy

VIM guide

A good basic starting point for using Vim is http://www.pixelbeat.org/vim.tips.html

Share Button
Read More
| by Scott Kilroy

Filter duplicate lines from a sorted files

cat list-1 list-2 list-3 | sort | uniq > final.list

Share Button
Read More
| by Scott Kilroy

Debugging bash scripts

Debugg bash scripts by runing with option -x example bash -x scriptname.sh

Share Button
Read More
| by Scott Kilroy

lowercase filen names

#! /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

Share Button
Read More
| by Scott Kilroy

Kill all process associated with a user

skill -TERM -u USERNAME

Share Button
Read More
| by Scott Kilroy

Force a user off the system

slay USERNAME

Share Button
Read More
| by Scott Kilroy

Linux Security

“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

Share Button
Read More
| by Scott Kilroy

ssh tips

Someday I’ll get around to writing up my own tips but until then this is a pretty good guide http://lugatgt.org/2009/10/28/ssh-tips-and-tricks-2/

Share Button
Read More
| by Scott Kilroy

bashprofile

# .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 […]

Share Button
Read More
| by Scott Kilroy

bashrc

Here 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\] \$ “;

Share Button
Read More
| by Scott Kilroy

apache – watch httpd for connected clients

watch 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

Share Button
Read More