###########timedatectl###########

 

 

[root@lvchao ~]# date

Sat Nov 12 09:01:47 CST 2016

[root@lvchao ~]# timedatectl                                    ###显示系统当前的时间和日期

      Local time: Sat 2016-11-12 09:01:54 CST

  Universal time: Sat 2016-11-12 01:01:54 UTC

        RTC time: Sat 2016-11-12 01:01:54

        Timezone: Asia/Shanghai (CST, +0800)

     NTP enabled: yes

NTP synchronized: no

 RTC in local TZ: no

      DST active: n/a

[root@lvchao ~]# timedatectl list-timezones                        ###显示全部时区

Africa/Abidjan

Africa/Accra

Africa/Addis_Ababa

Africa/Algiers

[root@lvchao ~]# timedatectl set-timezone Asia/Shanghai              ###更改系统时区

[root@lvchao ~]# timedatectl set-time "2016-11-11 09:12:12"          ###更改系统时间

[root@lvchao ~]# date

Fri Nov 11 09:12:15 CST 2016

[root@lvchao ~]# timedatectl set-local-rtc 0                         ###同步UTC时间

[root@lvchao ~]# vim /etc/adjtime

[root@lvchao ~]# timedatectl set-local-rtc 1                         ###使用本地时间

[root@lvchao ~]# vim /etc/adjtime

 

 

#########hostnamectl#############

 

 

[root@desktop28 ~]# hostnamectl                                     ###查看系统hostname信息

   Static hostname: n/a

Transient hostname: desktop28.example.com

         Icon name: computer

           Chassis: n/a

        Machine ID: 946cb0e817ea4adb916183df8c4fc817

           Boot ID: a91121438e4440a4813e49507dd419dc

    Virtualization: kvm

  Operating System: Red Hat Enterprise Linux Server 7.0 (Maipo)

       CPE OS Name: cpe:/o:redhat:enterprise_linux:7.0:GA:server

            Kernel: Linux 3.10.0-123.el7.x86_64

      Architecture: x86_64

[root@desktop28 ~]# hostnamectl set-hostname westos.example.com      ##更改hostname

[root@desktop28 ~]# hostname                                         ###显示hostname

westos.example.com

[root@desktop28 ~]# vim /etc/hostname



#######linux中设备的访问#######

 

###1.设备访问###

1.设备识别

/dev/xdxn                                  ###硬盘设备/dev/sdb1

/dev/cdrom                                 ###光驱

