Brief Introduction on Linux Related Technology

KONG, Lei

Contents

1. Useful clients under Windows & Linux

2. line utilitie

3. Bash scripts Section I

Useful Tools under Windows & Linux

Clients under Windows for Remote Login

• Use PuTTY/SecureCRT as ssh client to login to the remote . – PuTTY: http://www.chiark.greenend.org.uk/~sgtat ham/putty/ – SecureCRT: http://www.vandyke.com/products/secure crt/index.html

Clients under Windows for Transfer

• Use WinSCP to do between local and remote computer – WinSCP http://winscp.net/ – SFTP (SSH ) , mostly used with SSH-2 – SCP (Secure Protocol) , mostly used with SSH-1

Clients under Windows for X

• Use Xmanager as Xwindow Server for X11 display. – Xmanager: http://www.netsarang.com/

Other Useful Tools

• GNU Screen – http://www.gnu.org/software/screen/

• lftp – sophisticated command line ftp/http client – http://lftp.yar.ru/

• GNU wget – http://www.gnu.org/software/wget/ Section II

BASIC Useful Linux/ Tools (Particular Thanks: ZHAO, Shuqi)

GNU Text Utilities

• dos, unix, mac text file – dos2unix unix2dos mac2dos

, estimate the time for the jobs – time someprog progparam

• economize on disk – run_certain_program -o /dev/stdout | gzip - > result.gz GNU Text Utilities

• Is the program with correct ? – -A filename

• edit the original file – -i -e ‘/badline/d’ *.fa – perl -i.bak -npe ‘s/old/new/g’ *.fa

• Input special characters in bash(eg. tab) – ctrl+v special_character

• -b --ignore-leading-blanks • -d --dictionary-order • -f --ignore-case • -i --ignore-nonprinting • -n --numeric-sort • -r --reverse • -k POS1[,POS2] --key=POS1[,POS2] • -s --stable • -t SEPARATOR --field-separator=SEPARATOR • -u --unique sort example

