Linux 101 Hacks CN

  • Published on
    28-Nov-2014

  • View
    1.622

  • Download
    2

Embed Size (px)

Transcript

Linux 101 Hacks

linux.101hacks.com

I

Linux 101 Hacks

linux.101hacks.com

Linux 101 Hacks IBM 08 Linux IBM Linux 101 Hacks Ramesh Natarajan Hacks Ubuntu 9.04

http://www.thegeekstuff.com/ http://linux.101hacks.com/ blog.footoo.org blog.cliffwoo.com cliffwoo@gmail.com

Pigsy.Beard@gmail.com

II

Linux 101 Hacks

linux.101hacks.com

................................................................................... II ..................................................................................... III ...................................................................................... 1 ................................................................................ 2 Vim 101 Hacks ........................................................... 3 .............................................................................. 4 ...................................................................................... 5 ...................................................................................... 6 CD ......................................................... 7 1CDPATH : cd ....................................................... 7 2 cd alias ................................................ 8 3mkdircd ................................................. 10 4cd - ............................................ 10 5dirspushdpopd ........................................ 11 6shopt s cdspellcd ...................... 13

.................................................................... 14 7 ..................................................................... 14 8 ..................................................................... 14 9 ............................................................... 15 10 ................................................................ 16 11 ................................................................ 17

SSHSecure SHell ....................................... 19 12 SSH ................................................................... 19 13 SSH ................................................................ 19 14 SSH ................................................................... 20 15 SSH SSH .......................................................... 21 16 SSH ..................................................... 22

linux ......................................................... 24 17grep ................................................................................ 24 18find ................................................................................. 25 19 ..................................................... 26 20join ................................................................................. 27

III

www.thegeekstuff.com

Linux 101 Hacks

linux.101hacks.com

21 ...................................................................... 27 22xargs ............................................................................... 28 23sort ................................................................................. 29 24uniq ................................................................................ 31 25cut .................................................................................. 31 26stat ................................................................................. 32 27diff ................................................................................. 33 28 ................................................................ 34

PS1,PS2,PS3 PROMPT_COMMAND .................................. 36 29PS1 ..................................................................... 36 30PS2 ..................................................................... 36 31PS3Shell select ....................................... 37 32PS4PS4-set -x" ..................................... 38 33PROMPT_COMMAND ....................................................... 39

PS1 ................................... 40 34 ....................................... 40 35.............................................................. 40 36 ........................................................... 41 37 ................................................................ 41 38 ................................................................... 42 39.............................................................. 42 40 tput ............................................................... 43 41 PS1 ............................................ 44 42 PS1 bash shell ....................................................... 45 43 PS1 shell ........................................................... 45

................................................................. 47 44zip ............................................................................ 47 45zip ............................................................................ 49 46zip ................................................................... 49 47 zip ................................................................ 50 48tar .................................................................... 50 49 tar gzip, bzip2 ............................................................ 51

history ................................................................ 52 50 HISTTIMEFORMAT TIMESTAMP .............................. 52 51 Ctrl R ........................................................... 52 52 ............................................... 53 53 .......................................................... 53 54 ....................................................... 53 55 HISTSIZE ................................................... 53 56 HISTFILE ...................................................... 54 57 HISTCONTROL ......................... 54

IV

www.thegeekstuff.com

Linux 101 Hacks

linux.101hacks.com

58 HISTCONTROL ................................. 54 59 HISTCONTROL history ............................ 55 60 c .................................................... 55 61 ................................................................ 55 62 ............................................................. 56 63 HISTSIZE history .............................................................. 56 64 HISTIGNORE history ............................... 56

.............................................................. 58 65 fdisk ..................................................................... 58 66 mke2fsk ............................................................. 59 67 ................................................................................ 60 68 tune2fs ............................................................. 61 69 ........................................................................... 62 70.............................................................................. 62 71 ....................................................... 63 72 OpenSSH SSH ............................................. 64 73 ssh-agent ssh-copy-id ............................................ 65 74crontab ................................................................................. 66 75 Magic SysRq Linux ............................................ 68

Apachectl Httpd ............................................... 70 76 httpd.conf apachectl ......................................... 70 77 DocumentRoot httpd.conf ............................. 71 78 Log ................................................................... 71 79 Apache ................................................................. 72 80 httpd.conf .............................................. 72 81 httpd.conf ............................................................. 73 82 httpd ................................................................ 73 83 ........................................................... 74

Bash ................................................................ 76 84.bash_*files .............................................................. 76 85 bash shell ..................................................... 77 86 ........................................................................... 77 87Quoting ................................................................. 78 88 shell ........................................... 80

......................................................... 81 89free ................................................................................. 81 90top .................................................................................. 81 91ps ................................................................................... 83 92df ................................................................................... 85 93kill .................................................................................. 85 94du ................................................................................... 87

V

www.thegeekstuff.com

Linux 101 Hacks

linux.101hacks.com

95lsof ................................................................................. 87 96sar .................................................................................. 89 97vmstat ............................................................................. 91 98netstat ............................................................................. 92 99sysctl ............................................................................... 94 100nice ............................................................................... 95 101renice ............................................................................ 96

.......................................................... 98 1 cd .................................................. 98 2 SSH .............................................. 99 3rar .................................................................. 100 4 Comm ..................................................... 102 5Compact-Disk (CD) .......................................................... 102 6DVD ............................................................................ 103 7 CD DVD ISO ................................................... 105 8OD .................................................................. 106 9Gpg ................................................................ 107 10Tee .................................................................. 111

