productivity tips

Shortcuts, Linux configurations, etc

Windows XP shortcuts

# focus system tray
Win + b

Ubuntu

Alt + F2    # run a command in Dash
Ctrl + Alt + F1 ~ F6 # switch to virtual terminals

Workspace

Super + s   # spread workspaces

Ctrl + Alt + Left   # move to workspace left 
Ctrl + Alt + Right   # move to workspace right 
Ctrl + Alt + Down   # move to workspace down
Ctrl + Alt + Up   # move to workspace up

Ctrl + Shift + Alt + Left       move window to workspace left 
Ctrl + Shift + Alt + Right      move window to workspace right 
Ctrl + Shift + Alt + Down       move window to workspace down
Ctrl + Shift + Alt + Up         move window to workspace up

add a user as sudoer

add the user to the sudo group

$ usermod -a -G sudo liguisheng     # run this as root, add liguisheng to the sudo group

# login as liguisheng again, and it had been added to the sudo group
$ id
uid=1000(liguisheng) gid=1000(liguisheng) groups=1000(liguisheng),27(sudo)

# crete a file in /etc/sudoers.d/ with the same name of your username

$ echo "lee ALL=(ALL) ALL" > /etc/sudoers.d/lee
$ chmod 440 /etc/sudoers.d/lee

findout Linux distribution name

$ ls /etc/*release*
/etc/lsb-release  /etc/os-release

$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="12.04.2 LTS, Precise Pangolin"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu precise (12.04.2 LTS)"
VERSION_ID="12.04"

disable a service from autostart

$ sudo update-rc.d nginx disable

display IP address in shell prompt

add following line to ~/.bashrc

MYIP=`ifconfig eth0 | sed -nr 's/^ *inet addr:([0-9.]+) .*$/\1/p'`
export PS1="\u@$MYIP:\w\$ "

hide default folders in home directory in Ubuntu

Ubuntu will create some folders in a user's home directory, such as 'Desktop', 'Music', etc

you can change these folders location by editting ~/.config/user-dirs.dirs

send mail

use ssmtp to send mail

compose message in msg.txt:

To: jack@gmail.com
Subject: hi

hello world!

send mail:

ssmtp jack@gmail.com < msg.txt

work with ps or pdf files

make a ps(PostScript) file from text

$ enscript -p syslog.ps /var/log/syslog
[ 2 pages * 1 copy ] left in syslog.ps
38 lines were wrapped

convert ps to pdf

$ ps2pdf syslog.ps

pdf info

$ pdfinfo syslog.pdf 
Title:          Enscript Output
Creator:        GNU Enscript 1.6.5.90
Producer:       GPL Ghostscript 9.10
CreationDate:   Mon Aug 11 11:51:07 2014
ModDate:        Mon Aug 11 11:51:07 2014
Tagged:         no
Form:           none
Pages:          2
Encrypted:      no
Page size:      612 x 792 pts (letter)
Page rot:       0
File size:      5016 bytes
Optimized:      no
PDF version:    1.4

extract first page of a pdf file

$ pdftk A=syslog.pdf cat A1 output syslog-firstpage.pdf

rotate apges of a pdf file

$ pdftk A=syslog.pdf cat A1-endright output syslog-rotated.pdf

SSH login without password

login from a@A to b@B using ssh withoud password, ref: http://www.linuxproblem.org/art_9.html

    a@A:~> ssh-keygen -t rsa
    a@A:~> ssh b@B mkdir -p .ssh
    b@B's password: 

    a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
    b@B's password: 

    # you may need to change some permissions (e.g. this is a must on CentOS 6)
    b@B:~> chmod 700 .ssh
    b@B:~> chmod 640 .ssh/authorized_keys

    # then no password, hooray!
    a@A:~> ssh b@B

simple:

    $ ssh-copy-id b@B

version number specifications

when you work with npm or composer, you may encounter various version numbers, refer to:

    $ npm help 7 semvar

lorem ipsum

placeholder text generator, install a perl module libtext-lorem-perl and use the lorem command

sudo apt-get install libtext-lorem-perl
lorem

extract media from Office files (docx,xlsx,pptx)

ref

A docx file is actually a compressed zip file, so we just need to copy that file as a zip file, and then extract it, all media files are in word/media/

$ cp a.docx the-doc.zip 

$ unzip the-doc.zip 
Archive:  the-doc.zip
  inflating: [Content_Types].xml     
  inflating: _rels/.rels    
...

$ ls
a.docx  [Content_Types].xml  docProps  _rels  the-doc.zip  word

$ ls word/media/
image10.png  image17.png
...