1.基本管理

 

 

1.1.Xwindows与命令行模式

 

  • 默认情况下,Linux会提供6个终端来让用户登入,切换时使用:[Ctrl]+[Alt]+[F2]~[F6]组合键,同时,系统为了判断,会将[F2]~[F6]定义为tty2~tty6的操作界面环境。当在图形化界面按下[Ctrl]+[Alt]+[F2]3个组合键时,就会进入到tty2的终端界面中了。

  • [Ctrl]+[Alt]+[F2]~[F6] :从图形化界面切换回命令行模式(F2—F65个命令行的登录界面)

  • [Alt]+[F1]:切换到图形界面的桌面

 

注:

  • 从命令行切换到图形化界面,如果xwindows已经默认运行,则可以直接通过[Ctrl]+[Alt]+[F1]来切换到图形化界面。

  • 如果开机启动默认是命令行模式,并且xwindows没有运行,从命令行切换到图形化界面要先使用startx调用xwindows,再通过[Ctrl]+[Alt]+[F1]来切换到图形化界面。

 

 

 

1.2.命令行模式说明

wKioL1ckNseAr9lrAAAkM2kWW2o774.png

显示Linux版本名称和版本号;

显示Linux内核版本和硬件等级;

显示主机名称、login后面需要输入登入者账号;

输入登入者对应的密码,命令模式下默认不显示



wKiom1ckNfiiQKpbAACEhAmItYw801.png

1.3.Linux命令说明

 

 

1.3.1.命令类型

 

  • Shell内部命令(一般情况下可以直接在命令行使用)

  • 外部应用程序命令(一般情况下需要安装包才能正常使用的命令)

 

 

1.3.2.命令格式

 

Command    [option]   [arguments]

说明:

command:执行的命令;

[]:表示选项或参数可有可无,参数并非必须

option:命令的选项说明对命令的要求;

arguments:命令的参数,描述命令作用的对象;

 

 

1.3.3.参数的运用

 

可选项参数:

  • 短格式可选项,如:-f

  • 带参数的短格式可选项,如:-f512-f 512

  • 长格式可选项,如:--filesize

  • 带参数的长格式可选项,如:--filesize=512

 

命令对象参数

  • 文件名

  • 用户名、组名

注:Linux命令和参数严格区分大小写。

 

 

1.3.4.帮助命令

 

  • 应用程序帮助选项:-h- -help

  • man

  • Info

  • help

 

 

 

1.4.基本网络管理

 

1.4.1.IP配置的五种方法

 

方法一:看图



wKiom1ckNfmjicjAAAJ2pVJvOAw606.png

Xwindows模式的桌面右上角点击网络设置图标【小电脑】(右键、左键均可),然后选择【Network Settings】打开网络设置,如下:

wKioL1ckNsmxf4AaAADdWH2IS1s165.png

选择【Wired】,然后在右边点击【设置】按钮,打开如下界面:

wKioL1ckNsmSRsMDAAB0p7zyMxo393.png


选择【Ipv4--地址选择手动即【Manual】,然后在下面填写IP地址及掩码、网关等信息。

接着把界面向下拉,找到如下内容:

wKiom1ckNfqDQ8EpAACCxaVqsgY296.png

勾选此选项,当网络可用时自动连接,不需再手动启用网络。

设置完毕后,点击界面最下方的【Apply】按钮应用。关闭网络设置界面即可

 

最后,使用命令重启网络,使ip生效

[root@freeit  Desktop]# systemctl restart network.service

 

注:此方法只适用于直接登录服务器xwindows界面时,其他情况不能使用。

 

 

方法二:命令行打开图形界面设置

 

输入以下命令打开设置对话框

[root@freeit  Desktop]# nm-connection-editor

 

wKiom1ckNfvC59IlAABFyJcZZv0146.png

选择【Eth0】(注:原始系统网卡名字为eno16777736eth0是手动修改的,后面我们将详细介绍怎么修改为eth0),然后点击【edit】,打开IP设置界面

wKioL1ckNsrifwJfAAByS-0OCAA807.png

点击【General】选项卡,勾选上图红框框处,当网络可用时自动连接。

然后选择【Ipv4Settings】,设置IP方式为【Manual----Add】添加IP地址,最后保存退出即可,如下图:



wKiom1ckNfvBOYk1AACYfKKjG2I181.png

最后用命令重启网卡服务,使IP生效。

 

 

方法三:修改网卡配置文件

 

Linux中,网卡的配置文件一般存放在/etc/sysconfig/network-scripts/,名字为ifcfg-eth0(如果不修改网卡名字,为原始的ifcfg-eno16777736),下面我们就进入配置文件修改IP

TYPE=Ethernet

BOOTPROTO=none

DEFROUTE=no

IPV4_FAILURE_FATAL=no

IPV6INIT=yes

IPV6_AUTOCONF=yes

IPV6_DEFROUTE=yes

IPV6_FAILURE_FATAL=no

NAME=eth0

UUID=4765ab39-581e-4412-8642-af58cbf93140

ONBOOT=yes

IPADDR0=192.168.10.100

PREFIX0=24

GATEWAY0=192.168.10.1

DNS1=192.168.10.100

HWADDR=00:0C:29:70:F0:64

IPV6_PEERDNS=yes

IPV6_PEERROUTES=yes

~                                                                          

"ifcfg-eth0" 17L, 315C                                  4,1           All

修改之后,按【ESC】然后【:】-wq!】保存退出即可。

 

最后,重启网卡服务,使IP生效。

 

 

方法四:nmcli设置IP

 

[root@freeit Desktop]# nmcli connection  modify eth0 ipv4.addresses '192.168.100.100'

[root@freeit Desktop]# systemctl restart  network.service

 

 

以上四种方法设置的IP,生效后为永久生效。下面我们就来介绍一种临时生效的方法(重启失效)

 

 

方法五:ifconfig配置法

 

此方法的配置方法比较简单,只需一条命令即可,如下:

[root@freeit  Desktop]# ifconfig eth0 192.168.1.1/22

[root@freeit Desktop]# ifconfig

eth0:  flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

         inet 192.168.1.1  netmask  255.255.252.0  broadcast 192.168.3.255

         inet6 fe80::20c:29ff:fe70:f064   prefixlen 64  scopeid  0x20<link>

         ether 00:0c:29:70:f0:64   txqueuelen 1000  (Ethernet)

         RX packets 13029  bytes 797524  (778.8 KiB)

         RX errors 0  dropped 0  overruns 0   frame 0

         TX packets 292  bytes 44227  (43.1 KiB)

         TX errors 0  dropped 0 overruns  0  carrier 0  collisions 0

 