• A sort key position may also have any of the option letters `Mbdfinr‘ appended to it, in which case the global ordering options are not used for that particular field.

• sort – sort -k5,6nr -k7,7

for tar – x to eXtract from an archive. – c to Create an archive. – t to lisT the contents of an archive. – z to work with a gzipped (ending with .gz) archive. (GNU Tar only) – j to work with a bzip2 (ending with .bz2) archive. (GNU Tar only) • general for -z and -j bash $ tar cf - /to// | gzip -c > xxx.tar.gz bash $ tar cf - path/to/dir/ | bzip2 -c > xxx.tar.bz2

• Syntax: – find pathname-lists option expression; • Examples: – To out the current pathname for file ‘myfile’: bash $ find . -name myfile -print

– To print out the yes* files accessed in the last two days: bash $ find . -name ‘yes*’ -atime +2 -print find

• 如何将查询的结果作为命令行参数

[kongl@soft tmp]$ find-example/ [kongl@soft find-example]$ >a >b >c >d >e >f [kongl@soft find-example]$ a b c d e f [kongl@soft find-example]$ find . - f -exec {} {}.1 \; [kongl@soft find-example]$ ls a.1 b.1 c.1 d.1 e.1 f.1 Difference between .bash_profile and .bashrc

• Login with shell (ssh user@host)

/etc/profile -> ~/.bash_profile -> ~/.bash_login -> ~/.profile #append to .bash_profile -f ~/.bashrc && . ~/.bashrc

• Login without shell (ssh user@host cmd)

/etc/bash.bashrc -> ~/.bashrc Special Shell Variables

• $# The number of arguments. • $@ All arguments, as separate words. • $* All arguments, as one word. • $$ ID of the current process. • $? status of the last command. • $0,$1,..$9,${10},${11}...${N} Positional parameters.

cbimgmt $ cat wrapper.sh exec program.real “$@” cbimgmt $ cat wrapper.sh WHAT‟S THE DIFFERENCE exec program.real $@ Bash test and comparison functions

• test, [ ], [[ ]], (( )), or if-then-else-fi

cbimgmt $ test #= [ expr ] , return $? cbimgmt $ test 3 -gt 4 && true || echo false cbimgmt $ [[ ( -d "$HOME" ) && ( -w "$HOME" ) ]] && \ echo "home is a writable "

• arithmetic comparisons -eq, -ne, -lt, -le, -gt, or -ge, • String comparisons =, !=, <, or > SSH Related Tips • always type the user and host name?

[kongl@soft tmp]$ cat ~/.ssh/config Host soft Hostname 162.105.250.142 User kongl SSH Public Key Authentication

[kongl@soft ~]$ ls ~/.ssh/ config known_hosts [kongl@soft ~]$ ssh-keygen -t dsa Generating public/private dsa key pair. Enter file in which to save the key (/home/kongl/.ssh/id_dsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/kongl/.ssh/id_dsa. Your public key has been saved in /home/kongl/.ssh/id_dsa.pub. The key fingerprint is: e4:b4:8d:98:f5:6f:39:5e:f7:96:f8:0c:c0:d6:cf:73 kongl@soft [kongl@soft ~]$ scp ~/.ssh/id_dsa.pub soft:.ssh/authorized_keys [email protected]'s password: id_dsa.pub 100% 600 0.6KB/s 00:00 [kongl@soft ~]$ ssh soft Last login: Sat Nov 28 15:34:57 2009 from 222.29.79.61 SSH Copy without SCP I

[kongl@soft tmp]$ if=/home/kongl/tmp/c | ssh soft 'dd of=/home/kongl/tmp/e' 0+1 records in 0+1 records out 123 bytes (123 B) copied, 2.1e-05 seconds, 5.9 MB/s [email protected]'s password: 0+1 records in 0+1 records out 123 bytes (123 B) copied, 0.002105 seconds, 58.4 kB/s [kongl@soft tmp]$ ls a c d e find-example sort_example.txt test.sh [kongl@soft tmp]$ cat e Greg Sanders: All work and no play makes Greg a dull boy. Gil Grissom: All play and no work makes Greg an UNEMPLOYED boy. SSH Copy Without SCP II

[kongl@soft tmp]$ cat c | ssh soft 'cat > /home/kongl/tmp/f' [email protected]'s password: [kongl@soft tmp]$ ls a c d e f find-example sort_example.txt test.sh [kongl@soft tmp]$ cat f Greg Sanders: All work and no play makes Greg a dull boy. Gil Grissom: All play and no work makes Greg an UNEMPLOYED boy. lftp

• lftp [ftp://|http://|fish://]user@host • lftp -c command • lftp -e cmd • lftp -f script_file

• lftp commands ! shell command level|off cd, lcd get, put, mget, mput, pget mirror Vim command mode operations • :g/pattern/d (Delete lines with the specified pattern) • :%!sed /pattern/d (same as above) • :1,10s/old/new/g ( ‘old’ with ‘new’ in line 1 - 10 globally.) • :r!date (Read current date.) • :set nu, :set nonu (Display line number or not.) • :set ai, :set noai (auto indent) • :set hlsearch, :set nohlsearch (high light search results) • n+yy (copy n lines),p (),dd (delete/ the current line), u (undo) • w ( cursor forward a word),b (move cursor backward a word) • shift+d (delete from cursor to line end) • ctrl+d (half page down),ctrl+u (half page up) • :w (save),:q! (force quit without saving),:wq (save & quit) Vim insert mode

• i (insert mode) • esc (quit insert mode) • ctrl+v special_character (input a special character in insert mode) Task Manager Tips

• crontab crontab –e

# use /bin/sh to run commands, # no matter what /etc/passwd says SHELL=/bin/sh

# run five minutes after midnight, every day 5 0 * * * $HOME/bin/daily.job &>> $HOME/tmp/out # run 2:15pm on the first of every month 15 14 1 * * $HOME/bin/monthly

crontab filename

Four device file

• /dev/stdin • /dev/stdout • /dev/stderr • /dev/null

cbimgmt $ cat /etc/passwd |do_job -i /dev/stdin -o /dev/stdout

cbimgmt $ -s /dev/stdout o.png && in. o.png |display

cbimgmt $ find /etc –name „*‟ -type f -exec ls -l {} \; 2>/dev/null Bash shortcuts – moving the cursor

Ctrl + a Go to the beginning of the line (Home) Ctrl + e Go to the End of the line (End) Ctrl + p Previous command (Up arrow) Ctrl + n Next command (Down arrow) Alt + b Back (left) one word Alt + f Forward (right) one word Ctrl + f Forward one character Ctrl + b Backward one character Ctrl + xx Toggle between the of line and current cursor position Bash shortcuts - editing

Ctrl + L Clear the Screen, similar to the clear command Ctrl + u Cut/delete the line before the cursor position. Alt + Delete the Word before the cursor. Alt + d Delete the Word after the cursor. Ctrl + d Delete character under the cursor Ctrl + h Delete character before the cursor (Backspace) Ctrl + w Cut the Word before the cursor to the . Ctrl + k Cut the Line after the cursor to the clipboard. Alt + t Swap current word with previous Ctrl + t Swap the last two characters before the cursor (typo). Esc + t Swap the last two words before the cursor. ctrl + y Paste the last thing to be cut (yank) Alt + u UPPER capitalize every character from the cursor to the end of the current word. Alt + l Lower the case of every character from the cursor to the end of the current word. Alt + c Capitalize the character under the cursor and move to the end of the word. Alt + r Cancel the changes and put back the line as it was in the history (revert). ctrl + _ Undo

TAB Tab completion for file/directory names Bash shortcuts - history

Ctrl + r Recall the last command including the specified character(s) searches the command history as you type. Equivalent to : vim ~/.bash_history. Ctrl + p Previous command in history (i.e. walk back through the command history) Ctrl + n Next command in history (i.e. walk forward through the command history)

Ctrl + s Go back to the next most recent command. (beware to not execute it from a terminal because this will also launch its XOFF). Ctrl + o Execute the command found via Ctrl+r or Ctrl+s Ctrl + g Escape from history searching mode !! Repeat last command !abc Run last command starting with abc !abc:p Print last command starting with abc !$ Last argument of previous command ALT + . Last argument of previous command !* All arguments of previous command ^abc^def Run previous command, replacing abc with def Bash shortcuts – process control

Ctrl + C Interrupt/ whatever you are running (SIGINT) Ctrl + l Clear the screen Ctrl + s Stop output to the screen (for long running verbose commands) Ctrl + q Allow output to the screen (if previously stopped using command above) Ctrl + D Send an EOF marker, unless disabled by an option, this will close the current shell (EXIT) Ctrl + Z Send the signal SIGTSTP to the current task, which suspends it. To resume the task enter ‘fg’ .

screen related tips • create a screen: #screen [ENTER] • fork a new shell #screen [ENTER] or C-a c • name current window: C-a A • switch to certain window: C-a ‘ • Present a list of all windows: C-a “ • Send the command character (C-a): C-a a • detach screen: C-a d • Toggle to previously window: C-a C-a • To screens: C-a S (Shift-s) • To unsplit screens: C-a Q (shift-q) • To switch between screens: C-a TAB • resumes a detached session: screen -r • Attach to a not detached session: screen -x Section III

Bash Script Programming Readings

• Advanced Bash-Scripting Guide 3.9.1 – http://www.linuxsir.org/main/?q=node/140

• BASH Programming - Introduction HOW-TO – http://www.linuxdoc.org/HOWTO/Bash-Prog- Intro-HOWTO.html UNIX Philosophy

• KISS: Keep It Simple and Stupid

• OT2: One Time, One Thing

• “Collaboration makes the world better” Very Simple Scripts

• Hello World [kongl@soft tmp]$ cat hello.sh #!/bin/bash echo Hello World [kongl@soft tmp]$ ./hello.sh Hello World

• A very simple backup script

#!/bin/bash tar -cZf /var/my-backup.tgz /home/me/ Input & Output • Standard input (stdin): keyboard; Standard output (stdout): monitor;

• A process has 3 special file descriptor.

Process file descriptor

$ ls -l /proc/14649/fd total 0 lrwx------1 lion lion 64 Aug 16 07:32 0 -> /dev/pts/8 lrwx------1 lion lion 64 Aug 16 07:32 1 -> /dev/pts/8 lrwx------1 lion lion 64 Aug 16 07:32 2 -> /dev/pts/8

Why did we look at directory /proc/14649/fd?

/proc is for "process information" /14649 is for "process #14649", the running bash shell /fd is for "file descriptors", the list of the process' open file descriptors

Now we see that we have three open file descriptors: 0,1,2. • 0 is stdin • 1 is stdout • 2 is stderr

IO Redirection

• 在shell中,使用者可以利用“>”和“<”来进行输入输出重定向。

• command >file – Redirect command’s stdout to a file

• command &>file – Redirect command’s stdout to a file along with the stderr

• command >>file – Append the command’s stdout to the file

• command &>> file – Append the command’s stdout to the file along with the stderr

• command 2>&1 – Redirect stderr to stdout.

• command i>&j – Redirect file descriptor i to j.

• j<>filename – Open file ‘filename’, and assign file descriptor j to it.

IO Redirection examples

[kongl@soft ~]$ > a ls [kongl@soft ~]$ cat a a Desktop F-7-i386-DVD.iso fedora7 gentoo new -svap surgemail_40u4_linux64.tar.gz tmp zimbra The order bash deal with io redirection: left to right

[kongl@soft tmp]$ ls [kongl@soft tmp]$ >a [kongl@soft tmp]$ >c [kongl@soft tmp]$ ls a c [kongl@soft tmp]$ b > d 2>&1 [kongl@soft tmp]$ cat d rm: cannot remove `b': No such file or directory [kongl@soft tmp]$ rm b 2>&1 >d rm: cannot remove `b': No such file or directory [kongl@soft tmp]$ cat d [kongl@soft tmp]$ [kongl@soft tmp]$ 2>&1 rm b > d rm: cannot remove `b': No such file or directory [kongl@soft tmp]$ >d 2>&1 rm b [kongl@soft tmp]$ >d rm b 2>&1

------我是分隔符------

[kongl@soft tmp]$ rm b 2>&1 2>a [kongl@soft tmp]$ cat a rm: cannot remove `b': No such file or directory [kongl@soft tmp]$ rm b 2>a 2>&1 rm: cannot remove `b': No such file or directory [kongl@soft tmp]$ cat a [kongl@soft tmp]$

