22期第七周课堂练习

1、创建一个10G分区,并格式为ext4文件系统;
       (1) 要求其block大小为2048, 预留空间百分比为2,   卷标为MYDATA, 默认挂载属性包含acl;
       (2)   挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;

   1.创建分区/dev/sdb1,容量为10G
   [root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xa5b8f2f4.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1435, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1435, default 1435): +10G

Command (m for help): w

  2.查看创建的分区
[root@localhost ~]# fdisk  -l /dev/sdb

Disk /dev/sdb: 11.8 GB, 11811160064 bytes
255 heads, 63 sectors/track, 1435 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa5b8f2f4

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1306    10490413+  83  Linux
  
  3.格式化
  [root@localhost ~]# mke2fs -b 2048 -m 2 -t ext4 -L MYDATA    /dev/sdb1
  4.修改分区属性
  [root@localhost ~]# tune2fs -o acl /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
  5.查看分区属性
  [root@localhost ~]# dumpe2fs -h  /dev/sdb1
dumpe2fs 1.41.12 (17-May-2010)
Filesystem volume name:   MYDATA
Last mounted on:          <not available>
Filesystem UUID:          d97d8ba2-ebed-413b-a4c7-a9a0a4986fa1
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash 
Default mount options:    acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              657408
Block count:              5245206
Reserved block count:     104904
Free blocks:              5123382
Free inodes:              657397
First block:              0
Block size:               2048
Fragment size:            2048
Reserved GDT blocks:      512
Blocks per group:         16384
Fragments per group:      16384
Inodes per group:         2048
Inode blocks per group:   256
Flex block group size:    16
Filesystem created:       Wed Sep 21 17:33:07 2016
Last mount time:          n/a
Last write time:          Wed Sep 21 17:34:14 2016
Mount count:              0
Maximum mount count:      39
Last checked:             Wed Sep 21 17:33:07 2016
Check interval:           15552000 (6 months)
Next check after:         Mon Mar 20 17:33:07 2017
Lifetime writes:          226 MB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:	          256
Required extra isize:     28
Desired extra isize:      28
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      043a3a0c-ac3a-4728-8bdf-e0347fa690da
Journal backup:           inode blocks
Journal features:         (none)
Journal size:             64M
Journal length:           32768
Journal sequence:         0x00000001
Journal start:            0
4.挂载
[root@localhost ~]# mount -o noexec,nodiratime  /dev/sdb1 /data/mydata/

5.设置开机自动挂载
[root@localhost ~]# vim /etc/fstab 
#
# /etc/fstab
# Created by anaconda on Mon Aug 22 18:25:35 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root /                       ext4    defaults        1 1
UUID=e36e7a7c-97a5-4712-ac29-7973c98c847c /boot                   ext4    defaults        1 2
/dev/mapper/VolGroup-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/sdb1               /mnt                    ext4    defaults        0 0

2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;