/dev/mapper/*                              ###虚拟设备

 

 

##2.设备的发现##

fdisk -l                                    ###查看真实存在的设备

 

cat /proc/partitions                        ###系统能够识别的设备

 

blkid                                       ###系统能够挂载使用的设备id

 

df                                          ###查看设备被系统使用的情况

 

[root@foundation28 ~]# fdisk -l             ##查看真实存在的设备

(插上U盘后效果)

Disk /dev/sda: 500.1 GB, 500107862016 bytes, 976773168 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 4096 bytes

I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk label type: dos

Disk identifier: 0xe8e708e2

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *          63   167782859    83891398+   7  HPFS/NTFS/exFAT

Partition 1 does not start on physical sector boundary.

/dev/sda2       167782860   976768064   404492602+   f  W95 Ext'd (LBA)

Partition 2 does not start on physical sector boundary.

/dev/sda3       976769024   976773119        2048   83  Linux

/dev/sda5       438333588   708884189   135275301    7  HPFS/NTFS/exFAT

Partition 5 does not start on physical sector boundary.

/dev/sda6       708884253   976768064   133941906    7  HPFS/NTFS/exFAT

Partition 6 does not start on physical sector boundary.

/dev/sda7       167786496   168196095      204800   83  Linux

/dev/sda8       168198144   176586751     4194304   82  Linux swap / Solaris

/dev/sda9       176588800   438333439   130872320   83  Linux

 

Partition table entries are not in disk order

 

Disk /dev/sdb: 15.9 GB, 15938355200 bytes, 31129600 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0xb2bb22af

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1             512    31129599    15564544    b  W95 FAT32

[root@foundation28 ~]# cat /proc/partitions                ###系统能够识别的设备

major minor  #blocks  name

 

   8        0  488386584 sda

   8        1   83891398 sda1

   8        2          1 sda2

   8        3       2048 sda3

   8        5  135275301 sda5

   8        6  133941906 sda6

   8        7     204800 sda7

   8        8    4194304 sda8

   8        9  130872320 sda9

   7        0    3799040 loop0

   8       16   15564800 sdb

   8       17   15564544 sdb1

 

 

[root@foundation28 ~]# blkid                        ###系统能够挂在使用的设备的id

/dev/sda1: UUID="BEE898DDE89894ED" TYPE="ntfs"

/dev/sda5: UUID="000B87C900033209" TYPE="ntfs"

/dev/sda6: UUID="000318A0000C409D" TYPE="ntfs"

/dev/sda7: UUID="14c874d0-bbb8-4fbb-9ca3-07b69d6d18f4" TYPE="xfs"

/dev/sda8: UUID="cb15f413-33e7-4cc4-a5a2-0b9483dabb7f" TYPE="swap"

/dev/sda9: UUID="f9663892-0c00-4379-9a82-e42ce19f0115" TYPE="xfs"

/dev/loop0: UUID="2015-02-19-11-11-02-00" LABEL="RHEL-7.1 Server.x86_64" TYPE="iso9660" PTTYPE="dos"

/dev/sdb1: UUID="2982-F523" TYPE="vfat"

[root@foundation28 ~]# df                           ###查看设备被系统使用的情况

Filesystem     1K-blocks     Used Available Use% Mounted on

/dev/sda9      130808420 30100812 100707608  24% /

devtmpfs         1881932        0   1881932   0% /dev

tmpfs            1891380      696   1890684   1% /dev/shm

tmpfs            1891380     9228   1882152   1% /run

tmpfs            1891380        0   1891380   0% /sys/fs/cgroup

/dev/loop0       3798292  3798292         0 100% /var/www/html/rhel7.1

/dev/sda7         198380   111212     87168  57% /boot

/dev/sdb1       15560448   356096  15204352   3% /run/media/kiosk/2982-F523

 

####3.设备的使用####

 

1.设备的挂载

 

 mount    设备     挂载点

 mount /dev/sdb1  /mnt/

 

[root@foundation28 ~]# mount /dev/sdb1 /mnt/            ###把系统中第二块硬盘的第一个分区挂载到/mnt/目录下

 

2.卸载设备

 

umount 设备|挂载点

 

如果出现以下情况:

[root@foundation28 ~]# umount /mnt/

umount: /mnt: target is busy.

        (In some cases useful info about processes that use

         the device is found by lsof(8) or fuser(1))

 

解决方法:

fuser -kvm 设备|挂载点                                ###-k kill, -v 显示详细信息, -m 扫描设备

[root@foundation28 ~]# fuser -vmk /dev/sdb1

                     USER        PID ACCESS COMMAND

/dev/sdb1:           root     kernel mount /run/media/kiosk/2982-F523

                     root       4916 ..c.. bash

 

####4.软硬链接####

 

1.硬链接:若一个节点对应多个文件名,则这些文件为硬链接。

ln /file /file1

 

[root@foundation28 mnt]# touch file

[root@foundation28 mnt]# ls -li file

274574055 -rw-r--r-- 1 root root 0 Nov 11 21:27 file

[root@foundation28 mnt]# ln /mnt/file /opt/

[root@foundation28 mnt]# ls -li /mnt/file

274574055 -rw-r--r-- 2 root root 0 Nov 11 21:27 /mnt/file

[root@foundation28 mnt]# ls -li /opt/file

274574055 -rw-r--r-- 2 root root 0 Nov 11 21:27 /opt/file

[root@foundation28 mnt]# rm -fr /opt/file

[root@foundation28 mnt]# ls -li /mnt/file

274574055 -rw-r--r-- 1 root root 0 Nov 11 21:27 /mnt/file

 

2.软链接:若多个节点对应一个文件名,则这些文件为软链接。

ln -s /file /file1

 

[root@foundation28 mnt]# touch file

[root@foundation28 mnt]# ls -li file

274574058 -rw-r--r-- 1 root root 0 Nov 11 21:17 file

[root@foundation28 mnt]# ln -s /mnt/file /opt/

[root@foundation28 mnt]# ls -li /mnt/file

274574058 -rw-r--r-- 1 root root 0 Nov 11 21:17 /mnt/file

[root@foundation28 mnt]# ls -li /opt/file

409654518 lrwxrwxrwx 1 root root 9 Nov 11 21:17 /opt/file -> /mnt/file

[root@foundation28 mnt]# rm -fr /mnt/file

[root@foundation28 mnt]# ls -li /opt/file

409654518 lrwxrwxrwx 1 root root 9 Nov 11 21:24 /opt/file -> /mnt/file

[root@foundation28 mnt]# cat /opt/file

cat: /opt/file: No such file or directory

 

######4.文件查找#####

 

1.locate filename                     ###在文件数据库中搜索filename信息,updatedb更新文件数据库

 

[root@foundation28 mnt]# locate westos

/etc/sysconfig/network-scripts/ifcfg-Auto_westos-east

/home/kiosk/.local/share/Trash/files/westos

/home/kiosk/.local/share/Trash/info/westos.trashinfo

/usr/bin/westos.sh

/var/log/libvirt/qemu/westots2.log

[root@foundation28 mnt]# touch /boot/westos

[root@foundation28 mnt]# locate westos

/etc/sysconfig/network-scripts/ifcfg-Auto_westos-east

/home/kiosk/.local/share/Trash/files/westos

/home/kiosk/.local/share/Trash/info/westos.trashinfo

/usr/bin/westos.sh

/var/log/libvirt/qemu/westos2.log

[root@foundation28 mnt]# updatedb

[root@foundation28 mnt]# locate westos

/boot/westos

/etc/sysconfig/network-scripts/ifcfg-Auto_westos-east

/home/kiosk/.local/share/Trash/files/westos

/home/kiosk/.local/share/Trash/info/westos.trashinfo

/usr/bin/westos.sh

/var/log/libvirt/qemu/westos2.log

 

2.find

 

find 查找位置 -条件    条件值    -exec 动作 {} \;

              -name

              -not 条件

              -group

               -user

               -size

               -perm

               -maxdepth

               -mindepth

               -a

               -o

 

[root@foundation28 mnt]# useradd redhat

[root@foundation28 mnt]# useradd linux

[root@foundation28 mnt]# touch file{1..4}

[root@foundation28 mnt]# chown redhat file1

[root@foundation28 mnt]# chown linux.redhat file2

[root@foundation28 mnt]# chown linux.linux file3

[root@foundation28 mnt]# chown linux file4

[root@foundation28 mnt]# ll

total 12

-rw-r--r-- 1 redhat root      0 Nov 11 21:42 file1

-rw-r--r-- 1 linux  redhat    0 Nov 11 21:42 file2

-rw-r--r-- 1 linux  linux     0 Nov 11 21:42 file3

-rw-r--r-- 1 linux  root      0 Nov 11 21:42 file4

[root@foundation28 mnt]# find /mnt/ -user linux                        ##user用户为linux的文件

/mnt/file2

/mnt/file3

/mnt/file4

[root@foundation28 mnt]# find /mnt/ -group linux                      ##group用户为linux的文件

/mnt/file3

[root@foundation28 mnt]# find /mnt/ -user redhat -a -group root         ##user用户为redhat且group用户为root的文件

/mnt/file1

[root@foundation28 mnt]# find /mnt/ -user redhat -o -group redhat      ##user用户为redhat或group用户为redhat的文件

/mnt/file1

/mnt/file2

[root@foundation28 mnt]# find /mnt/ -not -user redhat -o -group redhat   ##user用户不是redhat或group用户是redhat的文件

/mnt/

/mnt/file2

/mnt/file3

/mnt/file4

 

[root@foundation28 mnt]# dd if=/dev/zero of=/mnt/file1 bs=1024 count=10

10+0 records in

10+0 records out

10240 bytes (10 kB) copied, 0.00013982 s, 73.2 MB/s

[root@foundation28 mnt]# dd if=/dev/zero of=/mnt/file2 bs=1024 count=20

20+0 records in

20+0 records out

20480 bytes (20 kB) copied, 0.000160015 s, 128 MB/s

[root@foundation28 mnt]# dd if=/dev/zero of=/mnt/file3 bs=1024 count=30

30+0 records in

30+0 records out

30720 bytes (31 kB) copied, 0.000190452 s, 161 MB/s

[root@foundation28 mnt]# find /mnt/ -size 20k       ##文件大小是20k的

/mnt/file2  

[root@foundation28 mnt]# find /mnt/ -size -20k       ##文件大小小于20k的

/mnt/

/mnt/file1

[root@foundation28 mnt]# find /mnt/ -size +20k       ##文件大小大于20k的

/mnt/file3

 

[root@lvchao mnt]# ll

total 0

-r--r--r--. 1 root root 0 Nov 11 22:09 file1

--w--w--w-. 1 root root 0 Nov 11 22:09 file2

-rwxrw-r--. 1 root root 0 Nov 11 22:09 file3

--w-r-xrwx. 1 root root 0 Nov 11 22:09 file4

[root@lvchao mnt]# find /mnt/ -perm 444              ###权限是444的文件

/mnt/file1

[root@lvchao mnt]# find /mnt/ -perm 222              ###权限是222的文件

/mnt/file2

[root@lvchao mnt]# find /mnt/ -perm -222             ###权限含有222的文件

/mnt/

/mnt/file2

[root@lvchao mnt]# find /mnt/ -perm -124

/mnt/

/mnt/file3

[root@lvchao mnt]# find /mnt/ -perm /124       ###权限满足一个即可

/mnt/

/mnt/.java

/mnt/.java/.systemPrefs

/mnt/file1

/mnt/file2

/mnt/file3

/mnt/file4

[root@lvchao mnt]# find /etc/ -name passwd

/etc/passwd

/etc/pam.d/passwd

[root@lvchao mnt]# find /etc/ -maxdepth 1 -mindepth 1 -name passwd          ##目录最大深度为1,最小深度为1

/etc/passwd

 

[root@lvchao mnt]# find / -group mail -exec cp -rp {} /mnt/mailbackup/ \;     ##找出mail组下的文件复制到/mnt/mailbckup

find: ‘/proc/2457/task/2457/fd/6’: No such file or directory

find: ‘/proc/2457/task/2457/fdinfo/6’: No such file or directory

find: ‘/proc/2457/fd/6’: No such file or directory

find: ‘/proc/2457/fdinfo/6’: No such file or directory

cp: ‘/mnt/mailbackup/mail’ and ‘/mnt/mailbackup/mail’ are the same file

cp: ‘/mnt/mailbackup/rpc’ and ‘/mnt/mailbackup/rpc’ are the same file

cp: ‘/mnt/mailbackup/student’ and ‘/mnt/mailbackup/student’ are the same file

cp: ‘/mnt/mailbackup/root’ and ‘/mnt/mailbackup/root’ are the same file

cp: ‘/mnt/mailbackup/westos’ and ‘/mnt/mailbackup/westos’ are the same file

cp: ‘/mnt/mailbackup/redhat’ and ‘/mnt/mailbackup/redhat’ are the same file

cp: ‘/mnt/mailbackup/mailbckup’ and ‘/mnt/mailbackup/mailbckup’ are the same file

[root@lvchao mnt]# ls /mnt/mailbackup

mail  mailbckup  redhat  root  rpc  student  westos