第一周第五次课

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第一周第五次课相关的知识,希望对你有一定的参考价值。

2.1系统目录结构

2.1.1 ls【list 列出当前目录下的目录或者文件】

[[email protected] ~]# ls

anaconda-ks.cfg  mkdir

【比如直接ls就是列出当前目录下的文件或者目录】

[[email protected] ~]# ls /

bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

【写出ls根下面的目录】

2.1.2 ls /root/【root用户的家目录,家目录是用来存一些配置文件和自己的东西】

[[email protected] ~]# ls /root

anaconda-ks.cfg  mkdir

【root用户的家目录就在根目录的root里】

比如之前我们配置的密钥文件。我们还可以创建一个普通用户,在普通用户里我们配置密钥文件也可以用密钥连接。

[[email protected] ~]# ls /root/.ssh/authorized_keys

/root/.ssh/authorized_keys

你所创建的密钥的公钥必须要放在.ssh/authorized_keys 这是sshd硬性规定的】

[[email protected] ~]# ls /etc/ssh/sshd_config

/etc/ssh/sshd_config

【你可以去这里定义sshd,这里不做过

[[email protected] ~]# useradd GYB

【创建普通用户GYB】

[[email protected] ~]# ls /home/GYB/

【/home/GYB/就是普通用户GYB的家目录】

[[email protected] ~]# useradd gyb

【创建普通用户gyb】

[[email protected] ~]# ls /home/gyb/

【/home/gyb/就是普通用户gyb的家目录】

2.1.3tree命令

[[email protected] ~]# tree

-bash: tree: 未找到命令

【树形显示目录】

[[email protected] ~]# yum install -y tree

已加载插件:fastestmirror

base                                                                            | 3.6 kB  00:00:00    

extras                                                                          | 3.4 kB  00:00:00    

..................................................................................................................

已安装:

 tree.x86_64 0:1.6.0-10.el7                                                                          

完毕!

【安装tree命令】

安装完成后我们可以[[email protected] ~]# tree  /  但是由于/下的目录太多我们就不演示了

[[email protected] ~]# tree --hep