1.查看当前swap分区大小,目前为3G
[root@bogon ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          1862        303       1559          0         19        105
-/+ buffers/cache:        178       1683
Swap:         3071          0       3071

2.创建swap类型的分区/dev/sdb1
[root@bogon ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 11.8 GB, 11811160064 bytes
255 heads, 63 sectors/track, 1435 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa5b8f2f4

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         132     1060258+  82  Linux swap / Solaris
3.转换为交换分区
[root@bogon ~]# mkswap /dev/sdb1
Setting up swapspace version 1, size = 1060252 KiB
no label, UUID=898c07c8-5460-44d5-9ae9-049568b339bc
4.启动交换分区
[root@bogon ~]# swapon /dev/sdb1
5.再次查看交换分区。变成了4G
[root@bogon ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          1862        304       1558          0         19        105
-/+ buffers/cache:        179       1683
Swap:         4107          0       4107

    3、写一个脚本

       (1)、获取并列出当前系统上的所有磁盘设备;

       (2)、显示每个磁盘设备上每个分区相关的空间使用信息;

#!/bin/bash
#show dev info
for dev in $(fdisk -l|grep -o "^/dev/[[:alnum:]]\{3,\}");do
   echo   $dev 
   echo -e "$(df -h  $dev)\n"
done

    4、总结RAID的各个级别及其组合方式和性能的不同;

blob.png

    5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k;

1.创建2个raid类型的分区,/dev/sdc1,/dev/sdd1,/dev/sde1,创建raid1
[root@bogon ~]# mdadm -C -l 1 -c 128 -n 2 -x 1 /dev/sdc1 /dev/sdd1 /dev/sde1
mdadm: device /dev/sdc1 exists but is not an md array.
[root@bogon ~]# mdadm -C /dev/md0  -l 1 -c 128 -n 2 -x 1 /dev/sdc1 /dev/sdd1 /dev/sde1
mdadm: Note: this array has metadata at the start and
    may not be suitable as a boot device.  If you plan to
    store '/boot' on this device please ensure that
    your boot-loader understands md/v1.x metadata, or use
    --metadata=0.90
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

2.查看raid信息
[root@bogon ~]# mdadm -D /dev/md0  
/dev/md0:
        Version : 1.2
  Creation Time : Mon Sep 26 20:03:48 2016
     Raid Level : raid1
     Array Size : 10482112 (10.00 GiB 10.73 GB)
  Used Dev Size : 10482112 (10.00 GiB 10.73 GB)
   Raid Devices : 2
  Total Devices : 3
    Persistence : Superblock is persistent

    Update Time : Mon Sep 26 20:04:21 2016
          State : clean, resyncing 
 Active Devices : 2
Working Devices : 3
 Failed Devices : 0
  Spare Devices : 1

  Resync Status : 28% complete

           Name : bogon:0  (local to host bogon)
           UUID : c63aeb60:7f098351:3ed32a55:e3caca40
         Events : 4

    Number   Major   Minor   RaidDevice State
       0       8       33        0      active sync   /dev/sdc1
       1       8       49        1      active sync   /dev/sdd1

       2       8       65        -      spare   /dev/sde

      6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;

1.创建3个raid类型的分区,/dev/sdd1,/dev/sdd2,/dev/sde1,创建raid5
[root@bogon ~]# mdadm -C /dev/md0 -l 5 -c 256 -n 3 /dev/sdd1 /dev/sdd2 /dev/sde1
2.格式化为ext4
[root@bogon ~]# mke2fs -t ext4 /dev/md0
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=64 blocks, Stripe width=128 blocks
525200 inodes, 2098304 blocks
104915 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2151677952
65 block groups
32768 blocks per group, 32768 fragments per group
8080 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

3.设置开机自动挂载
[root@bogon ~]# vim /etc/fstab 
#
# /etc/fstab
# Created by anaconda on Mon Aug 22 18:25:35 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root /                       ext4    defaults        1 1
UUID=e36e7a7c-97a5-4712-ac29-7973c98c847c /boot                   ext4    defaults        1 2
/dev/mapper/VolGroup-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/md0                /backup                 ext4    defaults,nodiratime,acl  0 0

    7、写一个脚本
       (1) 接受一个以上文件路径作为参数;
       (2) 显示每个文件拥有的行数;

       (3) 总结说明本次共为几个文件统计了其行数;

#!/bin/bash
#sum file line
if [ $# -lt 2 ];then
 echo "please input in least two file:"
 exit 2
else
   for i in $@;do
      if [ -e $i ] && [ -f $i ];then
        echo " `wc -l $i`"
      else
          echo "no such file or this is diretory"
      fi
   done
fi

echo " the file number is:" $#

    8、写一个脚本
       (1) 传递两个以上字符串当作用户名;
       (2) 创建这些用户;且密码同用户名;

       (3) 总结说明共创建了几个用户;

!/bin/bash
if [ $# -lt 2 ]; then
      echo "At least two username."
      exit 2
fi
declare -x num=0;
for i in $@;do
   if  grep "^$i\>" /etc/passwd &> /dev/null; then
       echo "User $i exists"
   else
      useradd $i
      let num++
      echo $i | passwd --stdin $i &> /dev/null
      echo "Add user $i finished."
   fi
done
echo "Adding user number is:"$nu

    9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;

#!/bin/bash
for user in {1..20};do
 useradd visitor$user
 a=`id -u visitor$user`
 sum=$[$sum+$a]
done
 echo $sum

      10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;

#!/bin/bash
for file in /etc/rc.d/rc.sysinit /etc/rc.d/init.d/functions /etc/fstab;do
a=$(grep "^#" $file |wc -l)
b=$(grep "^$" $file |wc -l)
echo "$file  $a  $b"
done

    11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;

#!/bin/bash
a=`grep "\<bash\>$" /etc/passwd |cut -d: -f3`
b=`grep "\<bash\>$" /etc/passwd |cut -d: -f 1,3`
echo -e "$b\n"
for i in $a;do
sum=$[$sum+$i]
done
echo  "uid sum is:"$sum

    12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;

#!/bin/bash
 declare i=0
for user in $(cat /etc/passwd |cut -d: -f 1);do
   id $user |grep ","
  if [ $? -eq 0 ];then
  echo "$user"
  let i++
  fi
done
  echo  "the users is:" $i

      13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;

1.创建分区/dev/sdb1,/dev/sdb2
[root@MiWiFi-R1CM-srv ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 26.8 GB, 26843545600 bytes
255 heads, 63 sectors/track, 3263 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7e26fae5

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1306    10490413+  83  Linux
/dev/sdb2            1307        2612    10490445   83  Linux
[root@MiWiFi-R1CM-srv ~]# 
2.创建pv
[root@MiWiFi-R1CM-srv ~]# pvcreate  /dev/sdb{1,2}
  dev_is_mpath: failed to get device for 8:17
  Physical volume "/dev/sdb1" successfully created
  dev_is_mpath: failed to get device for 8:18
  Physical volume "/dev/sdb2" successfully create
3.创建卷组vg0,pe大小为8m
[root@MiWiFi-R1CM-srv ~]# vgcreate -s 8 vg0 /dev/sdb1 /dev/sdb2
  Volume group "vg0" successfully created
 4.查看vg信息
 [root@MiWiFi-R1CM-srv ~]# vgdisplay 
  --- Volume group ---
  VG Name               vg0
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               20.00 GiB
  PE Size               8.00 MiB
  Total PE              2560
  Alloc PE / Size       0 / 0   
  Free  PE / Size       2560 / 20.00 GiB
  VG UUID               FvNYvj-86jM-1LJz-pyph-2vfv-LuGN-eMs3pI
  5.创建lv逻辑卷mylv1,大小为5G
  [root@MiWiFi-R1CM-srv ~]# lvcreate -L 5g -n mylv1 /dev/vg0
  Logical volume "mylv1" created
[root@MiWiFi-R1CM-srv ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/vg0/mylv1
  LV Name                mylv1
  VG Name                vg0
  LV UUID                8XmMvG-3Psh-3GnR-H9MD-ZwVh-smGH-MEr3mW
  LV Write Access        read/write
  LV Creation host, time MiWiFi-R1CM-srv, 2016-09-26 00:20:53 +0800
  LV Status              available
  # open                 0
  LV Size                5.00 GiB
  Current LE             640
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  6.格式化为ext4格式     
  [root@MiWiFi-R1CM-srv ~]# mke2fs -t ext4 /dev/vg0//mylv1  
  mke2fs 1.41.12 (17-May-2010)
  Filesystem label=
  OS type: Linux
  Block size=4096 (log=2)
  Fragment size=4096 (log=2)
  Stride=0 blocks, Stripe width=0 blocks
  327680 inodes, 1310720 blocks
  65536 blocks (5.00%) reserved for the super user
  First data block=0
  Maximum filesystem blocks=1342177280
  40 block groups
  32768 blocks per group, 32768 fragments per group
  8192 inodes per group
  Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736

  Writing inode tables: done                            
  Creating journal (32768 blocks): done
  Writing superblocks and filesystem accounting information: done

  This filesystem will be automatically checked every 24 mounts or
  180 days, whichever comes first.  Use tune2fs -c or -i to override.
  7.配置开机自动挂载
  # /etc/fstab
# Created by anaconda on Sun Sep 25 20:18:18 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=f98e4337-9bbe-4d63-914b-1265dd7a9ddd /                       ext4    defaults        1 1
UUID=dc2e05ac-e97a-4369-83b6-a06cd6c32c3d swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/vg0/mylv1                  /users          ext4    defaults,acl    0 0

    14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;

[root@MiWiFi-R1CM-srv users]# useradd -d /users/magedu  magedu
[root@MiWiFi-R1CM-srv users]# su - magedu
[magedu@MiWiFi-R1CM-srv ~]$ cp /etc/init
init/    init.d/  inittab  
[magedu@MiWiFi-R1CM-srv ~]$ cp /etc/init
init/    init.d/  inittab  
[magedu@MiWiFi-R1CM-srv ~]$ cp  -r /etc/init.d/* /users/magedu/
[magedu@MiWiFi-R1CM-srv ~]$ cd /users/magedu/
[magedu@MiWiFi-R1CM-srv ~]$ ls
abrt-ccpp         crond         irqbalance      nfs          rngd        snmptrapd
abrtd             cups          kdump           nfslock      rpcbind     spice-vdagentd
abrt-oops         dnsmasq       killall         ntpd         rpcgssd     sshd
acpid             firstboot     lvm2-lvmetad    ntpdate      rpcidmapd   sssd
atd               functions     lvm2-monitor    oddjobd      rpcsvcgssd  sysstat
auditd            haldaemon     mdmonitor       portreserve  rsyslog     udev-post
autofs            halt          messagebus      postfix      sandbox     wdaemon
blk-availability  htcacheclean  netconsole      psacct       saslauthd   winbind
bluetooth         httpd         netfs           quota_nld    single      wpa_supplicant
certmonger        ip6tables     network         rdisc        smartd      ypbind
cpuspeed          iptables      NetworkManager  restorecond  snmpd

    15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;

[root@MiWiFi-R1CM-srv ~]# lvextend -L +4G /dev/vg0/mylv1 
  Extending logical volume mylv1 to 9.00 GiB
  Logical volume mylv1 successfully resized
[root@MiWiFi-R1CM-srv ~]# cd /users/magedu/
[root@MiWiFi-R1CM-srv magedu]# resize2fs /dev/vg0/mylv1 
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg0/mylv1 is mounted on /users; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vg0/mylv1 to 2359296 (4k) blocks.
^[[CThe filesystem on /dev/vg0/mylv1 is now 2359296 blocks long.

[root@MiWiFi-R1CM-srv magedu]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/sda2               17G  3.3G   13G  21% /
tmpfs                  936M   72K  936M   1% /dev/shm
/dev/mapper/vg0-mylv1  8.9G  140M  8.3G   2% /users
[root@MiWiFi-R1CM-srv magedu]# ls
abrt-ccpp         crond         irqbalance      nfs          rngd        snmptrapd
abrtd             cups          kdump           nfslock      rpcbind     spice-vdagentd
abrt-oops         dnsmasq       killall         ntpd         rpcgssd     sshd
acpid             firstboot     lvm2-lvmetad    ntpdate      rpcidmapd   sssd
atd               functions     lvm2-monitor    oddjobd      rpcsvcgssd  sysstat
auditd            haldaemon     mdmonitor       portreserve  rsyslog     udev-post
autofs            halt          messagebus      postfix      sandbox     wdaemon
blk-availability  htcacheclean  netconsole      psacct       saslauthd   winbind
bluetooth         httpd         netfs           quota_nld    single      wpa_supplicant
certmonger        ip6tables     network         rdisc        smartd      ypbind
cpuspeed          iptables      NetworkManager  restorecond  snmpd

    16、缩减mylv1至7G,确保缩减完成后原有数据完全可用;

1.卸载
[root@MiWiFi-R1CM-srv ~]# umount /dev/vg0/mylv1 
2.检查
[root@MiWiFi-R1CM-srv ~]# e2fsck -f /dev/vg0/mylv1 
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg0/mylv1: 85/589824 files (0.0% non-contiguous), 72765/2359296 blocks
3.重设大小
[root@MiWiFi-R1CM-srv ~]# resize2fs /dev/vg0/mylv1  7G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vg0/mylv1 to 1835008 (4k) blocks.
The filesystem on /dev/vg0/mylv1 is now 1835008 blocks long.
4.减小逻辑卷大小
[root@MiWiFi-R1CM-srv ~]# lvcreate -L 7G /dev/vg0/mylv1 
  Volume group name expected (no slash)
  Run `lvcreate --help' for more information.
[root@MiWiFi-R1CM-srv ~]# lvreduce  -L 7G /dev/vg0/mylv1 
  WARNING: Reducing active logical volume to 7.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce mylv1? [y/n]: y  
  Reducing logical volume mylv1 to 7.00 GiB
  Logical volume mylv1 successfully resized
5.重新挂载,并查看大小
[root@MiWiFi-R1CM-srv ~]# mount -a
[root@MiWiFi-R1CM-srv ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/sda2               17G  3.3G   13G  21% /
tmpfs                  936M   72K  936M   1% /dev/shm
/dev/mapper/vg0-mylv1  6.9G  140M  6.5G   3% /users

    17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;

1.创建快照
[root@MiWiFi-R1CM-srv ~]# lvcreate -L 1G -p r  -s -n sn_mylv1 /dev/vg0/mylv1 
  Logical volume "sn_mylv1" created
2.将快照挂载至/backup
[root@MiWiFi-R1CM-srv ~]# mount /dev/vg0/sn_mylv1 /back/
mount: block device /dev/mapper/vg0-sn_mylv1 is write-protected, mounting read-only
[root@MiWiFi-R1CM-srv ~]# cd /back/
[root@MiWiFi-R1CM-srv back]# ls
lost+found  magedu
[root@MiWiFi-R1CM-srv back]# cd magedu/
[root@MiWiFi-R1CM-srv magedu]# ls
abrt-ccpp         crond         irqbalance      nfs          rngd        snmptrapd
abrtd             cups          kdump           nfslock      rpcbind     spice-vdagentd
abrt-oops         dnsmasq       killall         ntpd         rpcgssd     sshd
acpid             firstboot     lvm2-lvmetad    ntpdate      rpcidmapd   sssd
atd               functions     lvm2-monitor    oddjobd      rpcsvcgssd  sysstat
auditd            haldaemon     mdmonitor       portreserve  rsyslog     udev-post
autofs            halt          messagebus      postfix      sandbox     wdaemon
blk-availability  htcacheclean  netconsole      psacct       saslauthd   winbind
bluetooth         httpd         netfs           quota_nld    single      wpa_supplicant
certmonger        ip6tables     network         rdisc        smartd      ypbind
cpuspeed          iptables      NetworkManager  restorecond  snmpd
[root@MiWiFi-R1CM-srv magedu]# mkdir /backup2
[root@MiWiFi-R1CM-srv magedu]# ls
abrt-ccpp         crond         irqbalance      nfs          rngd        snmptrapd
abrtd             cups          kdump           nfslock      rpcbind     spice-vdagentd
abrt-oops         dnsmasq       killall         ntpd         rpcgssd     sshd
acpid             firstboot     lvm2-lvmetad    ntpdate      rpcidmapd   sssd
atd               functions     lvm2-monitor    oddjobd      rpcsvcgssd  sysstat
auditd            haldaemon     mdmonitor       portreserve  rsyslog     udev-post
autofs            halt          messagebus      postfix      sandbox     wdaemon
blk-availability  htcacheclean  netconsole      psacct       saslauthd   winbind
bluetooth         httpd         netfs           quota_nld    single      wpa_supplicant
certmonger        ip6tables     network         rdisc        smartd      ypbind
cpuspeed          iptables      NetworkManager  restorecond  snmpd

[root@MiWiFi-R1CM-srv magedu]# cd ..
[root@MiWiFi-R1CM-srv back]# ll
total 20
drwx------. 2 root   root   16384 Sep 26 00:23 lost+found
drwx------. 4 magedu magedu  4096 Sep 26 00:40 magedu
3.将快照的文件复制至/backup2
[root@MiWiFi-R1CM-srv back]# cp -a magedu/  /backup2/
[root@MiWiFi-R1CM-srv back]# cd /backup2
[root@MiWiFi-R1CM-srv backup2]# ls
magedu
4.查看权限,没有改变
[root@MiWiFi-R1CM-srv backup2]# ll
total 4
drwx------. 4 magedu magedu 4096 Sep 26 00:40 magedu
[root@MiWiFi-R1CM-srv backup2]# cd magedu/
[root@MiWiFi-R1CM-srv magedu]# ls
abrt-ccpp         crond         irqbalance      nfs          rngd        snmptrapd
abrtd             cups          kdump           nfslock      rpcbind     spice-vdagentd
abrt-oops         dnsmasq       killall         ntpd         rpcgssd     sshd
acpid             firstboot     lvm2-lvmetad    ntpdate      rpcidmapd   sssd
atd               functions     lvm2-monitor    oddjobd      rpcsvcgssd  sysstat
auditd            haldaemon     mdmonitor       portreserve  rsyslog     udev-post
autofs            halt          messagebus      postfix      sandbox     wdaemon
blk-availability  htcacheclean  netconsole      psacct       saslauthd   winbind
bluetooth         httpd         netfs           quota_nld    single      wpa_supplicant
certmonger        ip6tables     network         rdisc        smartd      ypbind
cpuspeed          iptables      NetworkManager  restorecond  snmpd

原创文章,作者:a295053193,如若转载,请注明出处:http://www.178linux.com/48115

赞 (0)
a295053193a295053193
上一篇 2016-10-09 09:06
下一篇 2016-10-09 09:06

相关推荐

  • 构建企业日志实时查看系统

    前言:          由于项目刚刚上线,出现了许多bug,开发人员需要经常跑过来查看日记,严重影响了我们运维人员的工作效率,时而久之,感觉那个烦啊。。各位仁兄有 没有体 会到呢!!! 之前找了一些处理日记的工具都不具有实时性,所以都未采纳,刚刚发现了log.io这个工具推荐个…

    Linux干货 2015-02-13
  • select和case用法

    一、作业 1、斐波那契数列又称黄金分割数列,因数学家列昂纳多·斐波那契以兔子繁殖为例子而引入,故又称为“兔子数列”,指的是这样一个数列:0、1、1、2、3、5、8、13、21、34、……,斐波纳契数列以如下被以递归的方法定义:F(0)=0,F(1)=1,F(n)=F(n-1)+F(n-2)(n≥2) 写一个函数,求n阶斐波那契数列 2、汉诺塔(又称河内塔)问…

    Linux干货 2016-08-21
  • lvs-keepalived

    keepalived: vrrp协议:Virtual Redundant Routing Protocol        术语:        虚拟路由器:Virtual Router &n…

    Linux干货 2017-05-13
  • 马哥教育网络班22期第二周课程练习1-未闻花名

    1、Linux管理文件和目录的命令 命令 功能 命令 功能 pwd 显示当前目录 ls 查看目录下的内容 cd 改变所在目录 cat 显示文件的内容 grep 在文件中查找某字符 cp 复制文件 touch 创建文件 mv 移动文件 rm 删除文件 rmdir 删除目录 1.1 pwd命令 该命令的英文解释为print working directory(打…

    Linux干货 2016-08-29
  • kickstart 的使用!

    简介 1.什么是kickstart KickStart是一种无人职守安装方式。KickStart的工作原理是通过记录典型的安装过程中所需人工干预填写的各种参数,并生成一个名为ks.cfg的文件;在其后的安装过程中(不只局限于生成KickStart安装文件的机器)当出现要求填写参数的情况时,安装程序会首先去查找KickStart生成的文件,当找到合适的参数时,…

    Linux干货 2016-11-03
  • shell脚本中变量与运算及简单编程示例

    一、变量         在Linux shell脚本的变量中,分为系统定义的变量和用户定义的变量。这些变量是用来调用一个数值或字符值。定义变量时,不需要声明变量类型。 1、系统变量         …

    Linux干货 2016-08-15

评论列表(1条)

  • luoweiro
    luoweiro 2016-10-11 23:25

    这是我看到脚本写的看着最舒服的作业,而且作业整个过程也是非常详细的,加油。