Redirection order test

[kongl@soft tmp]$ cat c Greg Sanders: All work and no play makes Greg a dull boy. Gil Grissom: All play and no work makes Greg an UNEMPLOYED boy. [kongl@soft tmp]$ cat c > a > d > e > f [kongl@soft tmp]$ cat a [kongl@soft tmp]$ cat d [kongl@soft tmp]$ cat e [kongl@soft tmp]$ cat f Greg Sanders: All work and no play makes Greg a dull boy. Gil Grissom: All play and no work makes Greg an UNEMPLOYED boy. More Funny

[kongl@soft tmp]$ cat test.sh #!/bin/bash cat c rm b [kongl@soft tmp]$ ls a c d test.sh [kongl@soft tmp]$ ./test.sh > a rm: cannot remove `b': No such file or directory [kongl@soft tmp]$ cat a Greg Sanders: All work and no play makes Greg a dull boy. Gil Grissom: All play and no work makes Greg an UNEMPLOYED boy. [kongl@soft tmp]$ ./test.sh > a 3>&1 1>&2 2>&3 3<&- Greg Sanders: All work and no play makes Greg a dull boy. Gil Grissom: All play and no work makes Greg an UNEMPLOYED boy. [kongl@soft tmp]$ cat a rm: cannot remove `b': No such file or directory File descriptor