tree: Invalid argument -`-'.

usage: tree [-acdfghilnpqrstuvxACDFQNSUX] [-H baseHREF] [-T title ] [-L level [-R]]

[-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes]

[--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset]

[--filelimit[=]#] [--si] [--timefmt[=]<f>] [<directory list>]

【显示tree常用的一些选项,也可以用[[email protected] ~]# man tree查看】

[[email protected] ~]# tree -L 2 /tmp/

/tmp/

├── ks-script-gj7SLD

├── systemd-private-b790378614824502a426de0c821711bd-chronyd.service-9N2vhR

│   └── tmp

├── systemd-private-b790378614824502a426de0c821711bd-vgauthd.service-qSZmKx

│   └── tmp

├── systemd-private-b790378614824502a426de0c821711bd-vmtoolsd.service-C4cdab

│   └── tmp

└── yum.log

6 directories, 2 files

【-L就是显示tmp下的两层目录】

2.1.4ls根下目录的介绍

[[email protected] ~]# ls /

bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

【我们平时常用的命令一般都是在/bin/、/sbin/、/sur/bin/、/sur/sbin/为什么我们用命令会在这几个里面找到以为有个环境变量PATH。环境变量这里不现做过多的解释。/sbin/下的命令一般是root用户用的,/bin/下的命令一般是给普通用户用的root也可以用的

[[email protected] ~]# ls /boot/

config-3.10.0-693.el7.x86_64

efi

grub

grub2

initramfs-0-rescue-e1347008496b4402b3149fa3dbc74006.img

initramfs-3.10.0-693.el7.x86_64.img

initrd-plymouth.img

symvers-3.10.0-693.el7.x86_64.gz

System.map-3.10.0-693.el7.x86_64

vmlinuz-0-rescue-e1347008496b4402b3149fa3dbc74006

vmlinuz-3.10.0-693.el7.x86_64

【boot一般是系统启动的相关文件。比如grub,之前我们就是用的grub更改的配置文件进入的单用户模式】

[[email protected] ~]# ls /dev/

agpgart          hidraw0             port      stdout  tty25  tty43  tty61    vcs4

autofs           hpet                ppp       tty     tty26  tty44  tty62    vcs5

block            hugepages           ptmx      tty0    tty27  tty45  tty63    vcs6

bsg              hwrng               pts       tty1    tty28  tty46  tty7     vcsa

btrfs-control    initctl             random    tty10   tty29  tty47  tty8     vcsa1

bus              input               raw       tty11   tty3   tty48  tty9     vcsa2

cdrom            kmsg                rtc       tty12   tty30  tty49  ttyS0    vcsa3

char             log                 rtc0      tty13   tty31  tty5   ttyS1    vcsa4

console          loop-control        sda       tty14   tty32  tty50  ttyS2    vcsa5

core             mapper              sda1      tty15   tty33  tty51  ttyS3    vcsa6

cpu              mcelog              sda2      tty16   tty34  tty52  uhid     vfio

cpu_dma_latency  mem                 sda3      tty17   tty35  tty53  uinput   vga_arbiter

crash            midi                sg0       tty18   tty36  tty54  urandom  vhci

disk             mqueue              sg1       tty19   tty37  tty55  usbmon0  vhost-net

dmmidi           net                 shm       tty2    tty38  tty56  usbmon1  vmci

dri              network_latency     snapshot  tty20   tty39  tty57  usbmon2  vsock

fb0              network_throughput  snd       tty21   tty4   tty58  vcs      zero

fd               null                sr0       tty22   tty40  tty59  vcs1

full             nvram               stderr    tty23   tty41  tty6   vcs2

fuse             oldmem              stdin     tty24   tty42  tty60  vcs3

【是我们linux系统特有的一些设备文件所在的路径,例如光盘、硬盘等】

[[email protected] ~]# ls /etc/

adjtime                  gcrypt                    modprobe.d         rsyslog.d

aliases                  GeoIP.conf                modules-load.d     rwtab

aliases.db               GeoIP.conf.default        motd               rwtab.d

alternatives             gnupg                     mtab               sasl2

anacrontab               GREP_COLORS               my.cnf             securetty

asound.conf              groff                     my.cnf.d           security

audisp                   group                     NetworkManager     selinux

audit                    group-                    networks           services

bash_completion.d        grub2.cfg       ......

【etc使我们系统配置相关的文件所在的路径,比如刚刚我们说到[[email protected] ~]# ls /etc/ssh/sshd_config 就是在etc下

[[email protected] ~]# ls /home/

gyb  GYB

【是用来存放用户的一些文件】

[[email protected] ~]# ls /lib /lib64  ^C

【存放系统的一些库文件,我们有些命令就依赖一些库文件,比如ls我们就可以用[[email protected] ~]# ldd /bin/ls来查看ls依赖于那些库文件。现在我们使用的linux系统都是64位的没有32位这一说了】

[[email protected] ~]# ldd /bin/ls

linux-vdso.so.1 =>  (0x00007ffde53e6000)

libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fb05e174000)

libcap.so.2 => /lib64/libcap.so.2 (0x00007fb05df6f000)

libacl.so.1 => /lib64/libacl.so.1 (0x00007fb05dd65000)

libc.so.6 => /lib64/libc.so.6 (0x00007fb05d9a2000)

libpcre.so.1 => /lib64/libpcre.so.1 (0x00007fb05d740000)

libdl.so.2 => /lib64/libdl.so.2 (0x00007fb05d53b000)

/lib64/ld-linux-x86-64.so.2 (0x000055cfa6e53000)

libattr.so.1 => /lib64/libattr.so.1 (0x00007fb05d336000)

libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb05d11a000)

[[email protected] ~]# ls /media/

【这是一个媒介目录,默认是空的。比如我们插一个优盘他就会放到这个目录下】

[[email protected] ~]# ls /mnt/

【临时挂载目录,默认也是空的。

[[email protected] ~]# ls /opt

【默认也是空的】

[[email protected] ~]# ls /proc/

1     15   249  281  423  525  980        driver       kpagecount    sched_debug    uptime

10    16   25   282  424  528  983        execdomains  kpageflags    schedstat      version

1008  17   250  283  425  539  acpi       fb           loadavg       scsi           vmallocinfo

1029  18   251  284  426  549  asound     filesystems  locks         self           vmstat

1123  19   26   3    427  581  buddyinfo  fs           mdstat        slabinfo       zoneinfo

1126  2    27   339  428  584  bus        interrupts   meminfo       softirqs

1165  231  274  352  429  60   cgroups    iomem        misc          stat

1166  232  275  36   432  7    cmdline    ioports      modules       swaps

1170  233  276  37   493  8    consoles   irq          mounts        sys

1171  241  277  376  5    892  cpuinfo    kallsyms     mpt           sysrq-trigger

1172  242  278  38   516  894  crypto     kcore        mtrr          sysvipc

12    243  279  39   518  9    devices    keys         net           timer_list

13    245  28   397  519  93   diskstats  key-users    pagetypeinfo  timer_stats

14    247  280  41   521  978  dma        kmsg         partitions    tty

【系统启动的一些进程,我们也可以看下面有什么文件,也可以看到这些进程在哪里云运行的。】

[[email protected] ~]# ls /run/

auditd.pid   crond.pid    firewalld  mount           sepermit  syslogd.pid  udev    xtables.lock

chrony       cron.reboot  initramfs  netreport       setrans   systemd      user

chronyd.pid  dbus         lock       NetworkManager  sshd.pid  tmpfiles.d   utmp

console      faillock     log        plymouth        sudo      tuned        vmware

【进程产生的一些文件,linux已关机就会消失】

[[email protected] ~]# ls /srv/

【会存储服务产生的一些文件,这也是一个空目录】

[[email protected] ~]# ls /sys/

block  bus  class  dev  devices  firmware  fs  hypervisor  kernel  module  power

【会存储系统内核的一些相关文件,平时我们不会动他

[[email protected] ~]# ls /tmp/

ks-script-gj7SLD

systemd-private-b790378614824502a426de0c821711bd-chronyd.service-9N2vhR

systemd-private-b790378614824502a426de0c821711bd-vgauthd.service-qSZmKx

systemd-private-b790378614824502a426de0c821711bd-vmtoolsd.service-C4cdab

yum.log

【是系统的临时目录,他的权限比较大。什么用户都可以在这里写西东删东西改东西】

[[email protected] ~]# ls /usr/

bin  etc  games  include  lib  lib64  libexec  local  sbin  share  src  tmp

【是用户的一些文件放在这个目录下面,这是一个比较重要的目录】

[[email protected] ~]# ls /usr/lib

binfmt.d   firmware  kdump       modules         python2.7         sse2        tuned

debug      games     kernel      modules-load.d  rpm               sysctl.d    udev

dracut     grub      locale      NetworkManager  sendmail          systemd     yum-plugins

firewalld  kbd       modprobe.d  polkit-1        sendmail.postfix  tmpfiles.d

[[email protected] ~]# ls /var/

adm    crash  empty  gopher    lib    lock  mail  opt       run    tmp

cache  db     games  kerberos  local  log   nis   preserve  spool  yp

[[email protected] ~]# ls /var/log

【[[email protected] ~]# ls /var/下面会存放一些系统的总日志,是一个比较常用的目录】

总结:/bin/、/sbin/、/etc/、/prco/、/usr/、/var/log/、/sur/bin/、/sur/sbin/这些都是我们比较最长用的目录,非常的重要

2.3ls命令【介绍ls常用的一些选项】

2.3.1ls -l

[[email protected] ~]# ls -l

总用量 4

-rw-------. 1 root root 1418 12月  5 22:33 anaconda-ks.cfg

【详细列出当前目录的文件或者目录。平时有的同学会使用ll命令这个命令就是ls -l。-rw-------.这一行代表文件的权限。1代表有几个文件和这个文件使用相同的inod号查看一个文件的inod号例如下面。root root 文件的所属主和所属组。1418代表文件的大小,默认大小单位b,使用-h会人性化的显示文件的大小例如下面。 12月  5 22:33文件创建的时间。最后面就是文件名】

[[email protected] ~]# ls -i anaconda-ks.cfg

33574978 anaconda-ks.cfg

【查看一个文件的inod号是多少,他所存储的是一个文件的权限、所属主、所属组等。inod号代表一个文件在系统的哪一块。】

[[email protected] ~]# ls -lh anaconda-ks.cfg

-rw-------. 1 root root 1.4K 12月  5 22:33 anaconda-ks.cfg

【人性化的现实一个文件的大小,之前我们看到的是1418现在是1.4k】

2.3.2ls -la

[[email protected] ~]# ls -la

总用量 28

dr-xr-x---. 3 root root  163 12月 16 06:15 .

dr-xr-xr-x. 17 root root  224 12月 14 13:51 ..

-rw-------.  1 root root 1418 12月  5 22:33 anaconda-ks.cfg

-rw-------.  1 root root 1208 12月 15 21:05 .bash_history

-rw-r--r--.  1 root root   18 12月 29 2013 .bash_logout

-rw-r--r--.  1 root root  176 12月 29 2013 .bash_profile

-rw-r--r--.  1 root root  176 12月 29 2013 .bashrc

-rw-r--r--.  1 root root  100 12月 29 2013 .cshrc

drwx------.  2 root root   80 12月 14 17:41 .ssh

-rw-r--r--.  1 root root  129 12月 29 2013 .tcshrc

【显示该目录下的一些隐藏文件或目录。每一个目录下面都会有一个点和点点,点代表目录本身】

[[email protected] ~]# ls -ld /root/

dr-xr-x---. 3 root root 147 12月 16 06:36 /root/

【可以看到root就是目录本身,他的详细信息就和第一的一样。3代表3个相同文件使用一样的inod号例如下面】

[[email protected] ~]# ls -i /root/

33574978 anaconda-ks.cfg

[[email protected] ~]# ls -i .

33574978 anaconda-ks.cfg

[[email protected] ~]# ls -i .ssh/..

33574978 anaconda-ks.cfg

2.3.3ls -t

[[email protected] ~]# ls -t

anaconda-ks.cfg

[[email protected] ~]# ls -lta

总用量 28

dr-xr-x---.  3 root root  147 12月 16 06:36 .

-rw-------.  1 root root 1208 12月 15 21:05 .bash_history

drwx------.  2 root root   80 12月 14 17:41 .ssh

dr-xr-xr-x. 17 root root  224 12月 14 13:51 ..

-rw-------.  1 root root 1418 12月  5 22:33 anaconda-ks.cfg

-rw-r--r--.  1 root root   18 12月 29 2013 .bash_logout

-rw-r--r--.  1 root root  176 12月 29 2013 .bash_profile

-rw-r--r--.  1 root root  176 12月 29 2013 .bashrc

-rw-r--r--.  1 root root  100 12月 29 2013 .cshrc

-rw-r--r--.  1 root root  129 12月 29 2013 .tcshrc

【-t就是按时间的先后序排列文件和目录,不过要配合-l和其他选项一起使用】

2.3.4ls -d

[[email protected] ~]# ls -l

总用量 4

-rw-------. 1 root root 1418 12月  5 22:33 anaconda-ks.cfg

[[email protected] ~]# ls -ld

dr-xr-x---. 3 root root 147 12月 16 06:36 .

【不加-d他会显示该目录下的子文件或则子目录,加上就会显示目录本身】

[[email protected] ~]# ll

总用量 4

-rw-------. 1 root root 1418 12月  5 22:33 anaconda-ks.cfg

[[email protected] ~]# ls -l

总用量 4

-rw-------. 1 root root 1418 12月  5 22:33 anaconda-ks.cfg

[[email protected] ~]# which ll

alias ll='ls -l --color=auto'

/usr/bin/ls

[[email protected] ~]# which ls -l

/usr/bin/which: invalid option -- 'l'

alias ls='ls --color=auto'

/usr/bin/ls

【这里我们可以看出ll和ls -l是一样的,这是别名的作用alias】

技术分享图片

【会显示一些颜色】

技术分享图片


2.4文件的类型

[[email protected] ~]# ls -l

总用量 4

-rw-------. 1 root root 1418 12月  5 22:33 anaconda-ks.cfg

【第一列第一个代表文件的类型】

 d【代表一个目录,一般为蓝色】

技术分享图片

 -【代表一个普通文件没有颜色或者二进制文件绿色(你是查看不了的)】技术分享图片

技术分享图片

 c【代表字符串设备,比如鼠标等,颜色为×××】

技术分享图片

 l【代表一个软连接文件,真正的文件在后面的哪一个。颜色为粉绿色】

技术分享图片

 b【代表块设备,比如光盘等,颜色×××】

技术分享图片

 s【代表通讯文件,颜色粉色】

技术分享图片

2.5alias

2.5.1which

[[email protected] ~]# which ls

alias ls='ls --color=auto'

/usr/bin/ls

[[email protected] ~]# which ll

alias ll='ls -l --color=auto'

/usr/bin/ls

【which用来查看命令的别名和命令的绝对路径的,在这里我们也可以看到ls和ll的别名】

2.5.2alias

[[email protected] ~]# alias

alias cp='cp -i'

alias egrep='egrep --color=auto'

alias fgrep='fgrep --color=auto'

alias grep='grep --color=auto'

alias l.='ls -d .* --color=auto'

alias ll='ls -l --color=auto'

alias ls='ls --color=auto'

alias mv='mv -i'

alias rm='rm -i'

alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

【我们直接alias可以查看到系统里面都是有哪些命令是有别名的】

[[email protected] ~]# echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

【环境变量,如果我们运行的命令就在这些目录里面我们直接运行命令他就会直接生效。我们使用的which查找的命令路径就是在这里面查找的】

2.5.3我们自己做一个别名的命令

[[email protected] ~]# gyb

-bash: gyb: 未找到命令

[[email protected] ~]# alias gyb='ls -lha'

【创建一个命令的别名】

[[email protected] ~]# which gyb

alias gyb='ls -lha'

/usr/bin/ls

[[email protected] ~]# gyb /

总用量 20K

dr-xr-xr-x. 17 root root  224 12月 14 13:51 .

dr-xr-xr-x. 17 root root  224 12月 14 13:51 ..

lrwxrwxrwx.  1 root root    7 12月  5 22:25 bin -> usr/bin

dr-xr-xr-x.  5 root root 4.0K 12月  5 22:33 boot

drwxr-xr-x. 19 root root 3.2K 12月 16 06:08 dev

drwxr-xr-x. 74 root root 8.0K 12月 16 06:08 etc

drwxr-xr-x.  4 root root   28 12月 15 19:08 home

lrwxrwxrwx.  1 root root    7 12月  5 22:25 lib -> usr/lib

lrwxrwxrwx.  1 root root    9 12月  5 22:25 lib64 -> usr/lib64

drwxr-xr-x.  2 root root    6 11月  5 2016 media

drwxr-xr-x.  2 root root    6 11月  5 2016 mnt

drwxr-xr-x.  2 root root    6 11月  5 2016 opt

dr-xr-xr-x. 98 root root    0 12月 16 06:07 proc

dr-xr-x---.  3 root root  147 12月 16 06:36 root

drwxr-xr-x. 23 root root  620 12月 16 06:08 run

lrwxrwxrwx.  1 root root    8 12月  5 22:25 sbin -> usr/sbin

drwxr-xr-x.  2 root root    6 11月  5 2016 srv

dr-xr-xr-x. 13 root root    0 12月 16 06:07 sys

drwxrwxrwt. 10 root root 4.0K 12月 16 07:50 tmp

drwxr-xr-x. 13 root root  155 12月  5 22:25 usr

drwxr-xr-x. 19 root root  267 12月  5 23:13 var

【我们使用了一下可以看到结果正确】

[[email protected] ~]# unalias gyb

【如果你不想要这个别名命令了,可以用这个命令取消掉】

[[email protected] ~]# gyb

-bash: gyb: 未找到命令



以上是关于第一周第五次课的主要内容,如果未能解决你的问题,请参考以下文章

一周第五次课(12月15日)

一周第五次课(12月15日)

一周第五次课(12月15日)

一周第五次课

2018.3.23一周第五次课

一周第五次课(10月20)