Log in User page Discussion History Go to the site toolbox

User:Sam Odio/Linux commands

From BluWiki

Cool Linux Commands

Tutorials I need to learn

Recursively counting lines of code in project

You can change *.py to whatever the standard extension is for your files:

find /path/to/dir -type f -name '*.py' | xargs wc -l
Actually, it's petter to just use sloccount





Broken backspace in Screen

Add this to ~/.bashrc:

alias screen='TERM=screen screen'

Starting fcgi on a remote server

/usr/bin/spawn-fcgi -P /var/run/fcgi.pid -p 1029 -C 8 -u lighttpd -g lighttpd -f /usr/bin/php-cgi

Search within files


grep query /path/to/dir

Usage stats

cool disk & cpu monitoring:

iostat -x


cat /proc/meminfo
free -m
vmstat 10 1


top -b -n 1

display all http / smtp traffic (realtime):

tcpdump 'host and ((port http) or (port smtp))' -v

Find which applications are using a drive (useful for figuring out why you can't umount a volume):

lsof /dev/disk0s3

System info:

displays detailed hardware info about machine:


list drives on system (find disk name for volumes)

diskutil list


secure SSH copy:

scp user@host:./source_file ./destination_file

copy files from source dir to destination, ignoring files that haven't changed.

rsync -rt ./ root@odioworks.com:/var/www/starvingstartups-com/htdocs

Automate SSH login w/o passwords [1]:

cat ~/.ssh/id_rsa.pub | ssh user@remote_host 'cat >> .ssh/authorized_keys'

(if you don't have ./.ssh/id_rsa.pub, click the link to follow the full instructions.)

Enable blogger sftp access:

Change PasswordAuthentication to yes in /etc/ssh/sshd_config

Postfix Virtual hosting

Add these files to main.cf:

virtual_alias_domains = /etc/postfix/virtual/domains
virtual_alias_maps = hash:/etc/postfix/virtual/addresses
home_mailbox = Maildir/

then add addresses to /etc/postfix/virtual/addresses:

test@example.com   local_user, root, anotheruser
test@example.com   forwarding@address.com

Then create addresses.db:

postmap addresses

Also add domains for mail that the system will receive mail for: /etc/postfix/virtual/domains



Create a symbolic link of an entire directory of files using the (*) wildcard.

ln -sf <system path of files to link>/*  <system path of desired new links directory>

Symbolic linking just one file.

ln -sf <system path of file>/<filename>  <system path of desired new link directory>

Symbolic linking a directory.

ln -sf <system path to directory>  <system path of the desired new link directory>

Search Bash Command Line History: [2]

history | grep -i "<search string>"
!<history number>

Using Screen [3]: resume/create a screen:

screen -R 

create specific screen:

screen -m -d -S divvyshot

attach to an attached screen:

screen -x

Bash tips: [4]

Previous command


end of previous command:


common bash commands

man readline
ctrl+u: deletes backwards
ctrl+k: deletes forwards
ctrl+w: kill word
ctrl+a: beginning of line
ctrl+e: end of line

User management




Stop postgres: sudo -u postgres pg_ctl stop -D /sw/var/postgresql-8.0/data

Change user:

login as user that you want to change, then:\
psql -c "ALTER USER postgres WITH PASSWORD 'newpassword'" -d template1 

Create user:

sudo su postgres
createuser username --pwprompt

Or create user (via login):

createuser username --pwprompt -U postgres --password

To require passwords for all logins, comment out all privileges in pg_hba.conf and add these lines (after you've created the users):

local   all         all                                md5
host    all         so        md5

(note for security, I only allow so to login remotely)

Be sure to add this line to postgresql.conf in order to allow remote connections:

listen_addresses = '*' 

Resoures: [5] and [6]


Start mysql: /sw/share/mysql/mysql.server start


MediaWiki error on installation - max key length is 1024 bytes:

If you get the MySQL error upon installation: failed with error code "Specified key was too long; max key length is 1024 bytes".

Drop(delete) database & execute this line:

CREATE DATABASE `<database name here>` DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci;

Then attempt the installation again.

Handling a RAID HD failure


Once the failed drive is ready to be added back into the array, do so w/ the following command:

mdadm /dev/md1 -a /dev/sdc2

More information on how to replace a failed drive: http://www.howtoforge.com/replacing_hard_disks_in_a_raid1_array

Important config files

DNS client config:


Ethernet config:

/etc/conf.d/net (gentoo)
/etc/sysconfig/network-scripts/ifcong-eth0 (centos)
/etc/network/interfaces (debian)

View default gateway in debian:

netstat -nr


/sbin/route del default gw
/sbin/route add default gw

I installed lighttpd & php on debian using this tutorial: http://www.howtoforge.com/lighttpd_mysql_php_debian_etch

Mac OS X

Find memory leaks in application:

leaks <process name>

Change wireless HW address (doesn't work on en0):

sudo ifconfig en0 lladdr XX:XX:XX:XX:XX:XX

Reboot mac os x from command line:

osascript -e 'tell application "System Events" to restart'

Sync iPhoto from laptop to media center:

rsync -rt ~/Pictures/iPhoto_Library media@

Sync iPhoto from media center to laptop:

rsync -rt media@ ~/Pictures/

Rdiff backups? http://liquidweather.net/howto/index.php?id=56

Launchctl / launch.d:

launchctl list
man launchctl

Macports man page: http://projectmouse.org/1872/port


How to check your pythonpath:

>>> import sys
>>> sys.path

Creating a spider

http://www.ibm.com/developerworks/linux/library/l-spider/index.html http://lifehacker.com/software/top/geek-to-live--mastering-wget-161202.php

wget -H -r --level=2 -k -p -no-clobber --convert-links --no-parent  http://bluwiki.com (WORKED, would want to use "restrict hosts" and increase the level though)
wget -A "*" -r -H -l 5 -Doldvw.stores.yahoo.net,yimg.com --no-clobber --convert-links --no-parent --restrict-file-names=windows http://stores.yahoo.net/

Site Toolbox:

Personal tools
GNU Free Documentation License 1.2
This page was last modified on 12 July 2009, at 18:11.
Disclaimers - About BluWiki