12 Linux ............................................................113 .............................................................................115 .....................................................................116

VI

www.thegeekstuff.com

Linux 101 Hacks

linux.101hacks.com

10 : H H H H

-- Geek

101 Linux

13 10

http://linux.101hacks.com/

1

www.thegeekstuff.com

Linux 101 Hacks

linux.101hacks.com

Ramesh Natarajan,The Geek Stuff

C Linux EMC

Password Dragon Windows,Linux,Max vim 101 hacksthegeekstuff.com/vim-101-hacks-ebook/

thegeekstuff.com/contac

2

www.thegeekstuff.com

Linux 101 Hacks

linux.101hacks.com

Vim 101 HacksLinux 101 Hacks Vim 101 Hacks

Linux/Unix Vim

Vim Vim

Vim 101 Hacks 101 Vim Vim Vim

Vim 101 hacks http://www.thegeekstuff.com/vim-101-hacks-ebook/

3

www.thegeekstuff.com

Linux 101 Hacks

linux.101hacks.com

Copyright 2009 - 2010 Ramesh Natarajan. All rights reserved.

4

www.thegeekstuff.com

Linux 101 Hacks

linux.101hacks.com

Linux 101 Hacks

-

--Prof. Dr. Fritz Mehner, FH Sdwestfalen, Germany bah-support vim Vim

5

www.thegeekstuff.com

Linux 101 Hacks

linux.101hacks.com

2009 2 12 2010 1 13

1.01.1

6

www.thegeekstuff.com

Linux 101 Hacks

linux.101hacks.com

CD cd Linux Unix 6 cd

1CDPATH : cd CD CDPATH cd , [ramesh@dev-db ~]# pwd /home/ramesh [ramesh@dev-db ~]# cd mail -bash: cd: mail: No such file or directory [: mail ] [ramesh@dev-db ~]# export CDPATH=/etc [ramesh@dev-db ~]# cd mail /etc/mail [: /etc mail mail ] [ramesh@dev-db /etc/mail]# pwd /etc/mail export CDPATH=/etc ~/.bash_profile PATH CDPATH export CDPATH=.:~:/etc:/var o OracleDBAsORACLE$ORACLE_HOME CDPATHOracle o Linux/Unix/etcCDPATH /etc o /home/projectsCDPATH /home/projects o CDPATH

7

www.thegeekstuff.com

Linux 101 Hacks~Linux/Unix

linux.101hacks.com

2 cd alias cd ../../ ,../, # mkdir -p /tmp/very/long/directory/structure/that/is/too/deep # cd /tmp/very/long/directory/structure/that/is/too/deep # pwd /tmp/very/long/directory/structure/that/is/too/deep # cd ../../../../ # pwd /tmp/very/long/directory/structure cd ../../../../ ,

..n..4 4 ..3 3 ..2 2 ~/.bashrc Linux/Unix ~/.bash_profile alias ..="cd .." alias ..2="cd ../.." alias ..3="cd ../../.." alias ..4="cd ../../../.." alias ..5="cd ../../../../.."

# cd /tmp/very/long/directory/structure/that/is/too/deep # ..4 [: ..4 ] # pwd /tmp/very/long/directory/structure/

"."

8

www.thegeekstuff.com

Linux 101 Hacks

linux.101hacks.com

.....(5 ) 5 ....(4 ) 3 2 .....(5 )./.bash_profile alias ..="cd .." alias ...="cd ../.." alias ....="cd ../../.." alias .....="cd ../../../.." alias ......="cd ../../../../.."

# cd /tmp/very/long/directory/structure/that/is/too/deep # ..... [:.....5 ] # pwd /tmp/very/long/directory/structure/

cd cd ..... cd 5 5 4 cd ....cd 4 3 cd ...(cd 3 ) 2 cd .....(5 ) ./.bash_profile alias cd..="cd .." alias cd...="cd ../.." alias cd....="cd ../../.." alias cd.....="cd ../../../.." alias cd......="cd ../../../../.." # cd /tmp/very/long/directory/structure/that/is/too/deep # cd..... [ : cd.....] # pwd /tmp/very/long/directory/structure

cd Method 5cd4cd 4 4 alias cd1="cd .." alias cd2="cd ../.." alias cd3="cd ../../.."

9

www.thegeekstuff.com

Linux 101 Hacksalias cd4="cd ../../../.." alias cd5="cd ../../../../.."

linux.101hacks.com

3mkdircd cd # mkdir -p /tmp/subdir1/subdir2/subdir3 # cd /tmp/subdir1/subdir2/subdir3 # pwd /tmp/subdir1/subdir2/subdir3

mkdir cd ./.bash_profile $ vi .bash_profile function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }

mkdir cd # mkdircd /tmp/subdir1/subdir2/subdir3 [: ] # pwd /tmp/subdir1/subdir2/subdir3

4cd -cd - # cd /tmp/very/long/directory/structure/that/is/too/deep # cd /tmp/subdir1/subdir2/subdir3 # cd # pwd /tmp/very/long/directory/structure/that/is/too/deep

10

www.thegeekstuff.com

Linux 101 Hacks

linux.101hacks.com

# cd # pwd /tmp/subdir1/subdir2/subdir3 # cd # pwd /tmp/very/long/directory/structure/that/is/too/deep

5dirspushdpopd * dirs: * pushd: * popd:

dirs dirs # popd -bash: popd: directory stack empty # dirs ~ # pwd /home/ramesh

pushd pop...