注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

WA!Peter

广州天河, 香港火炭,深圳罗湖, 北京国贸

 
 
 

日志

 
 

Linux Unix command  

2010-05-13 11:26:37|  分类: server |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
non-root user mode, avoid permission denied error message (2> means forward stderr)
用户模式, 会出现很多 Permission denied, 用 2>/dev/null 可以把错误信息删掉
find / -name resin.conf 2>/dev/null

以前的记录:
#!/bin/bash
x=1
while [ $x -le 5 ]
do
echo "Count $x"
x=$(( $x + 1))
done



## realtek network card related
rmmod r8169
insmod ./src/r8169.ko speed=100 duplex=0 autoneg=0
ethtool -s eth0 speed 100 duplex full autoneg on

smartctl -a /dev/sda show SMART info of harddisk (serial number)

psnup -n in.ps out.ps n=no. of page, to print n page in a single paper
dvips dvi format -> ps format
latex in.tex LaTeX formatting a doc.
cut -f[n] -d [delimiter] [filename]
cut is used to cut out some field from a line
Note: delimiter = separator
e.g. input = "hello,boy,good"
with cut -f2 -d ,
output = "boy"
with cut -f1 -d ,
output = "hello"
with cut -f2- -d ,
output = "boy,good"
with cut -f-2 -d ,
output = "hello,boy"
echo "hello,boy,good" | cut -f2 -d ,

indent -bli0 -i4 source.c Format a C source code (only in Linux)
indent -bli0 -i8 source.c This one avoid the use of tabs...
:1,$s/PATTERN/REPLACE/g vi global replace (1,$ = whole document)
vi settings in bash:
export EXINIT='se ai|se sw=4|se sts=4|se wm=5|se expandtab'
crontab -e edit the cron job table file

grep -v "pattern" file.txt > out.txt
take out all lines contains "pattern", -v means reverse match

find ./ -type d find all directories under the current dir.

## find all *.java, compile it
find ./ -name "*.java" -print -exec javac {} \;

## find all *.class, remove it, take care...
find ./ -name "*.class" -print -exec rm {} \;


## find all files which [last modified time] is older than 20 days (+) : remove it
find ./ -mtime +20 -print -exec rm {} \;

## find all files which [last modified time] is within 20 days, print it! (no +)
find ./ -mtime 20 -print

## find all directories and print out
find ./ -type d -exec echo The dir:{} \;

## find all directories, chmod all executable
find ./ -type d -print -exec chmod a+rx {} \;

#### find all files, chmod all readable a+r, remove -print if too much
find ./ -type f -print -exec chmod a+r {} \;

#### find all *.create.sql, run mysql to do init
find ./ -name "*.create.sql" -print -exec mysql -uyazimi -p1005 yazimi \< {} \;

#### find all files which is large than 5000K (5M) list them by ls -l
find ./ -size +5000k -exec ls -l {} \;


## if file exists case:
if [ -e filename ]; then
echo "hello"
fi
## if filename NOT exists, hello will be printed.
if [ ! -e o.txt ]; then
echo "hello"
fi

POP3 pop3 port 110 example:-) 
Note: type the line with >
> telnet your.pop.host.com 110
+OK POP3 your.pop.host.com v2001.78 server ready
> user your_username
+OK User name accepted, password please
> pass your_password
+OK Mailbox open, 23 messages


IMAP imap port 143 example:-)
Note: type the line with >
> telnet your.imap.host.com 143
* OK [CAPABILITY IMAP4REV1...]
> 1 LOGIN "your_username" "your_password"
1 OK [CAPABILITY...] ... User your_username authenticated


SMTP smtp port 25 example :-)
Note: type the line with >
> telnet smtp.host.com 25
* 220 XX mailer
> HELO myhost.com
250 Hello
> MAIL FROM: my_name@myhost.com
250 my_name@myhost.com: Sender Ok (if not OK, check relay rules)
> RCPT TO: receiver@host.com
250 receiver@host.com: Recipient Ok
> DATA
354 Mailer: Send data now. Terminate with "."
> Subject: Testing email from me!
>
> Dear friend,
>
> This is a email sent from RAW SMTP, reply it if you can see!
>
> Cheers,
> Someone out there
> .
250 Mailer: Message accepted for delivery
> quit