[kongl@soft tmp]$ ls c d test.sh [kongl@soft tmp]$ cat c Greg Sanders: All work and no play makes Greg a dull boy. Gil Grissom: All play and no work makes Greg an UNEMPLOYED boy. [kongl@soft tmp]$ 3<>a cat c>&3 [kongl@soft tmp]$ cat a Greg Sanders: All work and no play makes Greg a dull boy. Gil Grissom: All play and no work makes Greg an UNEMPLOYED boy. PIPE

STDOUT STDIN STDOUT Process A Process B

STDERR STDERR Sample: simple pipe with sed

[kongl@soft tmp]$ ls a c d e f find-example hello.sh sort_example.txt test.sh [kongl@soft tmp]$ ls | sed -e "s/[aeio]/u/g" u c d u f fund-uxumplu hullu.sh surt_uxumplu.txt tust.sh Sample: an alternative to ls -l *.txt

[kongl@soft tmp]$ ls -l *.txt -rw-r--r-- 1 kongl cbi 381 Nov 28 11:02 sort_example.txt [kongl@soft tmp]$ ls -l | "\.txt$" -rw-r--r-- 1 kongl cbi 381 Nov 28 11:02 sort_example.txt Variables

• Sample: Hello World! using variables

#!/bin/bash STR="Hello World!" echo $STR

