码迷,mamicode.com
首页 > 其他好文 > 详细

System-day3.md

时间:2018-05-21 16:17:40      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:mkdir   空行   哪些   mode   sim   文件夹   efi   sbin   cas   

System-Day3


//查看CPU信息
[root@final ~]# cat /proc/cpuinfo 
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 60
model name	: Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz
...
//查看内存信息
[root@final ~]# cat /proc/meminfo 
MemTotal:        1906492 kB
MemFree:         1478032 kB
Buffers:           94932 kB
Cached:           205616 kB
SwapCached:            0 kB
Active:           209344 kB
Inactive:          98712 kB
Active(anon):       7516 kB
//分页浏览
[root@final ~]# less /proc/cpuinfo

//查看开头2行
[root@final ~]# head -n 2 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
[root@final ~]# head -2 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
//查看末尾2行
[root@final ~]# tail -2 /etc/passwd
tcpdump:x:72:72::/:/sbin/nologin
admin:x:500:500:Centos66:/home/admin:/bin/bash
[root@final ~]# tail -n 2 /etc/passwd
tcpdump:x:72:72::/:/sbin/nologin
admin:x:500:500:Centos66:/home/admin:/bin/bash

//查看开头2行
[root@final ~]# ifconfig > ipadd.txt
[root@final ~]# head -2 ipadd.txt 
eth0      Link encap:Ethernet  HWaddr 00:0C:29:CC:3D:CF  
          inet addr:192.168.20.129  Bcast:192.168.20.255  Mask:255.255.255.0

常用的选项为:
-i:忽略大小写
-v:反转查找,输出不符合查找条件的行
-c:输出匹配结果的数量

常用的查找条件:
^...:表示以 ... 开头
...$:表示以 ... 结尾
^$:表示空行

//去掉ipadd.txt文件里的空行
[root@final ~]# grep -v ^$ ipadd.txt 
eth0      Link encap:Ethernet  HWaddr 00:0C:29:CC:3D:CF  
          inet addr:192.168.20.129  Bcast:192.168.20.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fecc:3dcf/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3296 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2916 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:313334 (305.9 KiB)  TX bytes:205234 (200.4 KiB)
eth1      Link encap:Ethernet  HWaddr 00:0C:29:CC:3D:D9  
          inet addr:192.168.10.130  Bcast:192.168.10.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fecc:3dd9/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:7400 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5375 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:635768 (620.8 KiB)  TX bytes:520631 (508.4 KiB)
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
         
//计算/bin目录下一共有多少个文件--不包括快捷方式
[root@final ~]# ls -l /bin/*|grep ^-|wc -l
93

//统计inittab文件中有效配置行数--排除#开头的行、空行
[root@final ~]# grep -v ^# /etc/inittab |grep -v ^$|wc -l
1

//zip压缩工具优点是可跨平台。
在使用时,它的命令格式需注意:
zip 压缩后文件名 源文件绝对路径
压缩式常用选项为“-r”,压缩目录时需加上,代表递归压缩。
解压时命令为unzip,常用选项为“-d”可以指定解压位置。

//制作zip包
[root@final opt]# zip test.zip /root/install*
  adding: root/install.log (deflated 77%)
  adding: root/install.log.syslog (deflated 86%)
  [root@final opt]# ls test.zip 
test.zip
//压缩/root与/etc目录
[root@final opt]# zip -r root_etc_back.zip /boot/ /etc/
[root@final opt]# ls 
root_etc_back.zip  test.zip

//解压zip包
[root@final opt]# unzip /opt/test.zip -d /tmp/
Archive:  /opt/test.zip
  inflating: /tmp/root/install.log   
  inflating: /tmp/root/install.log.syslog  
[root@final opt]# ls /tmp/
root

//tar命令的常用选项
-c:创建 .tar 格式的归档文件
-x:解开.tar格式的归档文件
-C:解包时指定释放的目标文件夹
-f:表示使用归档文件
-z:调用 gzip 执行压缩或解压缩
-j:调用 bzip2 执行压缩或解压缩
-v:输出详细信息
-t:列表查看包内的文件
tar命令的格式与zip命令格式有点相似:
tar -zcf 压缩后文件的名字 源文件绝对路径

