productivity tips

Shortcuts, Linux configurations, etc

Windows XP shortcuts

# focus system tray
Win + b


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


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 
VERSION="12.04.2 LTS, Precise Pangolin"
PRETTY_NAME="Ubuntu precise (12.04.2 LTS)"

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:

Subject: hi

hello world!

send mail:

ssmtp < msg.txt

work with ps or pdf files

make a ps(PostScript) file from text

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

convert ps to pdf

$ ps2pdf

pdf info

$ pdfinfo syslog.pdf 
Title:          Enscript Output
Creator:        GNU Enscript
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:

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

    a@A:~> cat .ssh/ | 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


    $ 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

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


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 

$ unzip 
  inflating: [Content_Types].xml     
  inflating: _rels/.rels    

$ ls
a.docx  [Content_Types].xml  docProps  _rels  word

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