http://10.1.1.35/ule_basic/ule07.txt

--


linux 的打包,压缩,解压


压缩使文件更小,有利于网络传输,在传输大量小文件时,最好是打包压缩,速度较快


windows 下 winrar .rar
winzip .zip


linux下的压缩命令:

.Z compress --淘汰了,现在极少见到
.gz gzip压缩的
.bz2 bzip2压缩的
.tar tar打包
.tar.gz tar,gzip
.tar.bz2 tar,bzip2





--compress 老的压缩工具

[root@li ~]# yum list|grep compress
This system is not registered with RHN.
RHN support will be disabled.
ncompress.i386 4.2.4-47 Server

[root@li ~]# yum install ncompress --装这个包使用compress命令

compress grub.conf --直接压缩文件,源文件没了
compress -d grub.conf.Z --解压
compress -c grub.conf > grub.conf.Z --这样压缩并保留源文件


--gzip 使用广泛,用来替代compress,它能解压.Z .gz .zip 等格式的压缩包
gzip grub.conf --压缩
zcat grub.conf.gz --查看压缩包的内容
gzip -d grub.conf.gz --解压
gzip -c grub.conf > grub.conf.gz --压缩并保留源文件
gzip -d grub.conf.Z

unzip Discuz_6.1.0_SC_GBK.zip -d /root/Desktop/ --.zip结尾的包用unzip来解压,-d参数指定解压的位置


--bzip2 它用来替代gzip,拥有更好的压缩比率
bzip2 grub.conf --压缩
bzcat grub.conf.bz2 --查看压缩包的内容
bzip2 -d grub.conf.bz2 --解压
bzip2 -c grub.conf > grub.conf.bz2 --压缩并保留源文件

[root@li test]# ll
-rw------- 1 root root 810 Apr 24 09:53 grub.conf
-rw-r--r-- 1 root root 560 Apr 24 10:04 grub.conf.bz2
-rw-r--r-- 1 root root 493 Apr 24 09:59 grub.conf.gz
-rw-r--r-- 1 root root 614 Apr 24 09:55 grub.conf.Z



--rar
/share/soft/soft/rarlinux-3.7.1.tar.zip --这个包是经过三层处理的,先tar,再gz,再zip过,所以解压也要先unzip,再tar xvf
unzip /share/soft/soft/rarlinux-3.7.1.tar.zip -d /usr/src/
cd /usr/src/
tar xvf rarlinux-3.7.1.tar.gz
cd /usr/src/rar
make --此包直接make就可以了,有makefile文件,表示是已经./configure好的

有rar命令就表示安装完毕

此命令是没有man page,因为没有安装man的帮助文件,可以用rar -h 或者rar --help来看

rar a etc.tar.rar etc.tar --压缩
rar e etc.tar.rar --解压



--tar
-c 打包
-v 显示过程
-f 接文件
-j 调用bzip2进行压缩或者解压
-z 调用gzip进行压缩或者解压
-C 解压时指定解压的路径
-t 查看包内容
-x 解压

tar cvf etc.tar etc/ --打包 ,注意源和目地的位置
tar xvf etc.tar --解压,默认解到当前路径下
tar xvf etc.tar -C /usr/src/ --用-C参数指定解压的路径,注意是大写字母C

tar cjvf etc.tar.bz2 etc/ --打包,并用bzip2压缩
tar xjvf etc.tar.bz2 --对应的解压
tar czvf etc.tar.gz etc/ --打包,并用gzip压缩
tar xzvf etc.tar.gz --对应的解压

W能解压参数
tar xvf etc.tar.gz --自动会调用压缩工具解压


