Published using Google Docs
Geek HowTos
Updated automatically every 5 minutes

Geek HowTos

Useful Linux command I have a tendency to forget...

lsof:  lists all open files  belonging  to all active processes.

sudo fdisk -l : shows all the available partition (mounted or not). Nice when one is looking for some USB drive :)

lsmod/insmod: to find out which modules are loaded, e.g. which driver for your graphic card.

gnome-volume-properties

gnome-volume-control

htop and other CPU tools (here)

Pack and compress all at once:    tar -cf - file_to_pack1 file_to_pack2 ... | gzip -c > packed_files.tar.gz

XML document is well formed? (A configuration file maybe..) use 'xmlwf'

Save man pages as plain text? use 'col'

Mount SMB shares from command line: apt-get install smbfs, mount -t smbfs -o username=xxx,password=xxx,uid=xxx,gid=xxx //server/share <mountpoint>

Remote Desktop to windows machine from linux, here.

CHM reader: xchm, gnochm

Copy Shell Prompt Output To Clipboard Directly with xclip.

Resize pixconvert -resize 1024x768 pix_orig pix_result or convert -resize 50% input.jpg output.png

List HW (RAM in this case): lshw -C memory

Use SSHFS: Mounting: sshfs user@machine:/<path> <local_mount_point>. Unmounting: fusermount -u <local_mount_point>

Run the equivalent of chkdsk for a FAT 32 disk from Linux: sudo /sbin/dosfsck -tawv /dev/sdc1

How to format a disk from the command line: http://www.cyberciti.biz/faq/linux-disk-format/

Env Variables

1) /etc/profile is for system-wide environment variables -> thus available to all users

2) ~/.profile is for user environment variables -> for current user only, but available to all processes whether launched from x-term, menu, whatever.

3) ~/.bashrc is for (bash) terminal environment variables -> current user, applies only to processes launched from terminal

4) ~/.gnomerc will get sourced every time you log into gnome as well

More info here.

SSH timeout: Add ServerAliveInterval 540 to /etc/ssh/ssh_config on the client. More here.

Denyhosts to be installed to protect your server against brute-force attack on SSH port

Bash Tips and Tricks

History:

export HISTCONTROL=erasedups  #removes all matching commands, can also use ignoreboth

export HISTSIZE=2000

export HISTFILESIZE=50000

export HISTIGNORE="&:ls:[bf]g:exit"

shopt -s histappend  #multiple shells all write in same history file

Terminal colors:

I wanted to customize the colors in my terminals but could not find the config file for this under Ubuntu. So here is the trick:

- run ' dircolors --print-database > ~/.dir_colors'

- edit ~/.dir_colors and change the settings to your liking

- make sure that the eval line in your .bashrc is like this:  eval "`dircolors -b ~/.dir_colors`"

Bash scripting Tutorial

http://www.linuxconfig.org/Bash_scripting_Tutorial

 

Screen

http://gentoo-wiki.com/TIP_Using_screen

Quick walk-through

Command

Effect

 

screen

Login and start a Screen session right away

 

C-a "

Show list of terminals managed by Screen; Here: only one

 

Esc

Close the list window

 

C-a c

Create a new terminal window

 

C-a "

The list of terminals now shows two entries

 

Esc

Close the list window

 

ls

show the directory contents in this window

 

C-a p

return to the previous, first window

 

ping forums.gentoo.org

Do something in this window, too

 

C-a c

Create another window

 

C-a S

Split the term vertically into two regions

 

C-a X

Kill the current region

 

C-a <Tab>

Focus the newly created region

 

C-a -

Resize this region and make it 3 lines smaller

 

C-a 1

Show the first window in this region

 

C-a <Tab>

Move the focus back to the upper region

 

C-a d

Detach the Screen session

 

 

open a xterm

 

screen -DR

login again and make Screen re-attach (R) to the first session found, after detaching (D) the session first, if necessary (which it wasn't)

[edit]

Seeing is believing

This animated .gif shows most basic commands in a sequence of 50 pictures. This is a transcript of all typed keystrokes:

xterm<Enter>

screen<Enter>

C-a "

<Esc>

C-a c

C-a "

<Esc>

ping forums.gentoo.org<Enter>

C-a n

ls -la<Enter>

C-a S

C-a <Tab>

C-a 1

C-a <Tab>

C-a +

C-a :resize 18<Enter>

C-a x

password

C-a d

screen -ls<Enter>

screen -R<Enter>

printf 'GET / HTTP/1.0\n\n' | telnet forums.gentoo.org 80<Enter>

C-a <Esc>

<PageUp>

<ArrowKeys>

<Space>

<ArrowKeys>

<Space>

C-a c

lynx C-a ]

