2.1 系统目录结构(上)
系统用户家目录 /root/
普通用户家目录 /home/用户名/
创建新用户 useradd 用户名
[root@aming-01 ~]# useradd aming
[root@aming-01 ~]# useradd user1
[root@aming-01 ~]# ls /home/
aming user1
authorized_keys必须放在/root/.ssh/下,且名称必须为authorized_keys 这是ssh规定的,可以在/etc/ssh/sshd_config里定义
tree 显示树形目录子目录和文件 没有tree命令,手动安装
[root@aming-01 ~]# yum install -y tree
已加载插件:fastestmirror
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/4): base/7/x86_64/group_gz | 156 kB 00:00:02
(2/4): extras/7/x86_64/primary_db | 145 kB 00:00:03
(3/4): updates/7/x86_64/primary_db | 4.5 MB 00:00:03
base/7/x86_64/primary_db FAILED ===================- ] 336 kB/s | 6.5 MB 00:00:12 ETA
http://mirrors.njupt.edu.cn/centos/7.4.1708/os/x86_64/repodata/0c34273ad0292747ee5e15c047d3e51c67ca59861a446972db45d71abacc7ad7-primary.sqlite.bz2: [Errno 14] curl#56 - "Recv failure: Connection reset by peer"
正在尝试其它镜像。
(4/4): base/7/x86_64/primary_db | 5.7 MB 00:00:00
Determining fastest mirrors
* base: mirrors.cn99.com
* extras: mirrors.163.com
* updates: mirrors.cn99.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 tree.x86_64.0.1.6.0-10.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=========================================================================================================================================================
Package 架构 版本 源 大小
=========================================================================================================================================================
正在安装:
tree x86_64 1.6.0-10.el7 base 46 k
事务概要
=========================================================================================================================================================
安装 1 软件包
总下载量:46 k
安装大小:87 k
Downloading packages:
警告:/var/cache/yum/x86_64/7/base/packages/tree-1.6.0-10.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
tree-1.6.0-10.el7.x86_64.rpm 的公钥尚未安装
tree-1.6.0-10.el7.x86_64.rpm | 46 kB 00:00:00
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 检索密钥
导入 GPG key 0xF4A80EB5:
用户ID : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
指纹 : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
软件包 : centos-release-7-4.1708.el7.centos.x86_64 (@anaconda)
来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : tree-1.6.0-10.el7.x86_64 1/1
验证中 : tree-1.6.0-10.el7.x86_64 1/1
已安装:
tree.x86_64 0:1.6.0-10.el7
完毕!
显示常用选项tree --hep
man 显示命令的帮助文档 man tree
指定最大目录深度 [root@aming-01 ~]# tree -L 2 /
常用目录
·保存常用命令
bin sbin /usr/bin /usr/sbin
bin 所有用户都可以使用的命令
sbin 一般都是root用户使用的,普通用户无法使用
·系统启动相关的文件
/boot (请勿删除任何文件,否则无法正常启动)
·系统的设备文件
/dev 光盘、硬盘、鼠标、键盘等
·系统配置文件所在路径
/etc
[root@aming-01 ~]# ls /etc/sysconfig/network-scripts/ifcfg-ens33
[root@aming-01 ~]# ls /etc/ssh/sshd_config
·用户的家目录
/home
[root@aming-01 ~]# ls /home/
aming user1
·系统的库文件
/lib /lib64
如何查看命令依赖哪些库
查看某个命令以来哪些库,可以用以下命令
[root@aming-01 ~]# ldd /bin/ls
linux-vdso.so.1 => (0x00007ffeea3c3000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fa76bb7c000)
libcap.so.2 => /lib64/libcap.so.2 (0x00007fa76b977000)
libacl.so.1 => /lib64/libacl.so.1 (0x00007fa76b76d000)
libc.so.6 => /lib64/libc.so.6 (0x00007fa76b3aa000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007fa76b148000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fa76af43000)
/lib64/ld-linux-x86-64.so.2 (0x0000557f1f2f0000)
libattr.so.1 => /lib64/libattr.so.1 (0x00007fa76ad3e000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fa76ab22000)
2.2 系统目录结构(下)
从CentOS7开始,系统不再区分32位,64位,全部都是64位
·媒介目录,默认为空
/media
·临时挂载目录,默认为空
/mnt
·主机额外安装软件所摆放的目录,默认为空
/opt
·存放系统进程目录等(是一个虚拟文件系统)
/proc
[root@aming-01 ~]# ls /proc/
1 13 17 275 295 39 400 530 60 678 asound diskstats ioports loadavg net stat version
10 1365 18 276 3 392 401 538 621 688 buddyinfo dma irq locks pagetypeinfo swaps vmallocinfo
1009 1367 19 279 36 393 402 539 645 689 bus driver kallsyms mdstat partitions sys vmstat
1011 1368 2 28 366 394 41 541 646 7 cgroups execdomains kcore meminfo sched_debug sysrq-trigger zoneinfo
1116 1369 25 281 367 395 470 542 648 705 cmdline fb keys misc schedstat sysvipc
1118 1370 259 286 37 396 489 545 650 8 consoles filesystems key-users modules scsi timer_list
1125 14 26 288 378 397 5 546 651 9 cpuinfo fs kmsg mounts self timer_stats
1128 15 27 290 379 398 500 547 662 92 crypto interrupts kpagecount mpt slabinfo tty
12 16 274 292 38 399 529 548 665 acpi devices iomem kpageflags mtrr softirqs uptime
·进程产生的临时文件,重启就消失
/run
[root@aming-01 ~]# ls /run
auditd.pid console dbus faillock lock lvmetad.pid NetworkManager setrans syslogd.pid tuned utmp
chrony crond.pid dmeventd-client firewalld log mount plymouth sshd.pid systemd udev vmware
chronyd.pid cron.reboot dmeventd-server initramfs lvm netreport sepermit sudo tmpfiles.d user xtables.lock
·服务产生的文件,默认为空
/srv
·系统内核相关文件 (平时不用关注)
/sys
[root@aming-01 ~]# ls /sys/
block bus class dev devices firmware fs hypervisor kernel module power
·系统临时目录
/tmp (执行权限很高)
[root@aming-01 ~]# ls /tmp
ks-script-DvfSzK systemd-private-5099007c323a42dbbef7226763f0e00f-vmtoolsd.service-7ZusGn
systemd-private-5099007c323a42dbbef7226763f0e00f-chronyd.service-6MOjGt yum.log
systemd-private-5099007c323a42dbbef7226763f0e00f-vgauthd.service-iirN2o
·系统用户相关文件
/usr 安装apachi等服务时,会把服务安装在 /usr/local 下
[root@aming-01 ~]# ls /usr
bin etc games include lib lib64 libexec local sbin share src tmp
·日志文件、缓存等
/var
/var/log 存一些日志文件
系统日志 /var/log/messages
进程的pid /var/run
[root@aming-01 ~]# ls /var
adm cache crash db empty games gopher kerberos lib local lock log mail nis opt preserve run spool tmp yp
常用目录:
/usr/bin /usr/sbin 实际就是/bin /sbin 只是做了软连接
/etc /var /usr/local /root /home
2.3 ls命令
ls -l 详细的信息
[root@aming-01 ~]# ls -l
总用量 4
-rw-------. 1 root root 1546 12月 13 06:40 anaconda-ks.cfg
每个项目代表: 权限、多少文件使用相同inode、所有者、所属组、大小、创建日期、名称
ls -i 查看inode号(inode存储权限、大小、时间、所有者、所属组等信息)
inode记录文件存在于磁盘的哪个区域上,如果两个文件使用相同的inode,那么这两个文件 在磁盘存放的数据块是一样的,实际就是硬链接。
[root@aming-01 ~]# ls -i
33583087 anaconda-ks.cfg
ls -lh 用更人性化方式显示
[root@aming-01 ~]# ls -lh
总用量 4.0K
-rw-------. 1 root root 1.6K 12月 13 06:40 anaconda-ks.cfg
ls -la 显示所有,包括隐藏文件
[root@aming-01 ~]# ls -la
总用量 28
dr-xr-x---. 3 root root 147 12月 13 22:21 .
dr-xr-xr-x. 17 root root 224 12月 14 21:57 ..
-rw-------. 1 root root 1546 12月 13 06:40 anaconda-ks.cfg
-rw-------. 1 root root 1397 12月 14 23:03 .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 22:44 .ssh
-rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc
. 是当前目录 .. 是上一级目录
dr-xr-x---. 3 root root 147 12月 13 22:21 中,3个文件inode号一样
[root@aming-01 ~]# ls -i /root/
33583087 anaconda-ks.cfg
[root@aming-01 ~]# ls -i .
33583087 anaconda-ks.cfg
[root@aming-01 ~]# ls -i .ssh/..
33583087 anaconda-ks.cfg
ls -lta t 是按创建时间顺序排序
[root@aming-01 ~]# ls -lta
总用量 28
-rw-------. 1 root root 1397 12月 14 23:03 .bash_history
drwx------. 2 root root 80 12月 14 22:44 .ssh
dr-xr-xr-x. 17 root root 224 12月 14 21:57 ..
dr-xr-x---. 3 root root 147 12月 13 22:21 .
-rw-------. 1 root root 1546 12月 13 06:40 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
ls -d 只列出目录本身
[root@aming-01 ~]# ls -d /root/
/root/
ls -ld 列出目录内详细信息和目录
[root@aming-01 ~]# ls -ld /root/
dr-xr-x---. 3 root root 147 12月 13 22:21 /root/
ll = ls -l ll 是 ls -l 的别名
[root@aming-01 ~]# which ll
alias ll='ls -l --color=auto'
/usr/bin/ls
2.4 文件类型
ll 命令查看文件详细信息时
[root@aming-01 ~]# ls -la
总用量 28
dr-xr-x---. 3 root root 147 12月 13 22:21 .
dr-xr-xr-x. 17 root root 224 12月 14 21:57 ..
-rw-------. 1 root root 1546 12月 13 06:40 anaconda-ks.cfg
-rw-------. 1 root root 1397 12月 14 23:03 .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 22:44 .ssh
-rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc
如:dr-xr-x---第一位代表文件类型
-是普通文件,(文本文档、二进制文件)
-rw-------. 1 root root 1546 12月 13 06:40 anaconda-ks.cfg
d是目录
drwx------. 2 root root 80 12月 14 22:44 .ssh
c是字符串设备,(鼠标、键盘、tty等)
crw-rw-rw-. 1 root tty 5, 0 12月 15 20:15 tty
l是软连接文件
lrwxrwxrwx. 1 root root 15 12月 15 20:15 stderr -> /proc/self/fd/2
b是块设备,(光驱、光盘、磁盘)
brw-rw----. 1 root disk 8, 0 12月 15 20:15 sda
s是socket文件,(用作进程和进程之间通信的)
srw-rw-rw-. 1 root root 0 12月 15 20:15 log
anaconda-ls.cfg 这一类文本文档可以cat查看
/bin/ls 这一类是二进制文件,被编译过的,无法cat
2.5 alias命令
用于查找并显示给定命令的绝对路径(如果有别名,可以显示别名) which
[root@aming-01 ~]# which ls
alias ls='ls --color=auto'
/usr/bin/ls
[root@aming-01 ~]# which ll
alias ll='ls -l --color=auto'
/usr/bin/ls
[root@aming-01 ~]# which man
/usr/bin/man
[root@aming-01 ~]# which yum
/usr/bin/yum
如果不想使用命令的别名,那么可以使用命令的绝对路径 例如:ls 可以使用 /usr/bin/ls
查看系统内所有别名 alias
[root@aming-01 ~]# 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'
which查看命令,就是在环境变量PATH中查看 [root@aming-01 ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
自定义别名 alias 别名='命令' 取消别名 unalias 别名
[root@aming-01 ~]# alias aming='ls -lha'
[root@aming-01 ~]# aming
总用量 28K
dr-xr-x---. 3 root root 147 12月 13 22:21 .
dr-xr-xr-x. 17 root root 224 12月 14 21:57 ..
-rw-------. 1 root root 1.6K 12月 13 06:40 anaconda-ks.cfg
-rw-------. 1 root root 1.4K 12月 14 23:03 .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 22:44 .ssh
-rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc
[root@aming-01 ~]# which aming
alias aming='ls -lha'
/usr/bin/ls
[root@aming-01 ~]# unalias aming
[root@aming-01 ~]# aming
-bash: aming: 未找到命令