• Sample: A very simple backup script (little bit better)

#!/bin/bash OF=/var/my-backup-$(date +%Y%m%d).tgz tar -cZf $OF /home/me/ Local variables

[kongl@soft tmp]$ cat local_hello.sh #!/bin/bash HELLO=Hello function hello { local HELLO=World echo $HELLO } echo $HELLO hello echo $HELLO [kongl@soft tmp]$ ./local_hello.sh Hello World Hello Conditionals

• if expression then statement

• if expression then statement1 else statement2

• if expression1 then statement1 else if expression2 then statement2 else statement3 Examples • Basic conditional example if .. then #!/bin/bash if [ "foo" = "foo" ]; then echo expression evaluated as true fi • Basic conditional example if .. then ... else #!/bin/bash if [ "foo" = "foo" ]; then echo expression evaluated as true else echo expression evaluated as false fi

• Conditionals with variables #!/bin/bash T1=" foo" T2="bar" if [ "$T1" = "$T2" ]; then echo expression evaluated as true else echo expression evaluated as false fi Loops - for

[kongl@soft tmp]$ cat for_example.sh #!/bin/bash for i in $( ls *.*); do echo item: $i done echo "======separater======" for i in `seq 1 5`; do echo $i done

[kongl@soft tmp]$ ./for_example.sh item: for_example.sh item: hello.sh item: local_hello.sh item: sort_example.txt item: test.sh ======separater======1 2 3 4 5 Loops - while

[kongl@soft tmp]$ cat while_example.sh #!/bin/bash COUNTER=0 while [ $COUNTER -lt 5 ]; do echo The counter is $COUNTER let COUNTER=COUNTER+1 done

[kongl@soft tmp]$ ./while_example.sh The counter is 0 The counter is 1 The counter is 2 The counter is 3 The counter is 4 Loops - until

[kongl@soft tmp]$ cat until_example.sh #!/bin/bash COUNTER=10 until [ $COUNTER -lt 5 ]; do echo COUNTER $COUNTER COUNTER=`expr $COUNTER - 1` done

[kongl@soft tmp]$ ./until_example.sh COUNTER 10 COUNTER 9 COUNTER 8 COUNTER 7 COUNTER 6 COUNTER 5 Functions without parameter

[kongl@soft tmp]$ cat fun_no_param.sh #!/bin/bash function quit { exit } function hello { echo "Hello World!" } hello quit echo "It should not reach here!"