注:此方法设置的IP为临时生效,重启失效,且不会改变配置文件中的地址。

 

 

1.4.2.网卡名修改

 

在学习Redhat Linux(RHEL)的其他版本系统时,默认网卡都是以eth0格式命名的。而RHCL7.x的版本对网卡的命名是通过读取BIOS的网卡信息来命名的,所以有我们看到的网卡名:eno16777736。这样的命名方式,可以在多网卡环境中轻松识别使用的网卡。但有的人可能不习惯这样的命名方式,如果想要改回原来的eth0,也是可以办到的。下面我们就来介绍如何修改:

此信息的修改,要修改grub,文件路径为/ etc/sysconfig/grub,关闭BIOS命名网卡的功能。正常情况下,系统重启之后,默认读取的grub文件为/etc/sysconfig/grub2/grub.cfg,所以,前者修改之后,还要把修改内容刷进后者配置文件,以便系统重启之后能够读到更改的配置。

----------------------------------------------修改网卡配置文件------------------------

[root@freeit ~]# cd  /etc/sysconfig/network-scripts/

[root@freeit network-scripts]# ls

ifcfg-eno16777736  ifdown-post      ifup-bnep   ifup-routes

[root@freeit network-scripts]# cp -p  ifcfg-eno16777736 ifcfg-eth0

---------------------------------------修改配置文件的网卡名字--------------------------

TYPE=Ethernet

BOOTPROTO=none

DEFROUTE=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=yes

IPV6_AUTOCONF=yes

IPV6_DEFROUTE=yes

IPV6_FAILURE_FATAL=no

NAME=eth0

UUID=210db2a8-848e-46e2-83c2-23f0c30e227f

ONBOOT=yes

HWADDR=00:0C:29:02:1C:E7

IPADDR0=192.168.10.11

PREFIX0=24

GATEWAY0=192.168.10.1

IPV6_PEERDNS=yes

IPV6_PEERROUTES=yes

                                                                           

"ifcfg-eth0" 17L, 315C                                   13,1         全部

 

[root@freeit network-scripts]# mv  ifcfg-eno16777736 ifcfg-eno16777736.bak

----------------------------------------------修改grub文件------------------------------

[root@freeit ~]# vim /etc/sysconfig/grub

//进入grub文件,添加如下内容(红色字体)

GRUB_TIMEOUT=5

GRUB_DISTRIBUTOR="$(sed 's, release  .*$,,g' /etc/system-release)"

GRUB_DEFAULT=saved

GRUB_DISABLE_SUBMENU=true

GRUB_TERMINAL_OUTPUT="console"

GRUB_CMDLINE_LINUX="rd.lvm.lv=rhel/root  crashkernel=auto  rd.lvm.lv=rhel/sw

ap vconsole.font=latarcyrheb-sun16  vconsole.keymap=us net.ifnames=0 biosdev

name=0 rhgb quiet"

GRUB_DISABLE_RECOVERY="true"

--------------------------------------------刷入修改内容------------------------------------------------

[root@freeit ~]# grub2-mkconfig -o  /boot/grub2/grub.cfg

Generating grub configuration file ...

Found linux p_w_picpath:  /boot/vmlinuz-3.10.0-121.el7.x86_64

Found initrd p_w_picpath:  /boot/initramfs-3.10.0-121.el7.x86_64.img

Found linux p_w_picpath:  /boot/vmlinuz-0-rescue-dd5f92bce4bc4e71ae3de19137fea9dd

Found initrd p_w_picpath:  /boot/initramfs-0-rescue-dd5f92bce4bc4e71ae3de19137fea9dd.img

Done

------------------------------------------重启查看---------------------------------------

[root@freeit ~]# ifconfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

         inet 192.168.10.11  netmask  255.255.255.0  broadcast 192.168.10.255

         inet6 fe80::20c:29ff:fe02:1ce7   prefixlen 64  scopeid  0x20<link>

         ether 00:0c:29:02:1c:e7   txqueuelen 1000  (Ethernet)

         RX packets 1008  bytes 75053  (73.2 KiB)

         RX errors 0  dropped 0  overruns 0   frame 0

         TX packets 358  bytes 45826  (44.7 KiB)

         TX errors 0  dropped 0 overruns  0  carrier 0  collisions 0

 

lo:  flags=73<UP,LOOPBACK,RUNNING>   mtu 65536

         inet 127.x.0.1  netmask  255.0.0.0

         inet6 ::1  prefixlen 128  scopeid 0x10<host>

         loop  txqueuelen 0  (Local Loopback)

         RX packets 778  bytes 66180  (64.6 KiB)

         RX errors 0  dropped 0  overruns 0   frame 0

         TX packets 778  bytes 66180  (64.6 KiB)

         TX errors 0  dropped 0 overruns  0  carrier 0  collisions 0

 

 

 

2.常用命令

 

命令的使用可以单独一个命令,也可以后面跟参数使用。加参数使用,往往功能更加强悍。由于参数众多,所以本文档只介绍常用命令的简单使用,参数的使用规则可以用前面我们说的帮助类命令查看。

 

注:

一些命令有可能不能使用,因为没有安装此命令的包,所以,书写正确的命令但报错时,请检查是否安装命令相关包。

检查date命令属于哪个软件包:

[root@freeit ~]# yum provides date

已加载插件:langpacks, product-id, subscription-manager

This system is not registered to Red Hat  Subscription Management. You can use subscription-manager to register.

coreutils-8.22-11.el7.x86_64 : A set of basic GNU tools commonly used in

                             : shell scripts

    @anaconda/7.x

匹配来源:

文件名    /usr/bin/date

 

 

 

2.1.系统类命令

 

 

2.1.1.data    显示日期命令

 

例:查看当前时间

[root@freeit ~]# date

2015 04 28  星期二 12:34:54 CST

 

 

2.1.2.cal    列出当前月份的日历

[root@freeit ~]# cal

      April 2015    

Su Mo Tu We Th Fr Sa

           1  2  3  4

 5   6  7  8  9  10 11

12 13 14 15 16 17 18

19 20 21 22 23 24 25

26 27 28 29 30