[edit]

Exiting Screen

One way to close a Screen session is to exit all terminal sessions you are running inside, one after the other. After the last exit inside Screen you will get [screen is terminating] as a confirmation that your Screen session has ended.

However, a simpler and faster way to do the same thing is to use Screen's quit command.

C-a :quit

 

Sopcast how to

Once the necessary SW is installed on your machine you do this:

Terminal 1: sp-sc <URL> 3908 8908 > /dev/null (e.g sp-sc sop://broker.sopcast.com:3912/6002 3908 8908 > /dev/null)

Terminal 2: gmplayer  http://localhost:8908/tv.asf

To install the SW:

Here, here, here and here.

You can also use the Sopcast-player for a more user friendly experience. Download it here.

Truecrypt

How to install for Dapper (for more recent versions, the package is in the repo):

http://www.ubuntuforums.org/showthread.php?t=199367

How to find your extern USB disk:

fdisk -l

How to mount the TC volume:

sudo truecrypt -u /dev/sda1 /mnt/tc_hd

truecrypt --mount-options "rw,sync,utf8,uid=1000,umask=0007" /dev/sdb1 /mnt/USB_HD/  (the mount options are there in the case where your disk is FAT32 formatted)

How  to umount a TC volume:

truecrypt -d

How to create a crypted volume with ext3 from scratch (more info here, post #109):

truecrypt -c /dev/sdb

truecrypt /dev/sdb

mkfs.ext3 /dev/mapper/truecrypt0

truecrypt /dev/sdb /mnt/mountpoint

Ffmpeg and converting video for mobile devices

Hardy:

You need to install ffmpeg and libavcodec1d from Medibuntu.

Then to convert to divx, use "ffmpeg -i <orig_movie> -s qcif -r 15 -acodec mp3 -vtag xvid <target>.avi"

To convert to mp4, use "ffmpeg -i <orig_movie> -s qcif -r 15 -vcodec h264 <target>.mp4"

Intrepid:

You need to install a bunch of extra libs, like explained here.

Then to convert to divx, use "ffmpeg -i <orig_movie> -s qcif -r 15 -vtag xvid -acodec libmp3lame <target>.avi"

To convert to mp4, use "ffmpeg -i <orig_movie> -s qcif -r 15 -vtag h264 <target>.mp4"

Jaunty:

Install ffmpeg and libavcodec-unstripped-52. Then the command is the same as above for Intrepid

Edgy Eft links

EdgyReleaseNotes

Ubuntu Install Wiki

 

Capture Stream via Mplayer:

In this case, MPlayer comes to my rescue. This multimedia playback engine is available under pretty much any flavor of Linux; I installed it on my Ubuntu box with a simple sudo apt-get install mplayer. To create a Prairie podcast, first I use my Web browser to navigate the archives, arriving at the page for a particular show. Next I right-click the 'Try this one' link and select Copy Link Location. Then I open a command-line terminal and enter the following magic incantation, replacing URL with the link I have copied to the clipboard, and FILENAME with a file name ending in .wav ("PHC.wav" works just fine):

mplayer -playlist URL -ao pcm:file=FILENAME -vc null -vo null

When you enter this command, you'll see a lot of strange communication between your PC and the server scroll by, and then MPlayer will start capturing the stream. (You won't hear anything.) The stream comes down in real time, of course, so it will take 2 hours to capture the 2-hour show. Once that's done, you'll have an enormous .wav file on your hands; it's a good idea to convert that file to a much smaller MP3 file before taking it on the road. To do so, first check your package manager to ensure that Lame is installed, and then use this command:

lame filename.wav filename.mp3

To capture video stream:

mplayer -dumpstream mms://somehost.com/somedirectory/somefile.wmv

IRC in text mode

- run "irssi -c irc"

- /j #channel pwd

- /wc to close window

- /msg nick blablabla

Run Existing Windows installation With Vmware Player

 

More here.

SSHFS:

sshfs user@host:<path> <mountpoint>

fusermount -u <mountpoint>

SSH tunelling:

ssh-add

ssh -f -L 1863:messenger.hotmail.com:1863 -N user@server.com

ssh -f -L 5050:scs.msg.yahoo.com:5050 -N user@server.com

ssh -f -L 5190:login.oscar.aol.com:5190 -N user@server.com

ssh -f -L 5222:talk.google.com:5222 -N user@server.com

ssh -f -L 5223:jabber.org:5223 -N user@server.com

ssh -f -L 6667:irc.server.no:6667 -N user@server.com

ssh -f -L <local port>:<target server>:<target port> -N user@middleman_server

Don't forget to use localhost in your Gaim client instead of the normal servers!!

messenger.hotmail.com

scs.msg.yahoo.com

login.oscar.aol.com

irc.linpro.no

Another way is to use SOCKS!

ssh -f -D 7070 -N user@server.com

There configure your app to use a SOCKS proxy with localhost and port 7070! (or any other port you defined in the previous line)

Free ssh shells list, here. (num@sdf-eu.org and lp@freeshells.ch)

Misc links:

http://blog.unto.net/work/google-talk-over-ssh/

http://www.howtogeek.com/howto/windows/how-to-secure-gaim-instant-messenger-traffic-at-work-with-securedcrt-and-ssh/

http://www.neophob.com/serendipity/index.php?/archives/48-SSH-tunneling-Part-2,-use-SOCKS-to-be-free....html

http://www.suso.org/docs/shell/ssh.sdf

 

Tux Commander Shortcuts

 

Backup/Restore for the complete machine:

Backup:

$ cat /usr/local/lib/backup-disk-include

/etc/

/opt/

/var/

/home/

/usr/local/

/boot/

/root/

$ cat /usr/local/bin/backup-disk

#!/bin/bash

INCLUDE=/usr/local/lib/backup-disk-include

EXCLUDE=/usr/local/lib/backup-disk-exclude

TARGET=/media/disk/expresso2/backup/

dpkg --get-selections > $TARGET/dpkg-get-selections.log

rsync --progress --delete -arvz --exclude-from=$EXCLUDE --files-from=$INCLUDE / $TARGET

Restore:

cp /etc from backup

dpkg --set-selections

aptitude update upgrade

copy /home /var and so on from backup

done!

Install Awstats to work with Lighttpd

All you need to know is here and here.

Upstart

Link to a good into here.

The conf files are in /etc/init, with some symlinks in /etc/init.d

start mysql = initctl start mysql = service mysql start

initctl [start|stop|status]

Disable services on boot (SystemV and Upstart)

2 good links, here and here.

Basically, it boils down to this (choose your favorite):

* Rename the job configuration file such that it does not end with ".conf".

* Edit the job configuration file and comment out the "start on" stanza using a leading '#'.

* # echo "manual" >> /etc/init/myjob.override

Postgresql

PostgreSQL - Community Ubuntu Documentation

https://help.ubuntu.com/community/PostgreSQL

PostgreSQL add or create a user account and grant permission for database

http://www.cyberciti.biz/faq/howto-add-postgresql-user-account/

PostgreSQL: Documentation: Manuals: PostgreSQL 8.4: PostgreSQL Client Applications

http://www.postgresql.org/docs/8.4/static/reference-client.html

Initial Postgres Configuration - Glom

http://www.glom.org/wiki/index.php?title=Initial_Postgres_Configuration

PostgreSQL: Documentation: Manuals

http://www.postgresql.org/docs/current/static/index.html

Quick start:

sudo su postgres # become user postgres

psql <databasename> # connect to the database or use a specific client app to do a specific task

Configure sshd (remember to chmod 600 /etc/ssh/sshd_config)

Protocol 2

PermitRootLogin no

AuthorizedKeysFile         %h/.ssh/authorized_keys  <- change name of the file so it is not default

X11Forwarding no

UseDNS no

AllowUsers pim pam poum

XML formatting/indenting:

$ xmllint --format original.xml > formatted.xml

DNS tunneling:

Use the following tunlr.net DNS servers:

149.154.158.186, 199.167.30.144

Compiling tuxcmd from scratch:

Fetch the source from here or from here.

Install fp-compiler and lazarus (so you have all the libs you need!)

Complete Re-install of GRUB 2 from Live USB

https://www.youtube.com/watch?v=8lod8sRb_6I

Network manager CLI and VPN

nmcli con list

sudo nmcli con down id 'XXX'

sudo nmcli con up id 'XXX'

sudo less /etc/NetworkManager/system-connections/XXX

cd /etc/NetworkManager/system-connections/

http://askubuntu.com/questions/57339/connect-disconnect-from-vpn-from-the-command-line

Download videos from NRK site

sudo apt-get install php5 php5-curl php5-cli curl

Download https://raw.github.com/K-S-V/Scripts/master/AdobeHDS.php and put it in ~/bin and “chmod +x”

Download http://users.linpro.no/ingvar/nrk/nrk-download and put it in ~/bin and “chmod +x”

Now you can just use this command to download the video at the corresponding page:

nrk-download 'http://tv.nrk.no/serie/norske-naturperler/kmte50002211/sesong-1/episode-2'

All this good info comes from here:

Downloading HD content from tv.nrk.no « On the third side

http://ingvar.blog.redpill-linpro.com/2012/05/31/downloading-hd-content-from-tv-nrk-no/