[root@li test]# ll
total 116320
drwxr-xr-x 106 root root 12288 Apr 24 09:52 etc
-rw-r--r-- 1 root root 100280320 Apr 24 10:11 etc.tar
-rw-r--r-- 1 root root 7427569 Apr 24 10:17 etc.tar.bz2
-rw-r--r-- 1 root root 11238367 Apr 24 10:18 etc.tar.gz
-rw------- 1 root root 810 Apr 24 09:53 grub.conf
-rw-r--r-- 1 root root 560 Apr 24 10:04 grub.conf.bz2
-rw-r--r-- 1 root root 493 Apr 24 09:59 grub.conf.gz
-rw-r--r-- 1 root root 614 Apr 24 09:55 grub.conf.Z


注意:
--这里可以看出来bzip2比gzip有更好的压缩比率, 但在压缩一个小文件时,反而没有gzip压得小
--压缩目录是把目录里的每个文件都压缩,所有一般没有这种做法,正确的做法是把目录用tar打包,再用gzip或者bzip2压缩



tar的特殊应用:

tar tvf etc.tar |grep fstab --查看压缩包的内容 用-t参数
tar xvf etc.tar etc/fstab --指定解压单一文件
tar cvf etc.3.tar etc/ --exclude=etc/fstab 排除某些文件不打包
tar cvf etc.5.tar etc/ --exclude=etc/fstab --exclude=etc/inittab 排除多个文件
tar cvf etc.6.tar etc/ --exclude=etc/*.conf 支持通配符,排除有相似度的一批文件


tar cvf - etc/ |tar xvf - -C /root/Desktop/ --使用管道来执行一些特殊操作









--######################################################################################


job管理
linux下有前台和后台的概念,每个bash终端都可以运行自己的job,注意不能跨bash终端管理

& --后台运行符号,运行的程序不会占用你的终端

[root@li test]# firefox &
[1] 6003 --1代表job号,6003代表的就是pid(process identification)


[root@li test]# vim /etc/passwd --在这里按下ctrl+z键,作用是把job暂停到后台

[2]+ Stopped vim /etc/passwd


[root@li test]# vim /etc/shadow --再按ctrl+z放到后台,与ctrl+c(中断)不同

[3]+ Stopped vim /etc/shadow

[root@li test]# jobs --列出后台job列表,别的终端看不到的
[1] Running firefox &
[2]- Stopped vim /etc/passwd
[3]+ Stopped vim /etc/shadow

jobs -l --还要列出pid号
jobs -s --只列出暂停的jobs
jobs -r --只列出运行的jobs

[root@li test]# fg %1 --把一号job的firefox 调到前台
firefox



[root@li test]# jobs -l
[1]+ 6003 Stopped firefox
[2] 6036 Stopped vim /etc/passwd
[3]- 6074 Stopped vim /etc/shadow


[root@li test]# bg %1 --把-号job的firefox由stop状态放到后台执行,就是变为running状态
[1]+ firefox &
[root@li test]# jobs -l
[1] 6003 Running firefox &
[2]- 6036 Stopped vim /etc/passwd
[3]+ 6074 Stopped vim /etc/shadow

[root@li ~]# tar cvf root.tar / & --注意不要在这里加v参数,它是standard out,就算是加了后台符号,也会一直占用前台终端输出打包的信息

[root@li ~]# tar cf root.tar / & --可以不加v参数来放到后台执行

[root@li ~]# tar cvf root.tar / > /root/tarroot.log 2>&1 & --可以达到放到后台运行,并把打包的日志给保存下来

watch -n3 tail /root/tarroot.log --边后台打包,可以这样去查看日志的写入状态

[root@li /]# kill -9 %1 --杀掉一号job,或者用pid杀也可以




---------------------------
退出继续挂起

在运行的脚本或者命令前加nohup ,退出用户后继续挂起









--#####################################################################################



文件查找


which whereis locate find



--which
[root@li ~]# which ifconfig --查找二进制可执行文件,通过环境变量来查找
/sbin/ifconfig

[a@li ~]$ which ifconifg --普通用户环境变量没有/sbin/这个路径,所以which找不到
/usr/bin/which: no ifconifg in (/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/a/bin)

--whereis
[root@li ~]# whereis ifconfig
ifconfig: /sbin/ifconfig /usr/share/man/man8/ifconfig.8.gz

[a@li ~]$ whereis ifconfig
ifconfig: /sbin/ifconfig /usr/share/man/man8/ifconfig.8.gz


--locate
速度快,通过系统带的一个数据库去查找
[root@li ~]# ls /var/lib/mlocate/
mlocate.db

[root@li ~]# touch abcd777 --新建一个文件
[root@li ~]# locate abcd777 --locate查找不出来


[root@li ~]# updatedb --手动更新locate数据库,时间比较长,但是系统的时间任务服务会在晚上4点帮你去更新

[root@li ~]# locate abcd777 --更新locate数据库后,再查找就有了
/root/abcd777


--find
速度慢,因为要扫你的磁盘,功能强大
find 路径 [选项]
-name --通过名字找
-type --通过文件类型找

-uid --通过uid查找
-gid --通过gid查找
-user --通过username查找
-group --通过groupname查找

-perm --通过权限查找
+n --n包含的权限也查找出来
-n --包含n的权限也查找出来
-size --通过大小查找
+n --查出大于n的文件
-n --查出小于n的文件


1,按名称查找
find /etc/ -name grub.conf --查找/etc目录下的grub.conf文件
find /etc/ -name "*.conf" --使用通配符,查找/etc/目录下的以.conf结尾的文件
find /test/ -iname Aaa --忽略大小写加上-i
/test/aaa
/test/Aaa
/test/AAa
--定义查找的目录层次
[root@li a]# find /test/ -maxdepth 1 -name aaa
/test/aaa
[root@li a]# find /test/ -maxdepth 2 -name aaa
/test/aaa
/test/a/aaa


2,按类型查找
find /etc -type l |grep grub.conf
find /etc -type l -name grub.conf --与-name参数一起写

find / -type b
find / -type s
find / -type c
find / -type p


3,按用户名,组名,uid,gid查找
find / -user a
find / -group a
find / -uid 533
find / -gid 533
find / -nouser --查出系统的无头文件,就是指没有属主的文件
find / -nogroup --查出系统的没有属组的文件
没有属主和属组的文件,系统管理一般是要去注意的


4,按权限查找
find / -perm 777 --查出所有权限为777的文件,一般也是管理员要注意的
find . -perm +111
find . -perm -777


5,按大小查找

find / -size +500M --单位有k,m,g等
find / -size +1G
find /etc -size +50k
find /etc -size +50b
find / -size -1M

6,按时间查找

[root@li a]# stat 1
File: `1'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 808h/2056d Inode: 12177882 Links: 1
Access: (0777/-rwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2010-04-24 14:44:00.000000000 +0800 --atime 阅读过,用cat,tail,head命令等或者vi访问过,但没有修改;执行过也会改变
Modify: 2010-04-24 14:44:00.000000000 +0800 --mtime 修改过内容,用vi修改过或者echo一个值重定向
Change: 2010-04-24 14:44:14.000000000 +0800 --ctime 改变过内容,属主,属组,权限,创建软链接,硬链接等

-mtime n --代表n天前的24小时内
+n --代表n天前(不包含n天本身的24小时)
-n --代表n天内


1 2 3 4 5 6 7
|-- 2 --|
<------- -2 | | +2 --------------->

find / -mtime 0 --0代表目前当天的24小时
find / -mite +1 --修改时间1天之前
find . -mtime -1 --修改时间在一天之内


ctime atime 用法与mtime一样



find . -newer 1 --查找比1文件新的


-----------------------------
find后接-exec动作
-exec

find /etc/ -name "*.conf" -exec cp {} /test/a /;
find /etc/ -name grub -exec cat {} /;
-- -exec后面接动作, {}代表前面的结果集 /; 代表结束





--####################################################################################


Xwindows图形桌面 -->X协议 --> tcp/ip


mit (麻省理工) X windows
X11
xfree86计划
xorg组织接手,并发展成现在的x11 V7

gnome kde twm (最简单的桌面) --都属于xwindows client


xwindows 也是一种C/S架构 (server/client)
x server --驱动硬件,鼠标,键盘,显示器等
x client --接收server来的信号,进行程序处理,回传给server端进行像素的移动,绘图等

[root@li a]# w
15:54:47 up 6:35, 4 users, load average: 0.04, 0.06, 0.06
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root :0 - 09:21 ?xdm? 10:59 0.12s /usr/bin/gnome-session



例子一:
开机自动启动图形
/etc/X11/xinit/xinitrc.d/ --写上开机启动图形后自动启动的图形程序

vim /etc/X11/xinit/xinitrc.d/firefox.sh
#!/bin/bash
/usr/bin/firefox & --开机后会自动运行firefox



例子二:
远程调图形
ssh 10.1.1.104 -X firefox
ssh 10.1.1.104 -Y


[root@li a]# su - a
[a@li ~]$ firefox --普通用户不能运行图形
Xlib: connection to ":0.0" refused by server
Xlib: No protocol specified

Error: cannot open display: :0.0


xhost + --让所有普通用户可以调用图形
xhost + IP
x clinet: xhost + server_ip
x server: DISPLAY=client_ip:0 xeyes &



--跟图形有关的错误


开机时启动图形时间极慢, 一般是主机对应不好
检查一下

[root@li a]# hostname
li.cluster.com
[root@li a]# vim /etc/hosts
[root@li a]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=li.cluster.com


或者再尝试一下 rm /root/.gnome/ -rf
rm /root/.gnome2/ -rf
ls /tmp/ |grep root --把找到的全rm掉

全删除掉后,再重起X windows,会按默认配置重新建立


图形启不来还要注意的是 /tmp目录的权限
stat /tmp
(1777/drwxrwxrwt)


system-config-display 图形配置 桌面




---------------------------------------------------


VNC (虚拟网络计算)virtual network computing
AT&T实验室最早开发的

属于一种远程控制软件

主要分vncserver vncviewer

[root@li a]# yum list |grep vnc
This system is not registered with RHN.
RHN support will be disabled.
vnc.i386 4.1.2-14.el5_3.1 installed --客户端
vnc-server.i386 4.1.2-14.el5_3.1 installed --服务端


[root@li a]# vncserver

New 'li.cluster.com:1 (root)' desktop is li.cluster.com:1

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/li.cluster.com:1.log

[root@li a]# vncpasswd --建立vnc密码
Password:
Password must be at least 6 characters - try again
Password:
Verify:


/root/.vnc/ --配置目录

vim /root/.vnc/xstartup --要显示gnome-session 就把下面两句打开,再把别的都给注释掉
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc

#[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
#[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
#xsetroot -solid grey
#vncconfig -iconic &
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#twm &


访问方法
vncviewer 10.1.1.35:1

vncviewer -Viewonly -Shared 10.1.1.35:3


[root@li a]# ls /root/.vnc/
li.cluster.com:1.log li.cluster.com:2.log li.cluster.com:3.log passwd
li.cluster.com:1.pid li.cluster.com:2.pid li.cluster.com:3.pid xstartup

[root@li a]# vncserver -kill :1
Killing Xvnc process ID 11889

[root@li a]# ls /root/.vnc/
li.cluster.com:1.log li.cluster.com:2.pid li.cluster.com:3.pid xstartup
li.cluster.com:2.log li.cluster.com:3.log passwd

[root@li a]# netstat -ntl |grep 58
tcp 0 0 0.0.0.0:5802 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:5803 0.0.0.0:* LISTEN



vnc的端口是5801开始和5901开始
5800+n 是给浏览器用的 5900+n 是给vncviewer用的

http://10.1.1.35:5802/ --用浏览器访问

但linux下的firefox浏览器是要装一个java插件




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值