//备份 /boot /etc这两个文件夹
[root@final opt]# tar -zcf /opt/boot_etc_back.tar.gz /boot/ /etc
tar: Removing leading `/‘ from member names
[root@final opt]# ll -h
total 101M
-rw-r--r--. 1 root root 38M Aug  9 09:40 boot_etc_back.tar.gz
-rw-r--r--. 1 root root 63M Aug  9 09:34 root_etc_back.zip
-rw-r--r--. 1 root root 11K Aug  9 09:32 test.zip

//查看boot_etc_back.tar.gz文件内包含哪些内容
[root@final opt]# tar -ztf /opt/boot_etc_back.tar.gz |less
boot/
boot/vmlinuz-2.6.32-504.el6.x86_64
boot/config-2.6.32-504.el6.x86_64
boot/initramfs-2.6.32-504.el6.x86_64.img
boot/efi/
boot/efi/EFI/
boot/efi/EFI/redhat/
boot/efi/EFI/redhat/grub.efi
boot/.vmlinuz-2.6.32-504.el6.x86_64.hmac
boot/grub/

//boot_etc_back.tar.gz释放到/tmp目录下
[root@final opt]# tar -zxf /opt/boot_etc_back.tar.gz -C /tmp/

//备份/usr/sbin 目录,保存为sbin.tar.bz2
[root@final opt]# tar -jcf /opt/sbin.tar.bz2 /usr/sbin/
tar: Removing leading `/‘ from member names
tar: Removing leading `/‘ from hard link targets
[root@final opt]# ll -h /opt/sbin.tar.bz2 
-rw-r--r--. 1 root root 14M Aug  9 09:47 /opt/sbin.tar.bz2

//查看sbin.tar.bz2 包含哪些内容
[root@final opt]# tar -jtf /opt/sbin.tar.bz2
[root@final opt]# ls /tmp/
boot  etc  root  usr

//检查命令mkdir的程序文件在哪
[root@final opt]# which mkdir
/bin/mkdir
//检查命令ls的程序文件在哪
[root@final opt]# which ls
alias ls=‘ls --color=auto‘
    /bin/ls
//检查命令ifocnfig的程序文件在哪
[root@final opt]# which ifconfig
/sbin/ifconfig
//检查命令hostname的程序文件在哪
[root@final opt]# which hostname
/bin/hostname

//查看当前PATH变量的值
[root@final opt]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

find
-type 类型
f 文件
d 目录
l 链接
b 块设备文件
c 字符设备文件
-name 名字
-size 大小(单位c表示byte,k表示1024bytes)
+ 大于
- 小于
mtime 文件内容修改
n n为数字,意义在n天之前的“一天之内”被更改过的文件
+n 列出在n天之前(不含n天本身)被更改过的文件名
-n 列出在n天之内(含n天本身)被更改过的文件名
-a 多个条件同时满足
-o 多个条件满足一条即可

//创建目录、文件、软链接
[root@final opt]# mkdir -p /test/testdir
[root@final opt]# ifconfig > /test/ipadd.txt
[root@final opt]# ln -s /test/ipadd.txt /test/testdir/ip.txt

//查找链接文件--快捷方式
[root@final opt]# find /test/ -type l
/test/testdir/ip.txt

//查找文件
[root@final opt]# find /test/ -type f
/test/ipadd.txt

//查找目录
[root@final opt]# find /test/ -type d
/test/
/test/testdir

//查找/etc目录名称以res开头的conf结尾的配置文件
[root@final opt]# find /etc/ -name "res*.conf"
/etc/selinux/restorecond.conf
/etc/selinux/restorecond_user.conf
/etc/resolv.conf

//查找大于1M的文件
[root@final opt]# cp /boot/vmlinuz* /test/
[root@final opt]# find /test/ -size +1M
/test/vmlinuz-2.6.32-504.el6.x86_64

//查找大于300KB的文件
[root@final opt]# find /sbin/ -size +300k
/sbin/mdadm
/sbin/sln
/sbin/insmod.static
/sbin/grub
/sbin/ldconfig
/sbin/dhclient
/sbin/busybox
/sbin/rsyslogd
/sbin/lvm

System-day3.md

标签:mkdir   空行   哪些   mode   sim   文件夹   efi   sbin   cas   

原文地址:https://www.cnblogs.com/fina/p/9067234.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!