参数:

    -1:显示当前一个月的日历

    -3:显示前一个月、本月、下一个月日历

    -s:周日作为第一天显示

    -m:周一作为第一天显示

    -j:输出的日期为一年的第几天

    -y:显示本年度全年日历

    -V:显示当前日历版本

 

 

2.1.3.bc    简单的计算器

 

[root@freeit ~]# bc

bc 1.06.95

Copyright 1991-1994, 1997, 1998, 2000,2004, 2006 Free Software Foundation, Inc.

This is free software with ABSOLUTELY NOWARRANTY.

For details type `warranty'.

10*10

100

//计算10x10的结果

^C

(interrupt) Exiting bc.

//ctrl+c退出计算器。

 

 

2.1.4.ctrl+c    中断当前程序

 

如上个实验:退出计算器

 

 

2.1.5.wc    列出文件字节数

 

此命令可列出文件行数、单词数、字节数

例:查看/etc/passwd文件的内容

[root@freeit ~]# wc /etc/passwd

   41   70 1990 /etc/passwd

//一共41行,70个单次,1990个字节

 

-c----查看总的字节数

-w—查看总的单词数

-l ----查看总的行数

 

 

2.1.6.hostname   查看和修改主机名

 

  • 查看主机名

[root@freeit ~]# hostname

freeit.example.com

 

  • 修改主机名

在之前学习的RHEL5.x&6.x系统中,主机名保存文件为/etc/sysconfig/network,修改主机名可以修改此文件,但是要重启系统或者不重启,同时用hostname命令修改当前主机名即可。但是在RHEL7.x的系统中,主机名的配置文件为/etc/hostname.修改主机名的方法也多种多样。如下

 

  • hostname命令修改

---------------------------------------------------先查看此时的主机名----------------------------------

[root@freeit ~]# hostname

freeit.example.com

----------------------------------------------------修改并查看---------------------------------------

[root@freeit ~]# hostname gyh.example.com

[root@freeit ~]# hostname

gyh.example.com

 

  • 修改配置文件

RHEL7.x之前的系统,修改配置文件之后,用hostname查看,主机名不变。要重启才能生效,而7.x的系统,修改配置文件之后,同时用hostname查看,主机名与配置文件实现了同步,这也更加说明了Linuxwindows对比的强势,基本上不用重启

 

-------------------------------查看此时主机名配置文件内容及此时的主机名----------------------[root@freeit ~]# cat /etc/hostname

freeit.example.com

[root@freeit ~]# hostname

freeit.example.com

-----------------------------------------修改配置文件并查看此时的主机名-----------------------------

[root@freeit ~]# cat /etc/hostname

gyh.example.com

[root@freeit ~]# hostname

gyh.example.com

 

  • nmtui-hostname

把主机名修改回freeit开头

使用此命令后弹出如下对话框



wKioL1ckNsugSBiyAAAZkaps6EM244.png

直接填写并选择OK】退出

查看主机名

[root@freeit ~]# hostname

freeit.example.com

[root@freeit ~]# cat /etc/hostname

freeit.example.com

如上,不仅修改了主机名,同时也修改了配置文件

 

  • hostnamectl

把主机名改回gyh开头

[root@freeit ~]# hostnamectl set-hostname  gyh.example.com

[root@freeit ~]# hostname

gyh.example.com

[root@freeit ~]# cat /etc/hostname

gyh.example.com

同样:不仅修改了主机名,同时也修改了配置文件

 

 

2.1.7.uname    查看系统信息(版本&内核)

 

例:

[root@freeit ~]# uname

Linux

参数说明:

[root@freeit ~]# uname --help

   -a, --all                显示系统所有信息

   -s, --kernel-name        显示系统内核名

   -n, --nodename         显示网络节点主机名(即显示主机名)

   -v, --kernel-version       显示内核版本

   -m, --machine           查看硬件

   -i, --hardware-platform    查看硬件平台

 

 

2.1.8.time    量测特定指令执行时所需消耗的时间及系统资源等资讯

 

例:

[root@freeit ~]# time

 

real     0m0.000s

user     0m0.000s

sys      0m0.000s

 

 

2.1.9.clear    清屏

 

说明:此命令可以清除当前屏幕的所有内容,只需输入clear回车即可。不做过多说明。

 

注:ctrl+l快捷键也能起到清屏的作用,更加快捷,方便。

 

 

2.1.10.whoami    查看当前用户

例:

 [root@freeit~]#  whoami

root

//当前用户为root

 

 

2.1.11.查看当前已登录的用户

 

[root@freeit ~]# w

 09:55:21 up   1:44,  3 users,  load average: 0.00, 0.00, 0.00

USER      TTY      FROM              LOGIN@   IDLE    JCPU   PCPU WHAT

root      pts/0    192.168.10.1     08:13     1.00s  0.60s  0.13s w

root      pts/1    192.168.10.1     08:45     4:26   0.24s  0.24s -bash

root      tty1     -                08:53   48:48    6.79s  0.31s -bash

[root@freeit ~]# who

root      pts/0        2015-04-24 08:13  (192.168.10.1)

root      pts/1        2015-04-24 08:45  (192.168.10.1)

root      tty1         2015-04-24 08:53

 

 

2.1.12.halt&reboot    关机重启

 

Halt为关机命令,reboot为重启。不做过多说明,请自行实验

 

 

2.1.13.列出所有语系

 

[root@freeit ~]# locale -a

aa_DJ

aa_DJ.iso88591

aa_DJ.utf8

aa_ER

aa_ER@saaho

aa_ER.utf8

aa_ER.utf8@saaho

aa_ET

aa_ET.utf8

……



2.1.14.修改语言

 

--------------------------------------------------修改之前-----------------------------------------------

[root@freeit ~]# rm --help

用法:rm [选项]... 文件...

Remove (unlink) the FILE(s).

 

   -f, --force           ignore  nonexistent files and arguments, never prompt

   -i                    prompt  before every removal

   -I                    prompt  once before removing more than three files, or

                          when removing recursively; less  intrusive than -i,

                          while still giving  protection against most mistakes

       --interactive[=WHEN]  prompt  according to WHEN: never, once (-I), or

                          always (-i); without  WHEN, prompt always

       --one-file-system         递归删除一个层级时,跳过所有不符合命令行参

                                数的文件系统上的文件

       --no-preserve-root  do not treat  '/' specially

       --preserve-root   do not remove  '/' (default)

   -r, -R, --recursive   remove directories  and their contents recursively

   -d, --dir             remove  empty directories

   -v, --verbose         explain  what is being done

       --help            显示此帮助信息并退出

       --version         显示版本信息并退出

 

默认时,rm 不会删除目录。使用--recursive(-r -R)选项可删除每个给定

的目录,以及其下所有的内容。

 

To remove a file whose name starts with a  '-', for example '-foo',

use one of these commands:

   rm -- -foo

 

   rm ./-foo

 

请注意,如果使用rm 来删除文件,通常仍可以将该文件恢复原状。如果想保证

该文件的内容无法还原,请考虑使用shred

 

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>

请向<http://translationproject.org/team/zh_CN.html> 报告rm 的翻译错误

要获取完整文档,请运行:info coreutils 'rm invocation'

-----------------------------------------------修改之后---------------------------------------------------

[root@freeit ~]# LANG=en

[root@freeit ~]# rm --help

Usage: rm [OPTION]... FILE...

Remove (unlink) the FILE(s).

 

   -f, --force           ignore  nonexistent files and arguments, never prompt

   -i                    prompt  before every removal

   -I                    prompt  once before removing more than three files, or

                          when removing  recursively; less intrusive than -i,

                          while still giving  protection against most mistakes

       --interactive[=WHEN]  prompt  according to WHEN: never, once (-I), or

                          always (-i);  without WHEN, prompt always

       --one-file-system  when removing  a hierarchy recursively, skip any

                          directory that is  on a file system different from

                          that of the corresponding  command line argument

       --no-preserve-root  do not treat  '/' specially

       --preserve-root   do not remove  '/' (default)

   -r, -R, --recursive   remove  directories and their contents recursively

   -d, --dir             remove empty directories

   -v, --verbose         explain  what is being done

       --help     display this help and  exit

       --version  output version  information and exit

 

By default, rm does not remove  directories.  Use the --recursive (-r  or -R)

option to remove each listed directory,  too, along with all of its contents.

 

To remove a file whose name starts with a  '-', for example '-foo',

use one of these commands:

   rm -- -foo

 

   rm ./-foo

 

Note that if you use rm to remove a file,  it might be possible to recover

some of its contents, given sufficient  expertise and/or time.  For greater

assurance that the contents are truly  unrecoverable, consider using shred.

 

GNU coreutils online help:  <http://www.gnu.org/software/coreutils/>

Report rm translation bugs to  <http://translationproject.org/team/>

For complete documentation, run: info  coreutils 'rm invocation'

 

 

2.1.15.CPU查看

 

1:查看CPU信息

[root@freeit ~]# more /proc/cpuinfo

processor       : 0

vendor_id       : GenuineIntel

cpu family      : 6

model           : 60

model name      : Intel(R) Core(TM) i5-4210M CPU @  2.60GHz

stepping        : 3

microcode       : 0x17

cpu MHz         : 2594.080

cache size      : 3072 KB

……

 

2CPU运行位数

[root@freeit ~]# getconf LONG_BIT

64

 

3:查看CPU型号和逻辑核心数

[root@freeit ~]# cat /proc/cpuinfo |grep  name |cut -f2 -d: |uniq -c

       2  Intel(R) Core(TM) i5-4210M  CPU @ 2.60GHz

 

4:查看物理CPU个数

[root@freeit ~]# cat /proc/cpuinfo |grep  physical |uniq -c

       1 physical id     : 0

       1 address sizes   : 40 bits  physical, 48 bits virtual

 

5:验证是否支持64位,结果大于0支持64

[root@freeit ~]# cat /proc/cpuinfo |grep  flags |grep 'lm' |wc -l

1

 

6:查看CPU是否支持虚拟化

[root@freeit ~]# cat /proc/cpuinfo |grep  flags

flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca  cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm  constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc  aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic  movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm ida arat epb  xsaveopt pln pts dtherm fsgsbase smep

注:pae支持半虚拟化。Intel VT支持全虚拟化。

 

7:查看内存信息

[root@freeit ~]# more /proc/meminfo

MemTotal:        1010788 kB

MemFree:          729532 kB

MemAvailable:     737372 kB

Buffers:            1080 kB

Cached:           114456 kB

SwapCached:            0 kB

Active:            88088 kB

Inactive:          86136 Kb

……

 

8:查看全面硬件信息

[root@freeit ~]# dmidecode |less

# dmidecode 2.12

SMBIOS 2.4 present.

364 structures occupying 16582 bytes.

Table at 0x000E0010.

 

Handle 0x0000, DMI type 0, 24 bytes

BIOS Information

         Vendor: Phoenix Technologies LTD

         Version: 6.00

         Release Date: 07/31/2013

         Address: 0xEA050

         Runtime Size: 90032 bytes

         ROM Size: 64 kB

         Characteristics:

……

 

9:查看服务器型号

[root@freeit ~]# dmidecode |grep  "Product Name"

         Product Name: VMware Virtual Platform

         Product Name: 440BX Desktop Reference Platform

 

10:查看软硬raid信息

-------------------------------------------------查看软raid信息------------------------------------------

[root@freeit ~]# cat /proc/mdstat

Personalities :

unused devices: <none>

--------------------------------------------------查看硬raid信息--------------------------------------------

[root@freeit ~]# cat /proc/scsi/scsi

Attached devices:

Host: scsi4 Channel: 00 Id: 00 Lun: 00

   Vendor: VMware,  Model: VMware  Virtual S Rev: 1.0

   Type:   Direct-Access                    ANSI  SCSI revision: 02

Host: scsi4 Channel: 00 Id: 01 Lun: 00

   Vendor: VMware,  Model: VMware  Virtual S Rev: 1.0

   Type:   Direct-Access                    ANSI  SCSI revision: 02

Host: scsi4 Channel: 00 Id: 02 Lun: 00

   Vendor: VMware,  Model: VMware  Virtual S Rev: 1.0

   Type:   Direct-Access                    ANSI  SCSI revision: 02

Host: scsi4 Channel: 00 Id: 03 Lun: 00

   Vendor: VMware,  Model: VMware  Virtual S Rev: 1.0

   Type:   Direct-Access                    ANSI  SCSI revision: 02

Host: scsi4 Channel: 00 Id: 04 Lun: 00

  Vendor:  VMware,  Model: VMware Virtual S Rev:  1.0

   Type:   Direct-Access                    ANSI  SCSI revision: 02

Host: scsi3 Channel: 00 Id: 00 Lun: 00

   Vendor: NECVMWar Model: VMware SATA CD01 Rev: 1.00

   Type:   CD-ROM                           ANSI  SCSI revision: 05

 

11:查看硬件信息

[root@freeit ~]# lspci

00:00.0 Host bridge: Intel Corporation  440BX/ZX/DX - 82443BX/ZX/DX Host bridge (rev 01)

00:01.0 PCI bridge: Intel Corporation  440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 01)

00:07.x ISA bridge: Intel Corporation  82371AB/EB/MB PIIX4 ISA (rev 08)

00:07.1 IDE interface: Intel Corporation  82371AB/EB/MB PIIX4 IDE (rev 01)

00:07.3 Bridge: Intel Corporation  82371AB/EB/MB PIIX4 ACPI (rev 08)

00:07.7 System peripheral: VMware Virtual  Machine Communication Interface (rev 10)

00:0f.0 VGA compatible controller: VMware  SVGA II Adapter

00:10.0 SCSI storage controller: LSI  Logic / Symbios Logic 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)

……………………

 

12:查看开机信息

[root@freeit ~]# dmesg |less

[    0.000000] Initializing cgroup subsys  cpuset

[     0.000000] Initializing cgroup subsys cpu

[     0.000000] Initializing cgroup subsys cpuacct

[     0.000000] Linux version 3.10.0-121.el7.x86_64  (mockbuild@x86-021.build.eng.bos.redhat.com) (gcc version 4.8.2 20140120 (Red  Hat 4.8.2-16) (GCC) ) #1 SMP Tue Apr 8 10:48:19 EDT 2014

[     0.000000] Command line: BOOT_IMAGE=/vmlinuz-3.10.0-121.el7.x86_64  root=UUID=49bd8af3-32fb-446a-9104-b562640e5129 ro rd.lvm.lv=rhel/root  crashkernel=auto rd.lvm.lv=rhel/swap vconsole.font=latarcyrheb-sun16  vconsole.keymap=us net.ifnames=0 biosdevname=0 rhgb quiet

……

 

 

2.2.目录操作命令

 

2.2.1.ls    列出目录下的内容及属性信息

 

[root@freeit ~]# ls /root

1                Documents    install.log.syslog  Public

anaconda-ks.cfg  Downloads     Music               Templates

Desktop          install.log  Pictures            Videos

 

 

2.2.2.pwd    列出用户当前所处目录路径

 

[root@freeit www]# pwd

/var/www

 

 

2.2.3.du    列出目录或文件占用磁盘空间的大小

 

------------------------------------查看/var/www这个目录占用的空间大小---------------------

[root@freeit www]# du

16       ./error/include

212      ./error

4        ./cgi-bin

4        ./html

260      ./icons/small

944      ./icons

1168     .

<默认单位为K>

----------------------------------------参数说明----------------------------------

-h:以可读方式显示(带单位显示)

[root@freeit www]# du -h

16K      ./error/include

212K     ./error

4.0K     ./cgi-bin

4.0K     ./html

260K     ./icons/small

944K     ./icons

1.2M    .

 

-s:只显示总大小

[root@freeit www]# du -sh

1.2M     .

 

 

 

2.2.4.cd    改变用户的当前目录

 

------------------------------------/var/www回到/root目录------------------------

[root@freeit www]# pwd

/var/www

[root@freeit www]# cd /root

[root@freeit ~]# pwd

/root

 

注:

  • 不带参数是回到自己的家目录

  • cd – 回到上个目录

 

 

2.2.5.mkdir    建立一个新目录及多级目录

 

--------------------------------------root下创建一个gyh目录------------------------------------

[root@freeit ~]# mkdir /root/gyh

[root@freeit ~]# ls /root

1                Documents  install.log         Pictures   Videos

anaconda-ks.cfg  Downloads   install.log.syslog  Public

Desktop          gyh        Music               Templates

 

注:如果创建的父级目录不存在,可以使用递归创建参数:-p

[root@freeit ~]# mkdir /root/gyh/aaa

mkdir: cannot create directory  ‘/root/gyh/aaa’: No such file or directory

[root@freeit ~]# mkdir -p /root/gyh/aaa

[root@freeit ~]# ls

1   anaconda-ks.cfg  gyh  ……

-pparents,递归创建需要的父目录

 

 

2.2.6.rmdir    删除一个空目录(无法删除一个非空目录)

例:

-------------------------------------删除非空目录gyh------------------------

[root@freeit ~]# rmdir /root/gyh/

rmdir: failed to remove ‘/root/gyh’:  Directory not empty

--------------------------------------删除空目录aaa-------------------------------

[root@freeit ~]# ls /root/gyh/

aaa

[root@freeit ~]# rmdir /root/gyh/aaa

[root@freeit ~]# ls /root/gyh/

 

 

 

2.3.文件操作命令

 

 

2.3.1.df    报告文件系统的总容量、使用量、剩余量、挂载情况

 

-----------------------------------------查看sda的使用情况--------------------------------

[root@freeit ~]# df /dev/sda

Filesystem           1K-blocks      Used     Available       Use%    Mounted on

-                   315904        212     315692          1%     /dev

 

 

 

2.3.2.find    在指定路径查找文件

 

1:查找/目录下user1用户的所有文件,并拷贝到/root/findfile

 [root@freeit  ~]#find / -user user1 –exec /bin/cp –rf {} /root/findfile \;

 

参数说明:

     -user:按文件属主查找

    -name:按文件名字查找

    -group:按文件属组查找

    -perm:按文件权限查找

    -atime –n:使用时间在N天以内

    -atime +n:使用时间在N天以前

    -mtime –n:内容改变时间在N天以内

    -mtime  +n:内容改变时间在N天以前

    -ctime  -n:文件状态改变时间在N天内

    -ctime +n:文件状态改变时间在N天前

     -size+1000000c –print :查找文件长度大于1M字节的文件

注:

  • Linux文件无创建时间

  • Access为使用时间

  • Modify为内容修改时间

  • Change为状态改变时间(权限、属主)

 

2:查找user1的所有文件

[root@freeit ~]# find / -user user1

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

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

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

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

/tmp/user1

/var/spool/mail/user1

/home/user1

/home/user1/.mozilla

/home/user1/.mozilla/extensions

/home/user1/.mozilla/plugins

/home/user1/.bash_logout

/home/user1/.bash_profile

/home/user1/.bashrc

/home/user1/.cache

/home/user1/.cache/abrt

/home/user1/.cache/abrt/lastnotification

/home/user1/.config

/home/user1/.config/abrt

/home/user1/.bash_history

 

 

2.3.3.whereis&which

 

whereis:查找一个命令相关信息放在那里(查找命令的目录)

which:查看当前要执行的命令所在的路径;

---------------------------------------查找ls命令的存放目录----------------------------------

[root@freeit ~]# whereis ls

ls: /bin/ls   /usr/share/man/man1p/ls.1p.gz  /usr/share/man/man1/ls.1.gz

---------------------------------------查看ls命令所在路径-------------------------------------------

[root@freeit ~]# which ls

alias ls='ls --color=auto'

         /usr/bin/ls

 

 

2.3.4.grep     指定文件中查找指定的字符串

 

-----------------------------过滤出/etc/passwduser1用户所在行----------------------------

[root@freeit ~]# cat /etc/passwd |grep  user1

user1:x:501:501::/home/user1:/bin/bash

 

 

 

2.3.5.cat    连续显示、查看文件内容

 

通俗讲就是:本命令以不可编辑文本方式显示文件的内容(Vim是可以编辑的)

----------------------------------查看/etc/passwd文件内容------------------------------------

[root@freeit tmp]# cat /etc/passwd

root:x:0:0:root:/root:/bin/bash

bin:x:1:1:bin:/bin:/sbin/nologin

daemon:x:2:2:daemon:/sbin:/sbin/nologin

adm:x:3:4:adm:/var/adm:/sbin/nologin

lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

sync:x:5:0:sync:/sbin:/bin/sync

shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

halt:x:7:0:halt:/sbin:/sbin/halt

mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin

operator:x:11:0:operator:/root:/sbin/nologin

games:x:12:100:games:/usr/games:/sbin/nologin

gopher:x:13:30:gopher:/var/gopher:/sbin/nologin

ftp:x:14:50:FTP  User:/var/ftp:/sbin/nologin

nobody:x:99:99:Nobody:/:/sbin/nologin

dbus:x:81:81:System message  bus:/:/sbin/nologin

usbmuxd:x:113:113:usbmuxd  user:/:/sbin/nologin

rpc:x:32:32:Rpcbind  Daemon:/var/cache/rpcbind:/sbin/nologin

oprofile:x:16:16:Special user account to  be used by OProfile:/home/oprofile:/sbin/nologin

vcsa:x:69:69:virtual console memory  owner:/dev:/sbin/nologin

rtkit:x:499:496:RealtimeKit:/proc:/sbin/nologin

avahi-autoipd:x:170:170:Avahi IPv4LL  Stack:/var/lib/avahi-autoipd:/sbin/nologin

abrt:x:173:173::/etc/abrt:/sbin/nologin

haldaemon:x:68:68:HAL  daemon:/:/sbin/nologin

saslauth:x:498:76:"Saslauthd  user":/var/empty/saslauth:/sbin/nologin

postfix:x:89:89::/var/spool/postfix:/sbin/nologin

rpcuser:x:29:29:RPC Service  User:/var/lib/nfs:/sbin/nologin

nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin

gdm:x:42:42::/var/lib/gdm:/sbin/nologin

ntp:x:38:38::/etc/ntp:/sbin/nologin

apache:x:48:48:Apache:/var/www:/sbin/nologin

mysql:x:27:27:MySQL  Server:/var/lib/mysql:/bin/bash

pulse:x:497:494:PulseAudio System  Daemon:/var/run/pulse:/sbin/nologin

xguest:x:500:500:Guest:/home/xguest:/bin/bash

sabayon:x:86:86:Sabayon  user:/home/sabayon:/sbin/nologin

sshd:x:74:74:Privilege-separated  SSH:/var/empty/sshd:/sbin/nologin

tcpdump:x:72:72::/:/sbin/nologin

named:x:25:25:Named:/var/named:/sbin/nologin

dhcpd:x:177:177:DHCP  server:/:/sbin/nologin

user1:x:501:501::/home/user1:/bin/bash

user2:x:502:502::/home/user2:/bin/bash

 

 

 

2.3.6.more    分页查看文件内容

 

由于无法以图文演示本命令,请自行验证。

注:Ctrl+b向上翻一页

Ctrl+m向下翻一行

空格,向下翻一页

 

 

2.3.7.less    分页可控制查看文件内容

 

说明:当我们直接在真机上使用命令时,有时候查看一个文件或目录内容(一页显示不完),系统默认全部显示,但是不能像windows一样上下滚动显示。

我们可以利用less命令一页一页的显示,但是也是不可逆的,不能往回看

 

:查看/etc/passwd内容

[root@freeit ~]# less /etc/passwd



wKiom1ckNfyjH8JaAABqDZCsUCI566.png

按空格键向下翻页。

 

 

2.3.8.cp    复制文件或目录

 

例:

----------------------------------复制/etc/passwd/tmp--------------------------------------

[root@freeit tmp]# pwd

/tmp

[root@freeit tmp]# ls

[root@freeit tmp]# cp /etc/passwd .

[root@freeit tmp]# ls

passwd

常用参数:

-p:带权限复制

 

 

2.3.9.mv    移动文件或目录

 

此命令的使用与windows中的剪切命令功能一样。但是在Linux中,移动的同时,也可以改名。

---------------------------------------/root下的gyh文件移动到/tmp------------------------

[root@freeit tmp]# ls /root/

1   anaconda-ks.cfg  gyh  ……

[root@freeit tmp]# mv /root/gyh   /tmp/

[root@freeit tmp]# ls

gyh   passwd

--------------------------------------/tmp下的gyh改名为gyh.bak----------------------------

[root@freeit tmp]# mv gyh gyh.bak

[root@freeit tmp]# ls

gyh.bak   passwd

[root@freeit tmp]#

 

 

2.3.10.rm  删除文件或非空目录

 

------------------------------------------删除/tmp文件下的passwd--------------------------

[root@freeit tmp]# pwd

/tmp

[root@freeit tmp]# ls

gyh.bak   passwd

[root@freeit tmp]# rm passwd

rm: remove regular file ‘passwd’? y

[root@freeit tmp]# ls

gyh.bak

//删除成功

 

常用参数:

-r:删除目录

-f:强制删除,不提示直接删除

 

 

2.3.11.touch    建立空文件

 

-----------------------------------/tmp目录下创建一个空文件gyh-----------------------------------

[root@freeit tmp]# pwd

/tmp

[root@freeit tmp]# touch gyh

[root@freeit tmp]# ls

gyh

 

 

 

2.3.12.head    显示文件头几行

 

例:查看/etc/passwd文件的前10行内容,对照上面cat显示的内容验证

[root@freeit tmp]# head  /etc/passwd |nl

      1   root:x:0:0:root:/root:/bin/bash

      2   bin:x:1:1:bin:/bin:/sbin/nologin

      3   daemon:x:2:2:daemon:/sbin:/sbin/nologin

      4   adm:x:3:4:adm:/var/adm:/sbin/nologin

      5   lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

     6   sync:x:5:0:sync:/sbin:/bin/sync

      7   shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

      8   halt:x:7:0:halt:/sbin:/sbin/halt

      9   mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

     10   uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin

 

注:

  • nl为显示行号

 

 

2.3.13.tail    显示文件尾几行

 

例:查看/etc/passwd文件的后10行内容,参照cat显示内容

 [root@freeit  tmp]# tail /etc/passwd |nl

      1  mysql:x:27:27:MySQL  Server:/var/lib/mysql:/bin/bash

      2  pulse:x:497:494:PulseAudio  System Daemon:/var/run/pulse:/sbin/nologin

      3   xguest:x:500:500:Guest:/home/xguest:/bin/bash

      4  sabayon:x:86:86:Sabayon  user:/home/sabayon:/sbin/nologin

      5   sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

      6   tcpdump:x:72:72::/:/sbin/nologin

      7  named:x:25:25:Named:/var/named:/sbin/nologin

      8  dhcpd:x:177:177:DHCP  server:/:/sbin/nologin

      9   user1:x:501:501::/home/user1:/bin/bash

     10   user2:x:502:502::/home/user2:/bin/bash

 

 

2.4.ln   链接

 

 

2.4.1.软链接

 

软链接也叫做符号链接,相当于windows中的快捷方式。做完链接之后,链接文件的大小不变,不管源文件怎么变化。

-------------------------------------------/mnt目录下创建gyh.text文件----------------------------------

[root@freeit tmp]# touch /mnt/gyh.text

[root@freeit tmp]# ll /mnt/

total 0

-rw-r--r--. 1 root root 0 Apr 28 19:11  gyh.text

//大小为0

------------------------------------------把此文件连接到/tmp下并查看大小-----------------------------

[root@freeit tmp]# ln -s /mnt/gyh.text  ./gyh

[root@freeit tmp]# ll

total 0

lrwxrwxrwx. 1 root root 13 Apr 28 19:25 gyh ->  /mnt/gyh.text

链接之后大小为13K

------------------------------------------向源文件中导入内容-------------------------------------------------

[root@freeit tmp]# cat /etc/inittab  >/mnt/gyh.text

[root@freeit tmp]# ll /mnt/gyh.text

-rw-r--r--. 1 root root 491 Apr 28 19:31 /mnt/gyh.text

//大小变为491

-------------------------------------------查看连接文件/tmp/gyh的大小------------------------------------

[root@freeit tmp]# ll

total 0

lrwxrwxrwx. 1 root root 13 Apr 28 19:25 gyh ->  /mnt/gyh.text

//链接文件的大小没有变

注:

软连接相当于windows中的快捷方式,源文件删除之后,链接即失效。

 

 

2.4.2.硬链接

 

硬链接主要用于同步备份使用,源文件的大小变化,也会同步到链接文件。

---------------------------------/mnt目录下创建gyh.text文件--------------------------------------------------

[root@freeit tmp]# touch /mnt/gyh.text

[root@freeit tmp]# ls /mnt/

gyh.text

---------------------------------把此文件硬链接到/tmp-------------------------------------------------------

[root@freeit tmp]# ln -n /mnt/gyh.text  /tmp/gyh

[root@freeit tmp]# ll

total 0

-rw-r--r--. 2 root root 0 May   3 19:33 gyh

//大小为0

-----------------------------------------向源文件gyh.text导入内容------------------------------------------

[root@freeit tmp]# cat /etc/passwd  >/mnt/gyh.text      

[root@freeit tmp]# ll /mnt

total 4

-rw-r--r--. 2 root root 1926 May  3 19:36 gyh.text

//源文件导入内容后大小发生变化:1926

----------------------------------------------查看链接文件的大小----------------------------------------------

[root@freeit tmp]# ll

total 4

-rw-r--r--. 2 root root 1926 May  3 19:36 gyh

//大小与源文件一样,同步增长

-----------------------------------------------删除源文件,验证连接文件是否还能用--------------------

[root@freeit tmp]# rm -rf /mnt/gyh.text

[root@freeit tmp]# cat gyh

root:x:0:0:root:/root:/bin/bash

bin:x:1:1:bin:/bin:/sbin/nologin

daemon:x:2:2:daemon:/sbin:/sbin/nologin

adm:x:3:4:adm:/var/adm:/sbin/nologin

lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

sync:x:5:0:sync:/sbin:/bin/sync

shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

halt:x:7:0:halt:/sbin:/sbin/halt

mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

operator:x:11:0:operator:/root:/sbin/nologin

games:x:12:100:games:/usr/games:/sbin/nologin

ftp:x:14:50:FTP  User:/var/ftp:/sbin/nologin

nobody:x:99:99:Nobody:/:/sbin/nologin

dbus:x:81:81:System message  bus:/:/sbin/nologin

polkitd:x:999:998:User for  polkitd:/:/sbin/nologin

unbound:x:998:997:Unbound DNS  resolver:/etc/unbound:/sbin/nologin

colord:x:997:996:User for colord:/var/lib/colord:/sbin/nologin

usbmuxd:x:113:113:usbmuxd  user:/:/sbin/nologin

avahi:x:70:70:Avahi mDNS/DNS-SD  Stack:/var/run/avahi-daemon:/sbin/nologin

avahi-autoipd:x:170:170:Avahi IPv4LL  Stack:/var/lib/avahi-autoipd:/sbin/nologin

saslauth:x:996:76:"Saslauthd  user":/run/saslauthd:/sbin/nologin

qemu:x:107:107:qemu user:/:/sbin/nologin

libstoragemgmt:x:995:994:daemon account  for libstoragemgmt:/var/run/lsm:/sbin/nologin

rpc:x:32:32:Rpcbind  Daemon:/var/lib/rpcbind:/sbin/nologin

rpcuser:x:29:29:RPC Service  User:/var/lib/nfs:/sbin/nologin

nfsnobody:x:65534:65534:Anonymous NFS  User:/var/lib/nfs:/sbin/nologin

rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin

radvd:x:75:75:radvd user:/:/sbin/nologin

ntp:x:38:38::/etc/ntp:/sbin/nologin

chrony:x:994:993::/var/lib/chrony:/sbin/nologin

abrt:x:173:173::/etc/abrt:/sbin/nologin

pulse:x:171:171:PulseAudio System  Daemon:/var/run/pulse:/sbin/nologin

gdm:x:42:42::/var/lib/gdm:/sbin/nologin

gnome-initial-setup:x:993:991::/run/gnome-initial-setup/:/sbin/nologin

postfix:x:89:89::/var/spool/postfix:/sbin/nologin

sshd:x:74:74:Privilege-separated  SSH:/var/empty/sshd:/sbin/nologin

tcpdump:x:72:72::/:/sbin/nologin

freeit_gyh:x:1000:1000:freeit_gyh:/home/freeit_gyh:/bin/bash

//源文件删除之后,链接文件仍然可用,由此可以看出,硬链接的文件也能起到备份的作用

 

 

2.5.权限操作

 

 

2.5.1.文件权限介绍

 

格式:(-rw-r--r--

权限项

文件类型

执行

执行

执行

字符表示

()

(r)

(w)

(x)

(r)

(w)

(x)

(r)

(w)

(x)

数字表示


4

2

1

4

2

1

4

2

1

权限分配


文件所有者

文件所属组

其他用户

 

 

2.5.2.文件属性介绍

 

[root@freeit ~]# ls -l /etc/passwd

-rw-r--r--. 1 root root 1926 Dec 11 22:59  /etc/passwd

 

 

  • -rw-r--r--:权限

  • .:引用计数

  • root:所有者

  • root:所属组

  • 1926:文件大小,单位K

  • Dec 11 22:59:创建时间

  • /etc/passwd:文件名字

 

 

2.5.3.权限操作命令

 

  • chmod命令:根据文件访问权限的字母以及对应的数值用来设置访问权限的数值。

chmod [OPTION]... MODE[,MODE]... FILE...

  • 使用数值改变文件权限:

#chmod 777 file1

  • 使用字母来改变文件的权限:

参数设置

a 所有用户

u 创建者

g 同组用户

o 其他用户,除去创建者和同组用户之外的用户

+ 增加权限

清除权限

= 设置唯一权限

常用设置

g+w -- 增加组用户的写权限

o-rwx -- 清除其他用户的全部访问权限

u+x -- 允许文件属主执行文件

a+rw -- 允许所有用户读和写文件

ug+r -- 允许文件属主和属组用户读文件

g=rx -- 设置属组用户只能读和执行文件(不可写)

通过增加 -R 参数(递归),可以改变整个目录树的权限。

#chmod o+w sneakers.txt

#chmod go-rw sneakers.txt

#chmod a-rw sneakers.txt

 

例:创建一个文件/tmp/onepice.txt,修改权限,所有者rwx,所属组和其他用户rw权限

[root@freeit tmp]# chmod u=rwx  onepice.txt

[root@freeit tmp]# ll

total 0

-rwxr--r-x. 1 root root 0 May  6 08:29 onepice.txt

[root@freeit tmp]# chmod g+rw onepice.txt  

[root@freeit tmp]# ll

total 0

-rwxrw-r-x. 1 root root 0 May  6 08:29 onepice.txt

[root@freeit tmp]# chmod o+rw onepice.txt  

[root@freeit tmp]# ll

total 0

-rwxrw-rwx. 1 root root 0 May  6 08:29 onepice.txt

注:权限的附加,可以使用“+”,也可以使用“=”

 

 

2.5.4.ACL权限

 

命令:

getfacl:查看文件的acl权限。

setfacl:设置文件的acl权限。

 

简介:

使用chmod命令,可以为文件设置权限,设置对象有宿主、所属组、其他用户。但是,chmod设置的权限是大方向的,并不能针对具体的用户进行权限的设置,所以引入了acl权限。具体使用看下面的例子

例:依然拿上面的onepice.txt文件为例,查看其acl权限,然后针对具体用户设置:user1用户只有读(r)的权限,user2用户有读写(rw)的权限。

[root@freeit tmp]# pwd

/tmp

[root@freeit tmp]# ls

onepice.txt

[root@freeit tmp]# getfacl onepice.txt

# file: onepice.txt      //文件名

# owner: root        //文件所有者

# group: root        //文件所属组

user::rwx           //文件所有者的权限

group::rw-         //文件所属组的权限

other::rwx        //其他用户对文件的权限

-------------------------------------------针对user1user2设置acl---------------------------------------------

[root@freeit tmp]# setfacl -m u:user1:r--  onepice.txt

//user1设置acl权限

[root@freeit tmp]# setfacl -m u:user2:rw-  onepice.txt  

//user2设置acl权限

[root@freeit tmp]# getfacl  onepice.txt               

# file: onepice.txt

# owner: root

# group: root

user::rwx

user:user1:r--         //user1只有读的权限

user:user2:rw-        //user2只有rw权限

group::rw-

mask::rw-

other::rwx

---------------------------------------------验证-----------------------------------------------------------

[root@freeit tmp]# su user1

[user1@freeit tmp]$ cat onepice.txt

[user1@freeit tmp]$

//user1可以查看,由于文件为空,所以查看内容为空

[user1@freeit tmp]$ head /etc/passwd  >onepice.txt

bash: onepice.txt: Permission denied

//写入内容被拒绝,无权限

 

[root@freeit tmp]# su user2

 [user2@freeit tmp]$ head /etc/passwd  >onepice.txt

[user2@freeit tmp]$ cat onepice.txt              

root:x:0:0:root:/root:/bin/bash

bin:x:1:1:bin:/bin:/sbin/nologin

daemon:x:2:2:daemon:/sbin:/sbin/nologin

adm:x:3:4:adm:/var/adm:/sbin/nologin

lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

sync:x:5:0:sync:/sbin:/bin/sync

shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

halt:x:7:0:halt:/sbin:/sbin/halt

mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

operator:x:11:0:operator:/root:/sbin/nologin

//user2可以写入内容,并且能够查看,有读写的权限