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

Startup

debian:

sysv-rc-conf

gentoo:

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

http://www.macworld.com/article/41504/2004/12/jangeekfactor.html

grep query /path/to/dir

Usage stats

cool disk & cpu monitoring:

iostat -x
http://dammit.lt/2009/03/11/iostat/

memory:

cat /proc/meminfo
free -m
vmstat 10 1

CPU:

uptime
top -b -n 1

display all http / smtp traffic (realtime):

tcpdump 'host 10.0.1.22 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:

dmesg
lspci

list drives on system (find disk name for volumes)

diskutil list


SSH / SFTP

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

example.com
secondexample.com

BASH

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

$!:p

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

http://www.comptechdoc.org/os/linux/commands/linux_cruserman.html


Databases

Postgres:

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           0.0.0.0 0.0.0.0       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]

Mysql:

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

MediaWiki

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

http://gentoo-wiki.com/HOWTO_Gentoo_Install_on_Software_RAID#Misc_RAID_stuff

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:

/etc/resolv.conf

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

change:

/sbin/route del default gw 192.168.3.1
/sbin/route add default gw 192.168.3.100


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@192.168.0.112:~/Pictures/

Sync iPhoto from media center to laptop:

rsync -rt media@192.168.0.112:~/Pictures/iPhoto_Library ~/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

Python

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