[kongl@soft tmp]$ ./fun_no_param.sh Hello World! Functions with parameters

[kongl@soft tmp]$ cat fun_with_param.sh #!/bin/bash function quit { exit } function my_echo { echo $1 } my_echo Hello World my_echo "Hello World" quit echo "It should not reach here, either!"

[kongl@soft tmp]$ ./fun_with_param.sh Hello Hello World Using select to simple menus [kongl@soft tmp]$ cat select_menu.sh #!/bin/bash OPTIONS="Hello Test Quit" select opt in $OPTIONS; do if [ "$opt" = "Quit" ]; then echo done exit elif [ "$opt" = "Test" ]; then echo "This is a test." elif [ "$opt" = "Hello" ]; then echo "Hello World!" else clear echo "bad options!!!" fi done

[kongl@soft tmp]$ ./select_menu.sh 1) Hello 2) Test 3) Quit #? 1 Hello World! #? 2 This is a test. #? 3 done Using the command line parameters

[kongl@soft tmp]$ cat cmd_param.sh #!/bin/bash if [ -z "$1" ]; then echo usage: $0 directory exit fi SRCD=$1 TGTD="$HOME/tmp/" =`basename $SRCD` OF=$BASENAME-$(date +%Y%m%d).tgz echo tar czf "$TGTD/$OF" $SRCD tar czf "$TGTD/$OF" $SRCD

[kongl@soft tmp]$ ./cmd_param.sh usage: ./cmd_param.sh directory [kongl@soft tmp]$ ./cmd_param.sh find-example/ tar czf /home/kongl/tmp//find-example-20091129.tgz find-example/ [kongl@soft tmp]$ ls a d find-example fun_no_param.sh local_hello.sh test.sh c e find-example-20091129.tgz fun_with_param.sh select_menu.sh until_example.sh cmd_param.sh f for_example.sh hello.sh sort_example.txt while_example.sh Reading user input with read

[kongl@soft tmp]$ cat read_example.sh #!/bin/bash echo Please, enter your name read NAME echo "Hi $NAME!" echo Please, enter your firstname and lastname read FN LN echo "Hi! $LN, $FN !"

[kongl@soft tmp]$ ./read_example.sh Please, enter your name Kidding Hi Kidding! Please, enter your firstname and lastname Kidding Serious Hi! Serious, Kidding ! Arithmetic evaluation [kongl@soft tmp]$ cat arithmetic.sh #!/bin/bash echo "echo 1 + 1" echo 1 + 1 echo "echo \$((1+1))" echo $((1+1)) echo "echo \$[1+1]" echo $[1+1] echo "echo \$[3/4]" echo $[3/4] echo "echo 3/4|bc -l" echo 3/4|bc -l [kongl@soft tmp]$ ./arithmetic.sh echo 1 + 1 1 + 1 echo $((1+1)) 2 echo $[1+1] 2 echo $[3/4] 0 echo 3/4|bc -l .75000000000000000000 Getting the return value of a program

[kongl@soft tmp]$ cat return_val.sh #!/bin/bash cd /dada &> /dev/null echo return value: $? cd $() &> /dev/null echo return value: $?

[kongl@soft tmp]$ ./return_val.sh return value: 1 return value: 0 Capturing a commands output

[kongl@soft tmp]$ cat capture_output.sh #!/bin/bash LIST=`ls find-example` for f in $LIST do echo FILE: $f done

[kongl@soft tmp]$ ./capture_output.sh FILE: a.1 FILE: b.1 FILE: c.1 FILE: d.1 FILE: e.1 FILE: f.1 DEBUG • The first line like this will produce some intresting output information

#!/bin/bash -x

• Example: [kongl@soft tmp]$ cat debug.sh #!/bin/bash -x PARAM=$1 echo $0 echo $1

[kongl@soft tmp]$ ./debug.sh test.sh + PARAM=test.sh + echo ./debug.sh ./debug.sh + echo test.sh test.sh Acknownlegement

Dr. ZHAO, Shuqi REFERENCE

