Professional Documents
Culture Documents
com
I
Linux 101 Hacks linux.101hacks.com
Ramesh Natarajan
http://www.thegeekstuff.com/
http://linux.101hacks.com/
blog.footoo.org blog.cliffwoo.com
Pigsy.Beard@gmail.com cliffwoo@gmail.com
II
Linux 101 Hacks linux.101hacks.com
................................................................................... II
..................................................................................... III
...................................................................................... 1
................................................................................ 2
.............................................................................. 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
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 ................................... 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
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
C
Linux
EMC
Password Dragon
Windows,Linux,Max
thegeekstuff.com/contac
2 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
Linux/Unix
Vim
Vim
Vim
Vim
3 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
4 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
5 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
1.0 2009 2 12
1.1 2010 1 13
6 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
CD
cd Linux Unix 6 cd
1CDPATH : cd
CD CDPATH
cd ,
[: mail ]
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.101hacks.com
~Linux/Unix
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
# 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
# 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
# cd /tmp/very/long/directory/structure/that/is/too/deep
# cd.....
[ : cd.....]
# pwd
/tmp/very/long/directory/structure
cd Method 5
cd4cd 4 4
9 www.thegeekstuff.com
Linux 101 Hacks 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
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 popd
# mkdir /tmp/dir1
# mkdir /tmp/dir2
# mkdir /tmp/dir3
# mkdir /tmp/dir4
# cd /tmp/dir1
# pushd .
11 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
# cd /tmp/dir2
# pushd .
# cd /tmp/dir3
# pushd .
# cd /tmp/dir4
# pushd .
# dirs
/tmp/dir4 /tmp/dir4 /tmp/dir3 /tmp/dir2 /tmp/dir1
[:]
/tmp/dir4
/tmp/dir3
/tmp/dir2
/tmp/dir1
popd
/tmp/dir4
popd /tmp/dir4
# popd
# pwd
/tmp/dir4
[: popd
/tmp/dir3
/tmp/dir2
/tmp/dir1]
# popd
# pwd
/tmp/dir3
[: popd ]
/tmp/dir2
/tmp/dir1]
# popd
# pwd
12 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
/tmp/dir2
[: popd
/tmp/dir1]
# popd
# pwd
/tmp/dir1
[: popd ]
# popd
-bash: popd: directory stack empty
6shopt s cdspellcd
"shopt -s cdspell" cd
# cd /etc/mall
-bash: cd: /etc/mall: No such file or directory
# shopt -s cdspell
# cd /etc/mall
# pwd
/etc/mail
[: mail mall mall mail]
13 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
# date {mmddhhmiyyyy.ss}
mm
dd
hh 24
mi
yyyy
ss
2008 01 31 101953
# date 013122192009.53
# date 013122192009.53
# date +%Y%m%d -s "20090131"
# date -s "01/31/2009 22:19:53"
# date -s "31 JAN 2009 22:19:53"
# date set="31 JAN 2009 22:19:53"
8
7
# hwclock systohc
14 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
hwclock
# hwclock
clock UTC(:)
#cat /etc/default/rcS
UTC=yes
Linux RebHat
# cat /etc/sysconfig/clock
ZONE="America/Los_Angeles"
UTC=false
ARC=false
$ date
Thu Jan 1 08:19:23 PST 2009
$ date --date="now"
Thu Jan 1 08:20:05 PST 2009
$ date --date="today"
Thu Jan 1 08:20:12 PST 2009
$ date +"%d-%m-%Y"
01-01-2009
$ date +"%d/%m/%Y"
01/01/2009
15 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
date
o %D (//)
o %d (01..31)
o %m (01..12)
o %y (00..99)
o %a (Sun..Sat)
o %A (Sunday..Saturday)
o %b (Jan..Dec)
o %B (January..December)
o %H 24 (00..23)
o %I 12 (01..12)
o %Y (1970)
10
$ date --date="yesterday"
Wed Dec 31 08:27:34 PST 2008
16 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
11
$ date
Thu Jan 1 08:30:07 PST 2009
$ date --date='tomorrow'
Fri Jan 2 08:30:25 PST 2009
17 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
18 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
SSHSecure SHell
12 SSH
SSH ssh -V
Linux OpenSSH:
OpenSSH
$ ssh -V
OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003
SSH2
$ ssh -V
ssh: SSH Secure Shell 3.2.9.1 (non-commercial version) on
i686-pc-linux-gnu
13 SSH
ssh "yes"
.ssh/hostkeys
ssh
19 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
o SSH
o
yes
14 SSH
ssh v (
v)
SSH
20 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
ssh
ssh
ssh
15 SSH SSH
A A B A
ssh
ssh
1.
2.
remotehost$
3.~Control-Z
21 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
~<Control-Z>
~<Control-Z>
remotehost$ ~^Z
[1]+ Stopped ssh -l jsmith remotehost
localhost$
4.ssh UNIX
localhost$ jobs
[1]+ Stopped ssh -l jsmith remotehost
5. ssh
localhost$ fg %1
ssh -l jsmith remotehost
remotehost$
16 SSH
SSH 2
ssh ~ s ssh
remotehost$ [:~s .]
22 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
packets in: 15
packets out: 24
rekeys: 0
Algorithms:
Chosen key exchange algorithm: diffie-hellman-group1-sha1
Chosen host key algorithm: ssh-dss
Common host key algorithms: ssh-dss,ssh-rsa
Algorithms client to server:
Cipher: aes128-cbc
MAC: hmac-sha1
Compression: zlib
Algorithms server to client:
Cipher: aes128-cbc
MAC: hmac-sha1
Compression: zlib
localhost$
SSH
23 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
linux
17grep
grep grep
grep [] pattern []
jsmith:x:1082:1082:John Smith:/home/jsmith:/bin/bash
jdoe:x:1083:1083:John Doe:/home/jdoe:/bin/bash
-v
/etc/passwordJohn
/etc/passwordJohn
jbourne:x:1084:1084:Jason Bourne:/home/jbourne:/bin/bash
/etc/password/John
-cv John
-i
24 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
jsmith:x:1082:1082:John Smith:/home/jsmith:/bin/bash
jdoe:x:1083:1083:John Doe:/home/jdoe:/bin/bash
-r/home/users/
John-l
/home/users/subdir1/letter.txt
/home/users/name_list.txt
18find
find UNIX
find
: find
/etcmail
100M
60
25 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
# find . mtime -2
.tar.gz 100M
ls -l
rm
/home/jsmith 60 /tmp
ddmmyyyy_archive.tar
19
shell
/dev/nulll
/dev/null
shell
2>/dev/null
26 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
20join
join
employee.txt salary-
employee-id employee-id
$ cat employee.txt
$ cat bonus.txt
100 $5,000
200 $500
300 $3,000
400 $1,250
21
$ cat employee.txt
27 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
$ cat department.txt
100 FINANCE
200 MARKETING
300 PRODUCT DEVELOPMENT
400 SALES
100 finance
200 marketing
300 product development
400 sales
22xargs
xargs
xargs
1. rm /bin/rm Argument
list too long Linux xargs
/etc .conf
xargs.find xargs ls -l
.jpg
jpg
28 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
23sort
sort sort
:
$ cat names.txt
Emma Thomas:100:Marketing
Alex Jason:200:Sales
Madison Randy:300:Product Development
Sanjay Gupta:400:Support
Nisha Singh:500:Sales
$ sort names.txt
Alex Jason:200:Sales
Emma Thomas:100:Marketing
Madison Randy:300:Product Development
Nisha Singh:500:Sales
Sanjay Gupta:400:Support
$ sort -r names.txt
Sanjay Gupta:400:Support
Nisha Singh:500:Sales
Madison Randy:300:Product Development
Emma Thomas:100:Marketing
Alex Jason:200:Sales
employee_id
Emma Thomas:100:Marketing
29 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
Alex Jason:200:Sales
Madison Randy:300:Product Development
Sanjay Gupta:400:Support
Nisha Singh:500:Sales
tab (department_id),
Emma Thomas:100:Marketing
Madison Randy:300:Product Development
Alex Jason:200:Sales
Sanjay Gupta:400:Support
passwd (userid)
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
ip /etc/hosts
ps ef | sort :
ls -al | sort +4n : ls -al ( 5 )
ls -al | sort +4nr : ls -al ( 5 )
30 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
24uniq
uniq uniq sort
uniq
employee
Alex Emma
2 Alex Jason:200:Sales
2 Emma Thomas:100:Marketing
1 Madison Randy:300:Product Development
1 Nisha Singh:500:Sales
1 Sanjay Gupta:400:Support
3.
2 Alex Jason:200:Sales
2 Emma Thomas:100:Marketing
25cut
cut
employee_name
Emma Thomas
Alex Jason
Madison Randy
Sanjay Gupta
31 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
Nisha Singh
Emma Thomas:Marketing
Alex Jason:Sales
Madison Randy:Product Development
Sanjay Gupta:Support
Nisha Singh:Sales
Alex Jas
Madison
Sanjay G
Nisha Si
cut
26stat
stat
$ stat /etc/my.cnf
File: `/etc/my.cnf'
Size: 346 Blocks: 16 IO Block: 4096 regular file
Device: 801h/2049d Inode: 279856 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2009-01-01 02:58:30.000000000 -0800
Modify: 2006-06-01 20:42:27.000000000 -0700
Change: 2007-02-02 14:17:27.000000000 -0800
32 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
$ stat /home/ramesh
File: `/home/ramesh'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 803h/2051d Inode: 5521409 Links: 7
Access: (0755/drwxr-xr-x) Uid: ( 401/ramesh) Gid: ( 401/ramesh)
Access: 2009-01-01 12:17:42.000000000 -0800
Modify: 2009-01-01 12:07:33.000000000 -0800
Change: 2009-01-09 12:07:33.000000000 -0800
-f
$ stat -f /
File: "/"
ID: 0 Namelen: 255 Type: ext2/ext3
Blocks: Total: 2579457 Free: 2008027 Available: 1876998 Size: 4096
Inodes: Total: 1310720 Free: 1215892
27diff
diff
diff [] 1 2
diff w
diff
o---name_list.txt
o---name_list_new.txt
<>
2c2,3
< John Doe
---
33 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
28
ac
d 6
12 1 1
$ ac d
-p
$ ac -p
john 3.64
madison 0.06
sanjay 88.17
nisha 105.92
ramesh 111.42
total 309.21
$ ac -d sanjay
34 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
35 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
PS1,PS2,PS3 PROMPT_COMMAND
29PS1
Linux PS1
\s-\v\$, shell
[: "username@hostname current-dir>]
PS1
o \u --
o \h --
o \w --
PS1
[: ]
PS1
30PS2
\>
PS2 "continue->"
36 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
[: ">" ]
[: "continue-> " ]
31PS3Shell select
PS3 shell select
PS3 :
[: #?]
PS3
37 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
32PS4PS4-set -x"
PS4
PS4 shell:
set x
echo "PS4 demo script"
ls -l /etc/ | wc l
du -sh ~
38 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
++ wc l
243
++ du -sh /home/ramesh
48K /home/ramesh
[: sex -x ++]
PS4 :
PS4 ps.sh
o $0
o $LINENO
ramesh@dev-db ~> cat ps4.sh
33PROMPT_COMMAND
Bash PS1 PROMPT_COMMAND
22:08:42
ramesh@dev-db ~>
[: PROMPT_COMMAND PS1 ]
39 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
[22:08:51]ramesh@dev-db ~>
[: PROMPT_COMMAND PS1 ]
PS1
34
PS1
o /u
o /h
o /W
ramesh@dev-db mail>
35
81B PS1 $(LINUX COMMAND) LINUX
$(date)
ramesh@dev-db [11:09:56]>
\t hh:mm:ss
ramesh@dev-db [12:42:55]
83B \@ 12
40 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
36
LINUX ""
o \!
o \h
o $kernel_version name -r
o \$!
473|dev-db|2.6.25-14.fc9.i686|0>
37
:
[: ]
[: ]
o \e[
o x;ym
o \e[m
0:30
0;34
0;32
0;36
0;31
0;35
0;33
: 1 0]
~/.bashrc ~/.bash_profile
41 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
$ vi ~/.bash_profile
STARTCOLOR='\e[0;34m';
ENDCOLOR="\e[0m"
export PS1="$STARTCOLOR\u@\h \w> $ENDCOLOR"
38
PS1 /e{code}m
[: ]
[: ]
$ vi ~/.bash_profile
STARTFGCOLOR='\e[0;34m';
STARTBGCOLOR="\e[47m"
ENDCOLOR="\e[0m"
export PS1="$STARTFGCOLOR$STARTBGCOLOR\u@\h \w>
$ENDCOLOR"
o \e[40m
o \e[41m
o \e[42m
o \e[43m
o \e[44m
o \e[45m
o \e[46m
o \e[47m
39
~/bashrc
42 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
function prompt {
local BLUE="\[\033[0;34m\]"
local DARK_BLUE="\[\033[1;34m\]
local RED=\[\033[0;31m\]
local DARK_RED=\[\033[1;31m\]
local NO_COLOR=\[\033[0m\]
case $TERM in
xterm*|rxvt*)
TITLEBAR=\[\033]0;\u@\h:\w\007\]
;;
*)
TITLEBAR="
;;
esac
PS1=\u@\h [\t]>
PS1=${TITLEBAR}\
$BLUE\u@\h $RED[\t]>$NO_COLOR
PS2=continue->
PS4=$0.$LINENO+
}
source
$. ./.bash_profile
$ prompt
ramesh@dev-db [13:02:13]>
40 tput
PS1 tput
tput
tput
o tput bold -
43 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
o tput dim -
o tput smul -
o tput rmul -
o tput rev -
o tput smso -
o tput rmso -
o tput sgr0 -
tput
o 0
o 1
o 2
o 3
o 4
o 5
o 6
o 7 -
41 PS1
o \a ASCII
o \d (Tue May 26)
o \D{format} - strftime(3),
o \e ASCII
o \h
o \H
o \j shell
o \l shell
o \n
o \r
o \s shell$0 ()
o \t 24-hour HH:MM:SS
o \T 12-hour HH:MM:SS
o \@ 12-hour am/pm
o \A 24-hour HH:MM
o \u
o \v bash( 2.00)
o \V bash( 2.00.0)
o \w ,$HOME
o \W $HOME
o \!
44 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
o \#
o \$ ID 0#$
o \nnn
o \\
o \[ ,
o \]
./bash_profile ./bashrc
$ vi .bash_profile
function httpdcount {
ps aux | grep httpd | grep -v grep | wc -l
}
export PS1='\u@\h [`httpdcount`]> '
43 PS1 shell
PS1 PS1 ~/bin/totalfilesize.sh
45 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
[: PS1 totalfilesize.sh ]
46 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
44zip
zip
a*.zip
# unzip var-log.zip
Archive: var-log.zip
inflating: var/log/acpid
47 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
inflating: var/log/anaconda.log
inflating: var/log/anaconda.syslog
inflating: var/log/anaconda.xlog
creating: var/log/audit/
# unzip -v var-log.zip
Archive: var-log.zip
Length Method Size Ratio Date Time CRC-32
Name
-------- ------ ------- ----- ---- ---- ------ ---
-
1916 Defl:N 369 81% 02-08-08 14:27 e2ffdc0c
var/log/acpid
13546 Defl:N 2900 79% 02-02-07 14:25 34cc03a1
var/log/anaconda.log
skip..
7680 Defl:N 411 95% 12-30-08 10:55 fe876ee9
var/log/wtmp.1
40981 Defl:N 7395 82% 02-08-08 14:28 6386a95e
var/log/Xorg.0.log
-------- ------- --- ---
----
41406991 2809229 93% 56
files
# unzip -l var-log.zip
Archive: var-log.zip
Length Date Time Name
-------- ---- ---- ----
1916 02-08-08 14:27 var/log/acpid
13546 02-02-07 14:25 var/log/anaconda.log
..skip..
40981 02-08-08 14:28 var/log/Xorg.0.log
40981 02-08-07 14:56 var/log/Xorg.0.log.old
-------- -------
41406991 56 files
48 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
45zip
zip
o 0
o 1
o 6
o 9 9
0 6 9
# ls -ltr
-rw-r--r-- 1 root root 2817248 Jan 1 13:05
var-log-files-default.zip
-rw-r--r-- 1 root root 41415301 Jan 1 13:05
var-log-files-0.zip
-rw-r--r-- 1 root root 2582610 Jan 1 13:06
var-log-files-9.zip
46zip
zip P zip
shell
History e
# unzip var-log-protected.zip
Archive: var-log-protected.zip
[var-log-protected.zip] var/log/acpid password:
49 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
47 zip
zip t
# unzip -t var-log.zip
Archive: var-log.zip
testing: var/log/acpid OK
testing: var/log/anaconda.log OK
testing: var/log/anaconda.syslog OK
skip...
testing: var/log/wtmp OK
testing: var/log/wtmp.1 OK
testing: var/log/Xorg.0.log OK
No errors detected in compressed data of var-log.zip.
48tar
tar (tape archive)
tar [] [] []
/tmp my_home_directory.tar
/home/jsmith
vverbose
50 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
tar.gz
tar gzip
tar.gz z
tar bzip2
tar.bzip2 j
51 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
history
15
50 HISTTIMEFORMAT TIMESTAMP
history
[ alias ]
51 Ctrl R
history
Ctrl + R
redredcat
/etc/redhat-release
CtrlRreverse-i-search
.httpd
service httpd stopstopstart
[: Ctrl+R , reverse-i-search]
(reverse-i-search)`httpd`: service httpd stop
52 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
: ,
# service httpd start
52
1. up arrow
2.!!
3.!-1
4. Ctrl+P
53
4
# history | more
1 service network restart
2 exit
3 id
4 cat /etc/redhat-release
# !4
cat /etc/redhat-release
Fedora release 9 (Sulphur)
54
ps
psps aux | grep yp
# !ps
ps aux | grep yp
root 16947 0.0 0.0 36516 1264 ? Sl 13:10 0:00 ypbind
root 17503 0.0 0.0 4124 740 pts/0 S+ 19:19 0:00 grep yp
55 HISTSIZE
.bash_profile bash source .bash_profile
bash 450
# vi ~/.bash_profile
HISTSIZE=450
53 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
HISTFLESIZE=450
56 HISTFILE
.bash_history .bash_profile
shell.commandline_warrior .bash_history
# vi ~/.bash_profile
HISTFILE=/root/.commandline_warrior
57 HISTCONTROL
pwd history
HISTCONTROL ignoredups,
# pwd
# pwd
# pwd
# history | tail -4
44 pwd
45 pwd
46 pwd
47 history | tail -4
[: pwd pwd ]
# export HISTCONTROL=ignoredups
# pwd
# pwd
# pwd
# history | tail -3
56 export HISTCONTROL=ignoredups
57 pwd
58 history | tail -4
[ pwd pwd ]
58 HISTCONTROL
ignoredups HISTCONTROL
erasedups
# export HISTCONTROL=erasedups
# pwd
# service httpd stop
54 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
# history | tail -3
38 pwd
39 service httpd stop
40 history | tail -3
# ls -ltr
# service httpd stop
# history | tail -6
35 export HISTCONTROL=erasedups
36 pwd
37 history | tail -3
38 ls ltr
39 service httpd stop
40 history | tail -6
[: pwd service httpd stop ]
59 HISTCONTROL history
HISTCONTROL ignorespace
history history
ignorespace history
# export HISTCONTROL=ignorespace
# ls ltr
# pwd
# service httpd stop
[: service ]
# history | tail -3
67 ls ltr
68 pwd
69 history | tail -3
60 c
history
# history -c
61
vi "!!:$"
55 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
# ls anaconda-ks.cfg
anaconda-ks.cfg
# vi !!:$
vi anaconda-ks.cfg
vi !^
# cp anaconda-ks.cfg anaconda-ks.cfg.bak
anaconda-ks.cfg
# vi !^
vi anaconda-ks.cfg
62
!cp:2 cp (ls -l)
# cp ~/longname.txt /really/a/very/long/path/long-filename.txt
# ls -l !cp:2
ls -l /really/a/very/long/path/long-filename.txt
!cp:$ cp
ls l
# ls -l !cp:$
ls -l /really/a/very/long/path/long-filename.txt
63 HISTSIZE history
history bash shell HISTSIZE 0
# export HISTSIZE=0
# history
# [: history ]
64 HISTIGNORE history
pwd,ls HISTIGNORE
56 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
HISTIGNORE lslsls l
# pwd
# ls
# ls ltr
# history | tail -3
79 export HISTIGNORE=pwd:ls:ls -ltr:
80 service httpd stop
81 history
57 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
65 fdisk
fdisk
fdisk 5
o n
o d
o p
o w .
o q fdisk
, /dev/sda1
# fdisk /dev/sda
Device contains neither a valid DOS partition table, nor Sun, SGI or
OSF disklabel Building a new DOS disklabel. Changes will remain in
memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
The number of cylinders for this disk is set to 34893.
There is nothing wrong with that, but this is larger than 1024, and
could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected
by w(rite)
Command (m for help): p
Disk /dev/sda: 287.0 GB, 287005343744 bytes
255 heads, 63 sectors/track, 34893 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
58 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
# fdisk /dev/sda
The number of cylinders for this disk is set to 34893.
There is nothing wrong with that, but this is larger than 1024, and
could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sda: 287.0 GB, 287005343744 bytes
255 heads, 63 sectors/track, 34893 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 34893 280277991 83 Linux
Command (m for help): q
66 mke2fsk
superblock
# tune2fs -l /dev/sda1
mke2fs
# mke2fs /dev/sda1
mke2fs
59 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
o -m 0 : reserved-blocks-percentage
5% 0
o -b 4096 : block-size specified in bytes. 1024
2048 4096
ext2 ext3
# mkfs.ext3 /dev/sda1
# mke2fs j /dev/sda1
67
# mkdir /home/database
/etc/fstab
60 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
68 tune2fs
tune2fs l /dev/sda1
# tune2fs -l /dev/sda1
tune2fs 1.35 (28-Feb-2004)
Filesystem volume name: /home/database
Last mounted on: <not available>
Filesystem UUID: f1234556-e123-1234-abcd-bbbbaaaaae11
Filesystem magic number: 0xEF44
Filesystem revision #: 1 (dynamic)
Filesystem features: resize_inode filetype sparse_super
Default mount options: (none)
Filesystem state: not clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 1094912
Block count: 140138994
Reserved block count: 0
Free blocks: 16848481
Free inodes: 1014969
First block: 0
Block size: 2048
Fragment size: 2048
Reserved GDT blocks: 512
Blocks per group: 16384
Fragments per group: 16384
Inodes per group: 128
Inode blocks per group: 8
Filesystem created: Tue Jul 1 00:06:03 2008
Last mount time: Thu Aug 21 05:58:25 2008
Last write time: Fri Jan 2 15:40:36 2009
Mount count: 2
Maximum mount count: 20
Last checked: Tue Jul 1 00:06:03 2008
Check interval: 15552000 (6 months)
Next check after: Sat Dec 27 23:06:03 2008
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
61 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
tune2fs ex2/ext3
69
# mkswap /home/swap-fs
Linux
# swapon /home/swap-fs
/etc/fstab !
70
# useradd jsmith
62 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
useradd
o -c :
o -e : mm/dd/yy
# passwd jsmith
Changing password for user jsmith.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
useradd ?
# useradd D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
71
# groupadd developers
63 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
useradd
# id jsmith
uid=510(jsmith) gid=511(developers) groups=511(developers)
72 OpenSSH SSH
ssky-keygen ssh-copy-id 3
Linux
ssh-keygen ssh-copy-id
authorized_keys ssh-copy-id home~/.ssh,
~/.ssh/authorized_keys
1: ssh-key-gen
jsmith@local-host$ ssh-keygen
64 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
2: ssh-copy-id
jsmith@remote-hosts password:
Now try logging into the machine, with ssh remote-host, and check
in:
.ssh/authorized_keys to make sure we havent added extra keys that
you werent expecting.
[: ssh-copy-id .ssh/authorized_key .]
3:
[: SSH .]
jsmith@remote-host$ [: ]
73 ssh-agent ssh-copy-id
ssh-add/ssh-agent ssh-copy-id
i ~/.ssh/identity.pub , ssh-copy-id
jsmith@local-host$ ssh-add -L
The agent has no identities.
65 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
jsmith@local-host$ ssh-add
Identity added: /home/jsmith/.ssh/id_rsa (/home/jsmith/.ssh/id_rsa)
jsmith@local-host$ ssh-add -L
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAsJIEILxftj8aSxMa3d8t6JvM79D
aHrtPhTYpq7kIEMUNzApnyxsHpH1tQ/Ow== /home/jsmith/.ssh/id_rsa
jsmith@remote-hosts password:
Now try logging into the machine, with ssh remote-host, and check
in: .ssh/authorized_keys to make sure we havent added extra keys that
you werent expecting.
[: ssh-add -L ]
ssh-copy-id
1. : ssh-copy-id ~/.ssh/identity.pub (
i ) id_dsa.pub, id_rsa.pub,
identity.pub ,
,
identity.pub
3. authorized_keys: ssh-copy-id
authorized_keys ssh-copy-id,
authorized_keys
authorized_keys
74crontab
crontab shell Linux
cron ?
# crontab e
66 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
0 5 * * * /root/bin/backup.sh
5 /root/bin/backup.sh
Cron
crontab
Crontab
1. 12:01 a.m
1 0 * * * /root/bin/backup.sh
2. (Mon Fri) 11:59 p.m
59 11 * * 1,2,3,4,5 /root/bin/backup.sh
59 11 * * 1-5 /root/bin/backup.sh
3. 5
*/5 * * * * /root/bin/check-status.sh
4. 1:10 p.m
10 13 1 * * /root/bin/full-backup.sh
5. 11 p.m
0 23 * * 1-5 /root/bin/incremental-backup.sh
Crontab
crontab :
o crontab e : crontab .
o crontab l : crontab
o crontab -r : crontab
67 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
SysRq
SysRq
Alt+SysRq+commandkey Commandkeys.
o k- virtual console
o s-
o b-
o e- init SIGTERM
o m-
o i- init SIGKILL
o r- rawX11 XLATE
o s
o t
o u
o o
o p
o 0-9-
o f oom_kill
o h
/proc/sysrq-trigger ,
Linux
fsck Alt+SysRq
o unRaw (X11 ),
o tErminate (SIGTERM),
o Kill (SIGKILL),
o Sync (),
68 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
o Unmount (),
o reBoot ()
69 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
Apachectl Httpd
Apache2 , apachectl httpd
9 apachectl httpd
76 httpd.conf apachectl
httpd.conf Apache
httpd.conf httpd.conf.debug
httpd.conf.debug Apache
-f
# apachectl -f conf/httpd.conf.debug
[ apachectl httpd ]
Apache httpd.conf
Apache:
# cp httpd.conf.debug httpd.conf
# apachectl stop
# apachectl start
70 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
-k start
daemon 25115 25114 0 23:28 00:00:00 /usr/sbin/httpd
-k start
[ps httpd ]
77 DocumentRoot httpd.conf
DocumentRoot ,
DocumentRoot directory(/var/www/html) DocumentRoot
(/var/www/html/_debug) DocumentRoot
/var/www/html_debug Apache c
DocumentRoot,
DocumentRoot(/var/www/html), Apache
# httpd -k stop
# apachectl start
78 Log
httpd.conf LogLevel
LogLevel eLogLevel
o debug
o info
o notice
o warn
o error
o crit
71 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
o alert
o emerg
79 Apache
Apache
# httpd -l
Compiled in modules:
core.c
prefork.c
http_core.c
mod_so.c
Apache
l httpd M
:
# httpd M
Loaded Modules:
core_module (static)
mpm_prefork_module (static)
http_module (static)
so_module (static)
auth_basic_module (shared)
auth_digest_module (shared)
authn_file_module (shared)
authn_alias_module (shared)
Syntax OK
80 httpd.conf
httpd httpd.conf.
httpd.conf
Apache
# httpd L
HostnameLookups (core.c)
on to enable, off to disable reverse DNS lookups,
72 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
ServerLimit (prefork.c)
Maximum value of MaxClients for this run of Apache
Allowed in *.conf only outside <Directory>, <Files> or
<Location>
KeepAlive (http_core.c)
Whether persistent connections should be On or Off
Allowed in *.conf only outside <Directory>, <Files> or
<Location>
LoadModule (mod_so.c)
a module name and the name of a shared object file to
load it from
Allowed in *.conf only outside <Directory>, <Files> or
<Location>
81 httpd.conf
t Apache httpd.conf.debug
148 ,mod_auth_basicso so .
# httpd -t -f conf/httpd.conf.debug
Syntax OK
# httpd -t -f conf/httpd.conf.debug
Syntax OK
82 httpd
V Apache Apache
73 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
# httpd V
Apache v()
# httpd -v
83
Apache , LDAP LDAP
Apache
74 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
<IfDefine load-ldap>
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module
modules/mod_authnz_ldap.so
</IfDefine>
# apachectl start
[ ldap Apache]
75 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
Bash
84.bash_*files
o /etc/profile
o ~/.bash_profile
o ~/.bashrc
o ~/.bash_login
o ~/.profile
o ~/.bash_logout
shell
execute /etc/profile
IF ~/.bash_profile exists THEN
execute ~/.bash_profile
ELSE
IF ~/.bash_login exist THEN
execute ~/.bash_login
ELSE
IF ~/.profile exist THEN
execute ~/.profile
END IF
END IF
END IF
shell
/etc/bashrc ~/.bashrc
# cat ~/.bashrc
if [ -f /etc/bashrc ]; then
. /etc/bashrc
Fi
76 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
shell
shell,
85 bash shell
bash $RANDOM 0-32767
$ echo $RANDOM
22543
$ echo $RANDOM
25387
$ echo $RANDOM
647
86
set -xv
$ cat filesize.sh
#!/bin/bash
for filesize in $(ls -l . | grep "^-" | awk {print
$5})
do
let totalsize=$totalsize+$filesize
done
echo "Total file size in current directory: $totalsize"
77 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
$ ./filesize.sh
Total file size in current directory: 652
set -xv
$ cat filesize.sh
#!/bin/bash
set -xv
for filesize in $(ls -l . | grep "^-" | awk {print
$5})
do
let totalsize=$totalsize+$filesize
done
echo "Total file size in current directory: $totalsize"
$ ./fs.sh
++ ls -l .
++ grep ^-
++ awk {print $5}
+ for filesize in $(ls -l . | grep "^-" | awk
\{print $5}\)
+ let totalsize=+178
+ for filesize in $(ls -l . | grep "^-" | awk
\{print $5}\)
+ let totalsize=178+285
+ for filesize in $(ls -l . | grep "^-" | awk
\{print $5}\)
+ let totalsize=463+189
+ echo Total file size in current directory: 652
Total file size in current directory: 652
set -xv,
87Quoting
echo
78 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
bash The
Geek echo Stuff Linux command
not found
$HOSTNAME
$HOSTNAME Linux
o $
o ` Backquotes
o \$
o \
o \"
o \\
79 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
88 shell
shell field
employees.txt {employee-name}:{employee-id}:{department-name}
$ cat employees.txt
Emma Thomas:100:Marketing
Alex Jason:200:Sales
Madison Randy:300:Product Development
Sanjay Gupta:400:Support
Nisha Singh:500:Sales
$ vi read-employees.sh
#!/bin/bash
IFS=:
echo "Employee Names:"
echo "---------------"
while read name empid dept
do
echo "$name is part of $dept department"
done < ~/employees.txt
$ ./read-employees.sh
Employee Names:
---------------
Emma Thomas is part of Marketing department
Alex Jason is part of Sales department
Madison Randy is part of Product Development department
Sanjay Gupta is part of Support department
Nisha Singh is part of Sales department
80 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
89free
free RAM
: free []
RAM
1GB KB
# free
total used free shared buffers cached
Mem: 1034624 1006696 27928 0 174136 615892
-/+ buffers/cache: 216668 817956
Swap: 2031608 0 2031608
RAM
o m MB
o t Total
o o buffers/cache
90top
top CPU
: top []
CPU
81 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
top Contorl+c q
top
# top
top - 13:10:13 up 171 days, 20:21, 3 users, load average: 0.01, 0.05, 0.00
top
o top 171
o Tasks
o CpusCPUCPU 98.7%
o Memswapfree
o CPUCPU
top top
top F n
Enter
top CPU
82 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
top f l CPU
top c
/usr/local/apache2/bin/httpd httpd
top CPU
top 1 1, CPU
top - 13:10:13 up 171 days, 20:21, 3 users, load average: 0.01, 0.05, 0.00
Tasks: 194 total, 1 running, 193 sleeping, 0 stopped, 0 zombie
Cpu0 : 10.2% us, 2.6% sy, 0.0% ni, 86.8% id, 0.3% wa, 0.0% hi, 0.0% si
Cpu1 : 9.6% us, 8.0% sy, 0.0% ni, 82.4% id, 0.0% wa, 0.0% hi, 0.0% si
Cpu2 : 1.3% us, 1.3% sy, 0.0% ni, 95.0% id, 2.3% wa, 0.0% hi, 0.0% si
Cpu3 : 0.0% us, 0.0% sy, 0.0% ni, 100.0% id, 0.0% wa, 0.0% hi, 0.0% si
Mem: 1034624k total, 1007420k used, 27204k free, 174540k buffers
Swap: 2031608k total, 0k used, 2031608k free, 615904k cached
91ps
ps
: ps []
"ps aux"
# ps aux | more
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 2044 588 ? Ss Jun27
83 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
ps axuf ps ejH
# ps axuf
root Oct14 0:00 /opt/VRTSralus/bin/beremote
root Oct14 0:00 \_ /opt/VRTSralus/bin/beremote
root Oct14 0:00 \_ /opt/VRTSralus/bin/beremote
root Oct14 0:00 \_ /opt/VRTSralus/bin/beremote
root Oct14 0:01 \_ /opt/VRTSralus/bin/beremote
root Oct 14 0:00 \_ /opt/VRTSralus/bin/beremote
root Dec03 0:01 /usr/local/sbin/sshd
root Dec22 1:08 /usr/local/sbin/sshd
root 23:35 0:00 \_ /usr/local/sbin/sshd
511 23:35 0:00 \_ -bash
511 \_ ps axuf
[ pstree ]
linux oracle
$ ps U oracle
PID TTY STAT TIME COMMAND
5014 ? Ss 0:01 /oracle/bin/tnslsnr
7124 ? Ss 0:00 ora_q002_med
8206 ? Ss 0:00 ora_cjq0_med
8852 ? Ss 0:01 ora_pmon_med
8854 ? Ss 0:00 ora_psp0_med
8911 ? Ss 0:02 oraclemed (LOCAL=NO)
84 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
$ ps U $USER
PID TTY STAT TIME COMMAND
10329 ? S 0:00 sshd: ramesh@pts/1,pts/2
10330 pts/1 Ss 0:00 -bash
10354 pts/2 Ss+ 0:00 -bash
10530 pts/1 R+ 0:00 ps U ramesh
92df
df
: df [] []
GB ?
df h h
K Kb,M Mb G Gb
/ 17GB /home/user 70GB
# df h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 64G 44G 17G 73% /
/dev/sdb1 137G 67G 70G 49% /home/user
T //hone/user ext2
a 0
# df -Tha
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext2 64G 44G 17G 73% /
/dev/sdb1 ext2 137G 67G 70G 49% /home/user
none proc 0 0 0 - /proc
none sysfs 0 0 0 - /sys
none devpts 0 0 0 - /dev/pts
none tmpfs 2.0G 0 2.0G 0% /dev/shm
93kill
kill
85 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
: kill [] [ ID ]
ps id id kill
apache httpd
apachectl stop apache
SIGTERM
9 SIGKILL
function psgrep ()
{
ps aux | grep "$1" | grep -v grep
}
function psterm ()
{
[ ${#} -eq 0 ] && echo "usage: $FUNCNAME STRING" && return 0
local pid
pid=$(ps ax | grep "$1" | grep -v grep | awk { print $1 })
echo -e "terminating $1 / process(es):\n$pid"
kill -SIGTERM $pid
}
httpd
# psgrep http
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME
COMMAND
apache 31186 0.0 1.6 23736 17556 ? S
Jul26 0:40 /usr/local/apache2/bin/httpd
apache 31187 0.0 1.3 20640 14444 ? S
Jul26 0:37 /usr/local/apache2/bin/httpd
86 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
# psterm httpd
terminating httpd / process(es):
31186
31187
94du
du
s /home/jsmith
/home/jsmith h K KB,M
MB G GB du -sh /home/jsmith
# du -sh ~
320M /home/jsmith
/home/jsmith s
95lsof
lsof lsof
o COMMAND .
o PID ID
o USER
o FD
o TYPE
o DEVICE
o SIZE
o NODE
o NAME
lsof
# lsof | more
COMMAND PID USER
87 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
lsof
# lsof | wc -l
3093
lsof -u
# lsof u ramesh
vi 7190 ramesh txt REG 8,1 474608
475196 /bin/vi
sshd 7163 ramesh 3u IPv6 15088263
TCP dev-db:ssh->abc-12-12-12-12.socal.res.rr.com:2631
(ESTABLISHED)
lsof
vi
# lsof /bin/vi
88 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
96sar
Sar sysstat sysstat Sar,
Sysstat project
Sar CPUIO
Sar
Sadc
/usr/lib/sadc
/va/log/sa/sa[dd]dd
Sa1 shell
/usr/lib/sa1 /usr/lib/sadcs sa1 crontab 5
15 crontab 5
Sa2 shell
/usr/lib/sa2 /var/log/sa/sa[dd]dd
crontab sa2
# 59 23 * * * root /usr/lib/sa/sa2 A
[/etc/cron.d/sysstat sa1 sa2 sysstat
]
Sar CPU
# sar u
89 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
Skipped..
Average: all 4.56 0.00 1.00 0.15 94.29
[ CPU ]
# sar -u -P ALL
Sar IO
# sar d
Sar
90 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
97vmstat
vmstat
IO CPU
vmstat 100 .
# vmstat 1 100
Vmstat procs
o r
o b
Memory
o Swpd
o FreeRAM
o BuffRAM
o CachecacheRAM
Swap
o Si
o So
IO
o Bi
o Bo
System
o In
o Cs
CPU
o Us
o Sy
o Id
o WaIO
91 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
98netstat
netstat
netstat
netstat
# netstat an
ID
# netstat tap
92 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
tcp 34 0 localhost.localdomain:54221
localhost.localdomain:4089 CLOSE_WAIT 29881/httpd
tcp 0 3216 dev-db:ssh cpe-76-
94-215-154.soca:4682 ESTABLISHED 11717/sshd: ramesh
# netstat tap
RAW
# netstat --statistics --raw
Ip:
11080343 total packets received
0 forwarded
1 with unknown protocol
0 incoming packets discarded
11037744 incoming packets delivered
11199763 requests sent out
Icmp:
577135 ICMP messages received
64 input ICMP message failed.
ICMP input histogram:
destination unreachable: 537
timeout in transit: 65
source quenches: 2
echo requests: 576476
echo replies: 12
timestamp request: 3
address mask request: 3
581558 ICMP messages sent
93 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
Netstat
99sysctl
Liunx sysctl
sysctl Linux
# sysctl a
dev.cdrom.autoclose = 1
fs.quota.writes = 0
kernel.ctrl-alt-del = 0
kernel.domainname = (none)
kernel.exec-shield = 1
net.core.somaxconn = 128
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_wmem = 4096 16384
net.ipv6.route.mtu_expires = 600
sunrpc.udp_slot_table_entries = 16
vm.block_dump = 0
/etc/sysctl.conf
/etc/sysctl.conf sysctl p
# vi /etc/sysctl.conf
# sysctl p
94 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
# sysctl w {variable-name=value}
100nice
nice nice -20 20
-20 nice nice 20
ps axl nice
# ps axl
F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY
TIME COMMAND
4 0 1 0 16 0 2172 552 - S ?
0:17 init [5]
1 0 3 1 34 19 0 0 ksofti SN ?
3:18 [ksoftirqd/0]
1 0 10 1 5 -10 0 0 worker S< ?
0:01 [events/0]
4 0 5145 1 25 10 32124 18592 - SNs ?
0:08 /usr/bin/python /usr/bin/rhn-applet-gui --sm-client-id
default4
4 0 5147 5142 16 0 3528 604 - S ?
0:00 /sbin/pam_timestamp_check -d root
1 503 17552 4180 16 0 14208 3920 - S ?
0:01 /home/www/apache2/bin/httpd -f
/home/www/apache2/conf/httpd.conf -k start
shell nice
nice-test.sh nice 0
$ ./nice-test.sh &
[3] 13009
$ ps axl | grep nice-test
0 509 13009 12863 17 0 4652 972 wait S
pts/1 0:00 /bin/bash ./nice-test.sh
0 nice
nice
95 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
shell nice
101renice
renice
nice
nice renice
$ renice 16 -p 13245
13245: old priority 10, new priority 16
$ ps axl | grep nice-test
96 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
nice ?
nice root
$ renice 5 -p 13254
renice: 13254: setpriority: Permission denied
Login as root to increase the priority of a running
process
$ su -
# renice 5 -p 13254
13254: old priority 10, new priority 5
# ps axl | grep nice-test
0 509 13254 13216 25 5 4412 968 wait SN
pts/1 0:00 /bin/bash ./nice-test.sh
6 nice 5
97 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
1 cd
cd m
# cd m<tab><tab>
may myticket
[ m tab ]
cd M
# cd M<tab><tab>
March Music
bind
cd m tab m
# cd m<tab><tab>
98 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
2 SSH
SSH ControlMaster ssh
SSH
~/.ssh/config
$ vi ~/.ssh/config
Host *
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p
Host *
ControlPath ~/.ssh/master-%r@%h:%p
o %p port
SSH
sshscp sftp
ssh
~/.ssh/config
Host 192.168.1.?
Host *.com
ControlPath ~/.mysecretfiles/master-%r@%h:%p
ControlMaster
o ControlMaster auto
99 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
o ControlMaster autoask
yes
3rar
rar
100 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
unrar rar
# unrar e var-log-cups.rar
rar
# unrar l var-log-cups.rar
Archive var-log-cups.rar
.....
101 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
4 Comm
Comm
o name_list.txt
o name_list _new.txt
$ cat name_list.txt
Bram Moolenaar
Ken Thompson
Linus Torvalds
$ cat name_list_new.txt
Bram Moolenaar
Dennis Ritchie
Richard Stallman
5Compact-Disk (CD)
CD
102 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
CD
: --speed=1
CD
6DVD
DVD
103 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
DVD
DVD
ISO
iso
:
-M to merge a new session
Final argument indicates the files to be appended.
104 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
7 CD DVD ISO
CD DVD isoinfo
: isoinfo -d -i DEVICE-Of-CD-DVD
# isoinfo -d -i /dev/cdrom
dd CD DVD ISO
1825+0 records in
1825+0 records out
3737600 bytes (3.7 MB) copied, 4.43782 seconds,
842 kB/s
105 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
8OD
od
OD
$ cat sample-file.txt
abc de
f h
b c
o -b -t oC ,
o -c -t c , ASCII
# od -c special-chars.txt
0000000 a b c \t d e \n f
\t h
0000020 \n
0000021
# od -bc special-chars.txt
0000000 141 142 143 040 011 144 145 012 146 040 040 040
040 040 011 150
a b c \t d e \n f
\t h
0000020 012
\n
0000021
OD
16 ASC II
106 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
# od -N16 -c /usr/bin/h2xs
0000000 # ! / u s r / b i n / p
e r l \n
0000020
16
# od -N16 -a /usr/bin/h2xs
0000000 # ! / u s r / b i n / p
e r l nl
0000020
16
0000000 043 041 057 165 163 162 057 142 151 156 057 160
145 162 154 012
# ! / u s r / b i n / p
e r l \n
0000020
9Gpg
gpg
GPG
# gpg --gen-key
gpg --gen-key
gpg (GnuPG) 1.4.9; Copyright (C) 2008 Free
Software Foundation, Inc.
107 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
Your selection?
DSA keypair will have 1024 bits.
ELG-E keys may be between 1024 and 4096 bits long.
108 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
Enter passphrase:
Repeat passphrase:
.+++++++++++++++++++++++++.+++++++++++++++++++++++
# file ramesh-pub.gpg
ramesh-pub.gpg: GPG key public ring
109 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
import
John Bob
John Bob
Bob John
Enter passphrase:
[]
110 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
GPG
GPG
# gpg --list-keys
/home/ramesh/.gnupg/pubring.gpg
--------------------------------
pub 1024D/90130E51 2010-01-02
uid ramesh (testing demo key)
<ramesh.thegeekstuff@gmail.com>
sub 2048g/35C5BCDB 2010-01-02
# gpg --list-secret-keys
/home/ramesh/.gnupg/secring.gpg
--------------------------------
sec 1024D/90130E51 2010-01-02
uid ramesh (testing demo key)
<ramesh.thegeekstuff@gmail.com>
ssb 2048g/35C5BCDB 2010-01-02
10Tee
Tee
Tee
$ ls
111 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
$ ls > file
tee
file
$ ls | tee file
tee
tee
tee a tee
$ ls | tee a file
112 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
12 Linux
Linux 12
Linux Linux 12
Linux
Vi Vim Linux
CVi
VivimVim
3. Bash Cookbook
HU Carl Albing, JP Vossen and Cameron Newham
U
shell
shellshell
4. SSH,The Secure Shell Daniel J. Barrett, Richard E. Silverman and Robert G
HU U
ByrnesSSHSSH
SSHSSH
SSH
(SHH1,SHH2OpenSSH)SSH
5. Essential System Administrator leen FrischUNIX
HU UH
AIX,FreeBSD,
HP-UXLinux,Solaris Tru64UNIXUNIX
UNIX----Essential
System Administration Pocket Reference
6. Linux Server Hacks Rob Flickenger100
HU UH
Linux
SSHLinux Server
HacksWillian von Hagen Brian Jones
100,,,
7. DNS and BIND Cricket Liu Paul Albitz
HU UHU
113 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
RPMDebian
RedHatDaniel J. BarrettLinuxthe Linux
Pocker Guide
10. Linux Firewalls Michael RashLinux
HU UH
psad, fwsnort
Gregory N. Purdy
Linux Iptables Pocket Reference
11. Linux Administration Handbook Evi Nemeth Garth Snydet Trent R. Hein
HU UH
Basic Administration Networking Bunch OStuff 100030
12. Beginning Ubuntu Linux Keir Thomas Jaime SicamWindows
HU UH
LinuxUbuntu
LinuxLinuxLinux
Ubuntu
114 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
o SSHSCP:
o From openSSH to openSSH
HU U
o Midnight Commander (mc) Guide: Powerful Text based File Manager for
HU
Unix UH
115 www.thegeekstuff.com
Linux 101 Hacks linux.101hacks.com
Linux
LINUX The Geek Stuff blog
http://www.thegeekstuff.com/subscribe/ TGS
RSS
http://linux.101hacks.com/toc
http://www.thegeekstuff.com/contact/
116 www.thegeekstuff.com