zhousir1991

让开源路人皆知~!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

tar压缩,vim,正则表达式,重定向,nc_telnet,host

Posted on 2011-08-02 18:05  zhousir1991  阅读(1073)  评论(1编辑  收藏  举报
gzip -z  压缩时默认把源文件删除 
bzip2  -j   以bz2形式压缩
gunzip      解压*.gz文件
gunbz2      解压*.bz2文件
[root@desktop26 Desktop]# tar cf data.tar data/         //先打包归档
[root@desktop26 Desktop]# bzip2  data.tar               //再压缩
[root@desktop26 ~]# gunzip data.tar.gz           //解压成data.tar
[root@desktop26 ~]# bunzip2 data.tar.bz2         //解压成data.tar
[root@desktop26 ~]# tar zxf etc.tar.gz -C /opt/    指定路径
[root@desktop26 ~]# tar rf data.tar /etc/        //追加归档的内容
[root@desktop26 ~]# tar zf etc.tar.gz --get etc/passwd       //提取 *.tar.gz中的某个单独文件
[root@desktop26 ~]# ls etc
passwd
[root@desktop26 ~]# tar f etc.tar --delete etc/passwd        //删除*.tar中的某个文件
[root@desktop26 ~]# tar tf etc.tar |less                     //结果是passwd文件不再tar包中了
vim:
命令模式: set nu  显示行数
终端页的最上面一行:  H
搜索替换: 冒号模式 :%s/bash/zhousir/g        //%s表示全文,把bash替换为zhousir
:22,30s/zhousir/bash/g    //这里的 /g 经过测试发现要不要都可以生效
Ctrl+W+S 横向分屏,Ctrl+W+V 纵向分屏
:sp /etc/passwd           //表示打开一个文件
[root@desktop26 ~]# gcc -o hello hello.c 
[root@desktop26 ~]# ./hello
[root@desktop26 ~]# gcc -g hello.c        
正则表达式:
[root@desktop26 ~]# cut /etc/passwd -d : -f 3|grep ^[0-9][0-9][0-9]$   //uid为三位数
113
170
499
107
496
500
501
[root@desktop26 ~]# grep :[0-9]..:[0-9] /etc/passwd
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
rtkit:x:499:499:RealtimeKit:/proc:/sbin/nologin
abrt:x:498:498::/etc/abrt:/sbin/nologin
saslauth:x:497:495:"Saslauthd user":/var/empty/saslauth:/sbin/nologin
qemu:x:107:107:qemu user:/:/sbin/nologin
pulse:x:496:494:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
student:x:500:500::/home/student:/bin/bash
visitor:x:501:501::/home/visitor:/bin/bash
[root@desktop26 ~]# grep ':/home/*:' passwd        //两个对比 * 与 .* 的区别,要与bash中的区分开
visitor:x:501:501::/home/:/bin/bash                
visitor:x:501:501::/home///:/bin/bash
visitor:x:501:501::/home///////:/bin/bash
[root@desktop26 ~]# grep ':/home/.*:' /etc/passwd
student:x:500:500::/home/student:/bin/bash
visitor:x:501:501::/home/visitor:/bin/bash
[root@desktop26 ~]# grep -v ^# /etc/vsftpd/vsftpd.conf   //实用性实例
anonymous_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
 >   只重定向正确的输出
2>   中重定向错误的输出
2>&1 将错误正确的组合(伪装错误) //放在语句最后
 &>  同上 //放在语句中间
[student@desktop26 Desktop]$ find /etc -name passwd > out 2>&1
[student@desktop26 Desktop]$ find /etc -name passwd &> out2     //这两个命令效果相同
[student@desktop26 Desktop]$ cat out 
find: `/etc/cups/ssl': Permission denied
find: `/etc/ntp/crypto': Permission denied
find: `/etc/audisp': Permission denied
find: `/etc/pki/CA/private': Permission denied
find: `/etc/polkit-1/localauthority': Permission denied
find: `/etc/audit': Permission denied
/etc/pam.d/passwd
find: `/etc/lvm': Permission denied
find: `/etc/libvirt': Permission denied
find: `/etc/selinux/targeted/modules/active': Permission denied
find: `/etc/dhcp': Permission denied
/etc/passwd
[student@desktop26 Desktop]$ find /etc -name passwd > out 2> out2 
[student@desktop26 Desktop]$ cat out                   //这个时将正确和错误分开输出
/etc/pam.d/passwd
/etc/passwd
[student@desktop26 Desktop]$ cat out2
find: `/etc/cups/ssl': Permission denied
find: `/etc/ntp/crypto': Permission denied
find: `/etc/audisp': Permission denied
find: `/etc/pki/CA/private': Permission denied
find: `/etc/polkit-1/localauthority': Permission denied
find: `/etc/audit': Permission denied
find: `/etc/lvm': Permission denied
find: `/etc/libvirt': Permission denied
find: `/etc/selinux/targeted/modules/active': Permission denied
find: `/etc/dhcp': Permission denied
首先nc一个端口:
[root@desktop26 ~]# nc -l 4567
再新开一个终端:
[student@desktop26 Desktop]$ telnet localhost 4567
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
[root@desktop26 ~]# vi /etc/nsswitch.conf              //编辑内部解析顺序
[root@desktop26 ~]# ll /etc/hosts
[root@desktop26 ~]# ll /etc/resolv.conf
[root@desktop26 ~]# ifconfig  
[root@desktop26 ~]# route -n 
[root@desktop26 ~]# ip route
[root@desktop26 ~]# ll /etc/sysconfig/network-scripts/ifcfg-*
[root@desktop26 ~]# host desktop26.example.com           //解析主机名
desktop26.example.com has address 192.168.0.26
[root@desktop26 ~]# host -l  example.com                 //列出一个网段的主机名
example.com name server instructor.example.com.
example.com has address 192.168.0.254
ad.example.com name server w2k3.ad.example.com.
w2k3.ad.example.com has address 172.16.0.10
node-0.cluster-1.example.com has address 172.16.50.10
demo.example.com has address 192.168.0.250
desktop1.example.com has address 192.168.0.1
desktop10.example.com has address 192.168.0.10