nslookup example :-)
Note: read the "mail exchanger" address (resolve its IP help a lot!)
> set type=mx
> moffy.com
Server: ns1.xxx.com
Address: ppp.qqq.rrr.sss
moffy.com preference = 10, mail exchanger = mail.iilcorp.com
moffy.com nameserver = ns1.iilcorp.com
...


proftp config for change root style ftp server:
edit: /etc/proftpd.conf
## uncomment or add this line:
DefaultRoot ~

DOS (non-Unix) command:

nbtstat -A 192.168.1.22 -> read the computer name
netstat -na read the network port one by one


wc -l
- how many lines on the file
- 文件有多少行 (line numbers)
wc -w
- 文件有多少英文字


du -s *
- 列出每个目录的总大小, clean up 时候有用
配合 sort 来用:
du -s /home/* | sort -n
可以列出每个用户占多少位置, 由小到大排



-- setup smaller time_wait for better performance:
sysctl -w net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait=60


_vimrc :
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
set noincsearch " peter favorite, optional
"" gf path:
set path=.,../inc,C:\Symbian\8.1a\S60_2nd_FP3\Epoc32\include
set tags=tags;/ " for tags file
map :!ctags -R src


iptables (RH default firewall)
## turn on the incoming port 7749 (credit: Colin)
iptables -I RH-Firewall-1-INPUT 8 -p tcp --dport 7749 -j ACCEPT
/etc/init.d/iptables save

(dev)
iptables -I RH-Firewall-1-INPUT 8 -m state --state NEW -p tcp --dport 9996 -j ACCEPT


mysql root password change:
shell> mysql -uroot -pXXXX mysql
mysql> update user set Password=password('newpassword') where User='root';
mysql> flush privileges;



bash comparison operator
-a file
True if file exists.
-b file
True if file exists and is a block special file.
-c file
True if file exists and is a character special file.
-d file
True if file exists and is a directory.
-e file
True if file exists.
-f file
True if file exists and is a regular file.
-g file
True if file exists and its set-group-id bit is set.
-h file
True if file exists and is a symbolic link.
-k file
True if file exists and its "sticky" bit is set.
-p file
True if file exists and is a named pipe (FIFO).
-r file
True if file exists and is readable.
-s file
True if file exists and has a size greater than zero.
-t fd
True if file descriptor fd is open and refers to a terminal.
-u file
True if file exists and its set-user-id bit is set.
-w file
True if file exists and is writable.
-x file
True if file exists and is executable.
-O file
True if file exists and is owned by the effective user id.
-G file
True if file exists and is owned by the effective group id.
-L file
True if file exists and is a symbolic link.
-S file
True if file exists and is a socket.
-N file
True if file exists and has been modified since it was last read.
file1 -nt file2
True if file1 is newer (according to modification date) than file2.
file1 -ot file2
True if file1 is older than file2.
file1 -ef file2
True if file1 and file2 have the same device and inode numbers.
-o optname
True if shell option optname is enabled. The list of options appears in the description of the `-o' option to the set builtin (see section 4.3 The Set Builtin).
-z string
True if the length of string is zero.
-n string

string
True if the length of string is non-zero.
string1 == string2
True if the strings are equal. `=' may be used in place of `=='.
string1 != string2
True if the strings are not equal.
string1 < string2
True if string1 sorts before string2 lexicographically in the current locale.
string1 > string2
True if string1 sorts after string2 lexicographically in the current locale.
arg1 OP arg2
OP is one of `-eq', `-ne', `-lt', `-le', `-gt', or `-ge'. These arithmetic binary operators return true if arg1 is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to arg2, respectively. Arg1 and arg2 may be positive or negative integers.






  评论这张
 
阅读(364)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017