1. http://tldp.org/LDP/abs/html/io-redirection.html

2. http://www.linuxsir.org/main/doc/abs/abs3.7cnhtm/ioredirintro.html

3. http://hi.baidu.com/lb_hb/blog/item/bfe6a4659e8877f6f73654bd.html

4. http://www.diybl.com/course/3_program/shell/shelljs/200876/130761.h tml

5. http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html

6. http://ss64.com/bash/syntax-keyboard.html

Thanks 

Some Linux Tips

• mkfifo, a program to create named pipe GNU Text Utilities

• dos, unix, mac text file – dos2unix unix2dos mac2dos

• time, estimate the time for the jobs – time someprog progparam

• economize on disk – run_certain_program -o /dev/stdout | gzip -c > result.gz /proc directory organization • /proc/cpuinfo • /proc/meminfo • /proc/filesystems • /proc/version • /proc/[0-9]+ • /proc/[0-9]+/cmdline • /proc/[0-9]+/environ • /proc/[0-9]+/fd • /proc/[0-9]+/cwd Some Linux Tips • export • hash -r • reset • #the “\n” number, not the line number • ldd

cbimgmt $ ldd /bin/bash linux-gate.so.1 => (0xffffe000) libncurses.so.5 => /lib/libncurses.so.5 (0xb7f6e000) libdl.so.2 => /lib/libdl.so.2 (0xb7f6a000) libc.so.6 => /lib/libc.so.6 (0xb7e50000) /lib/ld-linux.so.2 (0xb7fb8000) file copy related Tips

• copy certain file to a new directory

cbimgmt $ target cbimgmt $ find src -name „*.class‟|grep -v secret| \ cpio -pd target • Compress certain files

cbimgmt $find ../dir1/ | cpio -o --format=tar > test.tar or cbimgmt $find ../dir1/ | cpio -o -H tar|gzip> test.tar.gz

• work with

cbimgmt $ mkdir target cbimgmt $ rsync --exclude="*.java" -av src target/ Some Linux Tips

• Remember the work path

cbimgmt $ cd some_path …. cbimgmt $ pushd some_path cbimgmt $ … do some work … cbimgmt $ … do some work … cbimgmt $ forget where to return? cbimgmt $ popd • Reorder the file column and row

cbimgmt $ cat data cbimgmt $ cat data | ' ' '\n'| -l5 1 2 3 cbimgmt $ cat data |tr ' ' '\n'|paste - - - - - 4 5 1 2 3 4 5 6 7 8 9 10 6 7 8 9 10

cbimgmt $ cat data|tr ' ' '\n'|xargs -l3|tr ' ' '+'|bc 15 40 Some Linux Tips • look up or signal process pgrep [-flvx] [-d delimiter] [-n|-o] [-P ppid,...] [-g pgrp,...] [-s sid,...] [-u euid,...] [-U uid,...] [-G gid,...] [-t term,...] [pattern]

pkill [-signal] [-fvx] [-n|-o] [-P ppid,...] [-g pgrp,...] [-s sid,...] [-u euid,...] [-U uid,...] [-G gid,...] [-t term,...] [pattern]

cbimgmt $ pgrep -u root #= ps -ef | egrep '^root ' | '{print $2}' cbimgmt $ pkill -HUP syslogd • display a of processes

pstree [-a] [-c] [-h|-Hpid] [-l] [-n] [-p] [-u] [-Z] [-A|-G|-U] [pid|user] SSH Related Tips

## Linux Laptop .ssh/config ## Host work HostName 66.35.250.203 User sporkey LocalForward 20000 192.168.0.66:80 LocalForward 22000 192.168.0.66:22 LocalForward 22139 192.168.0.8:139 Host workssh HostName localhost User donkey Port 22000 HostKeyAlias workssh

## Linux Laptop .ssh/config ## Host workssh HostName 192.168.0.66 ProxyCommand ssh [email protected] /usr/bin/nc -w 1 %h 22