[toc]node
简述linux
对于目录,咱们大体可以理解,像书本学的章节,每一个章下又都有不少小节同样;而Linux目录和Windows目录有着很大的不一样,Linux目录相似一个树,最顶层是其根目录,以下图:数据库
[root@xavi-001 ~]# ls anaconda-ks.cfg initial-setup-ks.cfg [root@localhost
[root@xavi-001 ~]# ls / bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[root@xavi-001 ~]# ls /root/ anaconda-ks.cfg
[root@xavi-001 ~]# useradd user1 //建立新用户user1 [root@xavi-001 ~]# ls /home/user1/ //普通用户user文件夹目录在home下
[root@xavilinux01 ~]# su - user01 [user01@xavilinux01 ~]$ [user01@xavilinux01 ~]$ su - root 密码:
系统没有tree指令,须要用yum来安装bash
[root@xavi-001 ~]# yum install -y tree
[root@xavi-001 ~]# tree / //查看tree目录,特别长
[root@xavi-001 ~]# tree --hep // 用来显示tree经常使用的选项 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>]
[root@xavi-001 ~]# ldd /bin/ls //查找关联目录 linux-vdso.so.1 => (0x00007ffdfa1f1000) libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f698648e000) libcap.so.2 => /lib64/libcap.so.2 (0x00007f6986289000) libacl.so.1 => /lib64/libacl.so.1 (0x00007f698607f000) libc.so.6 => /lib64/libc.so.6 (0x00007f6985cbe000) libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f6985a5d000) libdl.so.2 => /lib64/libdl.so.2 (0x00007f6985858000) /lib64/ld-linux-x86-64.so.2 (0x00007f69866c8000) libattr.so.1 => /lib64/libattr.so.1 (0x00007f6985653000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f6985437000)
/media:系统会自动识别一些设备(如U盘、光驱等),当识别后,Linux会把识别的设备挂载到该目录下。session
/mnt:系统提供该目录是为了让用户临时挂载别的文件系统。咱们能够将光驱挂载到/mnt/上,而后进入该目录查看光驱里的内容。dom
/opt:这是给主机额外安装软件所设置的目录,该目录默认为空。好比你要安装一个ORACLE数据库,能够放到该目录下。ssh
[root@xavi-001 ~]# ls /media/ [root@xavi-001 ~]# ls /mnt/ [root@xavi-001 ~]# ls /opt/
# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
[root@xavi-001 ~]# ls /proc/ 1 18 232 251 279 38 41 495 530 611 922 consoles interrupts loadavg partitions sysvipc 10 19 2328 252 28 380 42 5 538 613 927 cpuinfo iomem locks sched_debug timer_list 12 2 233 26 280 39 43 505 545 62 929 crypto ioports mdstat schedstat timer_stats 13 20 2331 261 281 395 439 509 547 669 938 devices irq meminfo scsi tty 1340 21 241 27 282 4 440 517 549 7 94 diskstats kallsyms misc self uptime 1349 2184 242 273 29 40 444 519 550 8 acpi dma kcore modules slabinfo version 1350 2186 243 274 3 401 446 520 554 9 asound driver keys mounts softirqs vmallocinfo 14 2247 244 275 30 404 448 521 555 912 buddyinfo execdomains key-users mpt stat vmstat 15 2250 247 276 351 405 450 522 558 913 bus fb kmsg mtrr swaps zoneinfo 16 231 248 277 373 406 452 524 591 917 cgroups filesystems kpagecount net sys 17 2310 250 278 374 407 454 529 6 918 cmdline fs kpageflags pagetypeinfo sysrq-trigger
进程生产PID,有1,10等,每一个进程都会有文件和目录,基本同样socket
[root@xavi-001 ~]# ls /proc/1 attr cmdline environ io mem ns pagemap schedstat stat timers autogroup comm exe limits mountinfo numa_maps personality sessionid statm uid_map auxv coredump_filter fd loginuid mounts oom_adj projid_map setgroups status wchan cgroup cpuset fdinfo map_files mountstats oom_score root smaps syscall clear_refs cwd gid_map maps net oom_score_adj sched stack task
[root@xavi-001 ~]# ls -l /proc/281 //281也是一个进程,里面的有不少目录和文件 ls: 没法读取符号连接/proc/281/exe: 没有那个文件或目录 总用量 0 dr-xr-xr-x 2 root root 0 12月 16 09:42 attr -rw-r--r-- 1 root root 0 12月 16 09:42 autogroup -r-------- 1 root root 0 12月 16 09:42 auxv -r--r--r-- 1 root root 0 12月 16 09:42 cgroup --w------- 1 root root 0 12月 16 09:42 clear_refs -r--r--r-- 1 root root 0 12月 16 09:32 cmdline -rw-r--r-- 1 root root 0 12月 16 09:42 comm -rw-r--r-- 1 root root 0 12月 16 09:42 coredump_filter -r--r--r-- 1 root root 0 12月 16 09:42 cpuset lrwxrwxrwx 1 root root 0 12月 16 09:42 cwd -> / //进程所在的路径 -r-------- 1 root root 0 12月 16 09:42 environ lrwxrwxrwx 1 root root 0 12月 16 09:42 exe dr-x------ 2 root root 0 12月 16 09:42 fd dr-x------ 2 root root 0 12月 16 09:42 fdinfo -rw-r--r-- 1 root root 0 12月 16 09:42 gid_map -r-------- 1 root root 0 12月 16 09:42 io -r--r--r-- 1 root root 0 12月 16 09:42 limits -rw-r--r-- 1 root root 0 12月 16 09:42 loginuid dr-x------ 2 root root 0 12月 16 09:42 map_files -r--r--r-- 1 root root 0 12月 16 09:42 maps -rw------- 1 root root 0 12月 16 09:42 mem -r--r--r-- 1 root root 0 12月 16 09:42 wchan
[root@xavi-001 ~]# ls /run/ abrt chronyd.pid dmeventd-client initramfs lsm NetworkManager samba sshd.pid udev alsactl.pid console dmeventd-server ksmtune.pid lvm plymouth sepermit sysconfig user atd.pid crond.pid faillock libvirt lvmetad.pid ppp setrans syslogd.pid utmp auditd.pid cron.reboot firewalld libvirtd.pid mdadm radvd setroubleshoot systemd xtables.lock avahi-daemon cups gssproxy.pid lock mount rpcbind sm-notify.pid tmpfiles.d certmonger dbus gssproxy.sock log netreport rpcbind.sock spice-vdagentd tuned
[root@xavi-001 ~]# ls /srv/ [root@xavi-001 ~]# ls /sys/ //系统内核相关的文件 block bus class dev devices firmware fs hypervisor kernel module power
[root@xavi-001 ~]# ls /tmp/ systemd-private-326256f65ea943dd8a67183d93dfe298-cups.service-AeQUKR systemd-private-326256f65ea943dd8a67183d93dfe298-vmtoolsd.service-4S9XrS systemd-private-66398656a9a941ce9ccbdb01047bb234-cups.service-PmWt6O systemd-private-66398656a9a941ce9ccbdb01047bb234-vmtoolsd.service-GWHU20 systemd-private-d19532cf8bd34e658a8f10d18cbbd068-cups.service-HyM93B systemd-private-d19532cf8bd34e658a8f10d18cbbd068-vmtoolsd.service-IxzO4H systemd-private-fb35f8ad85b54d3fa3ceaaa57cea1ae1-cups.service-1DZjWJ systemd-private-fb35f8ad85b54d3fa3ceaaa57cea1ae1-vmtoolsd.service-XH83aQ
[root@xavi-001 ~]# ls /usr/ bin etc games include lib lib64 libexec local sbin share src tmp
[root@xavi-001 ~]# ls /usr/local/ bin etc games include lib lib64 libexec sbin share src
[root@xavi-001 ~]# ls /var/ account cache db games kerberos local log nis preserve spool tmp adm crash empty gopher lib lock mail opt run target yp [root@xavi-001 ~]# ls /var/log anaconda cron firewalld maillog-20170813 pluto secure spooler-20171213 wtmp audit cron-20170813 gdm maillog-20171213 ppp secure-20170813 sssd Xorg.0.log boot.log cron-20171213 glusterfs messages qemu-ga secure-20171213 tallylog Xorg.0.log.old btmp cups lastlog messages-20170813 rhsm speech-dispatcher tuned yum.log btmp-20171213 dmesg libvirt messages-20171213 sa spooler vmware-vmsvc.log chrony dmesg.old maillog ntpstats samba spooler-20170813 wpa_supplicant.log [root@xavi-001 ~]# ls /var/log/messages /var/log/messages [root@xavi-001 ~]# ls /var/run/ abrt chronyd.pid dmeventd-client initramfs lsm NetworkManager samba sshd.pid udev alsactl.pid console dmeventd-server ksmtune.pid lvm plymouth sepermit sysconfig user atd.pid crond.pid faillock libvirt lvmetad.pid ppp setrans syslogd.pid utmp auditd.pid cron.reboot firewalld libvirtd.pid mdadm radvd setroubleshoot systemd xtables.lock avahi-daemon cups gssproxy.pid lock mount rpcbind sm-notify.pid tmpfiles.d certmonger dbus gssproxy.sock log netreport rpcbind.sock spice-vdagentd tuned
[root@xavi-001 ~]# ls /usr/bin /usr/sbin /bin/ /sbin/ /etc/ /var/ /usr/local/
[root@xavi-001 ~]# ls -l 总用量 8 -rw-------. 1 root root 1422 8月 9 05:35 anaconda-ks.cfg //数字1表示有多少文件使用了相同的 anaconda,第一个root表示是root的用户,第二个root表示的root用户组 -rw-r--r--. 1 root root 1647 8月 9 00:17 initial-setup-ks.cfg -rw-r--r-- 1 root root 0 12月 13 00:01 [root@localhost [root@xavi-001 ~]# ls -i anaconda-ks.cfg //查看文件的iload号 33574986 anaconda-ks.cfg
[root@xavi-001 ~]# ls -lh anaconda-ks.cfg //-lh表示更人性化的现示,1422byte -rw-------. 1 root root 1.4K 8月 9 05:35 anaconda-ks.cfg
[root@xavi-001 ~]# ls -la //查看全部目录,带.的表示当前目录,..表示上一级目录 总用量 32 dr-xr-x---. 5 root root 227 12月 13 00:02 . dr-xr-xr-x. 17 root root 253 8月 10 22:50 .. -rw-------. 1 root root 1422 8月 9 05:35 anaconda-ks.cfg -rw-------. 1 root root 1999 12月 15 21:27 .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 drwxr-xr-x. 3 root root 18 8月 10 20:22 .cache drwxr-xr-x. 3 root root 18 8月 10 20:22 .config -rw-r--r--. 1 root root 100 12月 29 2013 .cshrc -rw-r--r--. 1 root root 1647 8月 9 00:17 initial-setup-ks.cfg -rw-r--r-- 1 root root 0 12月 13 00:01 [root@localhost drwx------. 2 root root 80 12月 15 00:37 .ssh -rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc
[root@xavi-001 ~]# ls -ld /root/ dr-xr-x---. 5 root root 227 12月 13 00:02 /root/ [root@xavi-001 ~]# ls -i /root/ 33574986 anaconda-ks.cfg 34888138 initial-setup-ks.cfg 33989830 [root@localhost [root@xavi-001 ~]# ls -i . 33574986 anaconda-ks.cfg 34888138 initial-setup-ks.cfg 33989830 [root@localhost [root@xavi-001 ~]# ls -i .ssh/.. //.ssh的上级目录就是root 33574986 anaconda-ks.cfg 34888138 initial-setup-ks.cfg 33989830 [root@localhost
[root@xavi-001 ~]# ls -a / . 1 bin dev home lib64 mnt proc run srv tmp var .. .autorelabel boot etc lib media opt root sbin sys usr [root@xavi-001 ~]# ls -a /root/ . anaconda-ks.cfg .bash_logout .bashrc .config initial-setup-ks.cfg .ssh .. .bash_history .bash_profile .cache .cshrc [root@localhost .tcshrc
[root@xavi-001 ~]# ls -lta //加t后,按时间顺序排序 总用量 32 -rw-------. 1 root root 1999 12月 15 21:27 .bash_history drwx------. 2 root root 80 12月 15 00:37 .ssh dr-xr-x---. 5 root root 227 12月 13 00:02 . -rw-r--r-- 1 root root 0 12月 13 00:01 [root@localhost dr-xr-xr-x. 17 root root 253 8月 10 22:50 .. drwxr-xr-x. 3 root root 18 8月 10 20:22 .config drwxr-xr-x. 3 root root 18 8月 10 20:22 .cache -rw-------. 1 root root 1422 8月 9 05:35 anaconda-ks.cfg -rw-r--r--. 1 root root 1647 8月 9 00:17 initial-setup-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 [root@xavi-001 ~]# ls -la 总用量 32 dr-xr-x---. 5 root root 227 12月 13 00:02 . dr-xr-xr-x. 17 root root 253 8月 10 22:50 .. -rw-------. 1 root root 1422 8月 9 05:35 anaconda-ks.cfg -rw-------. 1 root root 1999 12月 15 21:27 .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 drwxr-xr-x. 3 root root 18 8月 10 20:22 .cache drwxr-xr-x. 3 root root 18 8月 10 20:22 .config -rw-r--r--. 1 root root 100 12月 29 2013 .cshrc -rw-r--r--. 1 root root 1647 8月 9 00:17 initial-setup-ks.cfg -rw-r--r-- 1 root root 0 12月 13 00:01 [root@localhost drwx------. 2 root root 80 12月 15 00:37 .ssh -rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc
[root@xavi-001 ~]# ls -l /root/ //不加d,会把目录下的全部文件列出 总用量 8 -rw-------. 1 root root 1422 8月 9 05:35 anaconda-ks.cfg -rw-r--r--. 1 root root 1647 8月 9 00:17 initial-setup-ks.cfg -rw-r--r-- 1 root root 0 12月 13 00:01 [root@localhost [root@xavi-001 ~]# ls -ld /root/ //加了d只列目录自己 dr-xr-x---. 5 root root 227 12月 13 00:02 /root/
[root@xavi-001 ~]# man ls [root@xavi-001 ~]# ls -l -i -a -t -h -d
[root@xavi-001 ~]# which ll alias ll='ls -l --color=auto' //表示有颜色的区别开 /usr/bin/ls [root@xavi-001 ~]# ls / 1 boot etc lib media opt root sbin sys usr bin dev home lib64 mnt proc run srv tmp var [root@xavi-001 ~]# /bin/ls/ -bash: /bin/ls/: 不是目录 [root@xavi-001 ~]# /bin/ls / 1 boot etc lib media opt root sbin sys usr bin dev home lib64 mnt proc run srv tmp var
[root@xavi-001 ~]# ls -la 总用量 32 dr-xr-x---. 5 root root 227 12月 13 00:02 . //第一列表示文件的权限,第一位d表示的是文件的类型,directory dr-xr-xr-x. 17 root root 253 8月 10 22:50 .. -rw-------. 1 root root 1422 8月 9 05:35 anaconda-ks.cfg //—表示的是普通文件 -rw-------. 1 root root 1999 12月 15 21:27 .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 drwxr-xr-x. 3 root root 18 8月 10 20:22 .cache drwxr-xr-x. 3 root root 18 8月 10 20:22 .config -rw-r--r--. 1 root root 100 12月 29 2013 .cshrc -rw-r--r--. 1 root root 1647 8月 9 00:17 initial-setup-ks.cfg -rw-r--r-- 1 root root 0 12月 13 00:01 [root@localhost drwx------. 2 root root 80 12月 15 00:37 .ssh -rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc
[root@xavi-001 ~]# cat anaconda-ks.cfg #version=DEVEL # System authorization information auth --enableshadow --passalgo=sha512 # Use CDROM installation media cdrom # Use graphical install graphical
[root@xavi-001 ~]# ls -l /dev/ 总用量 0 crw-rw---- 1 root video 10, 175 12月 16 09:32 agpgart crw------- 1 root root 10, 235 12月 16 09:32 autofs drwxr-xr-x 2 root root 140 12月 16 09:32 block drwxr-xr-x 2 root root 80 12月 16 09:32 bsg crw------- 1 root root 10, 234 12月 16 09:32 btrfs-control drwxr-xr-x 3 root root 60 12月 16 09:32 bus lrwxrwxrwx 1 root root 3 12月 16 09:32 cdrom -> sr0 drwxr-xr-x 2 root root 3060 12月 16 09:33 char crw------- 1 root root 5, 1 12月 16 09:32 console lrwxrwxrwx 1 root root 11 12月 16 09:32 core -> /proc/kcore drwxr-xr-x 3 root root 80 12月 16 09:32 cpu crw------- 1 root root 10, 61 12月 16 09:32 cpu_dma_latency crw------- 1 root root 10, 62 12月 16 09:32 crash drwxr-xr-x 5 root root 100 12月 16 09:32 disk crw-rw---- 1 root audio 14, 9 12月 16 09:32 dmmidi drwxr-xr-x 2 root root 100 12月 16 09:32 dri crw-rw---- 1 root video 29, 0 12月 16 09:32 fb0 lrwxrwxrwx 1 root root 13 12月 16 09:32 fd -> /proc/self/fd
[root@xavi-001 ~]# ls -l /dev/log srw-rw-rw- 1 root root 0 12月 16 09:32 /dev/log
总结前面所学的的文件类型ide
[root@xavi-001 ~]# d - c b s l
前面使用的ll,ls都是有别名的,如何查找他们的别名呢,使用which,这里可看到alias表示的就是这个指令是由命令+选项的组合造成的新的命令学习
[root@xavi-001 ~]# which ls alias ls='ls --color=auto' /usr/bin/ls
[root@xavi-001 ~]# ls anaconda-ks.cfg initial-setup-ks.cfg [root@localhost [root@xavi-001 ~]# /usr/bin/ls //此两条命令相同 anaconda-ks.cfg initial-setup-ks.cfg [root@localhost
[root@xavi-001 ~]# 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-tild
[root@xavi-001 ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@xavi-001 ~]# alias xavier='ls -lha' [root@xavi-001 ~]# xavier 总用量 32K dr-xr-x---. 5 root root 227 12月 13 00:02 . dr-xr-xr-x. 17 root root 253 8月 10 22:50 .. -rw-------. 1 root root 1.4K 8月 9 05:35 anaconda-ks.cfg -rw-------. 1 root root 2.0K 12月 15 21:27 .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 drwxr-xr-x. 3 root root 18 8月 10 20:22 .cache drwxr-xr-x. 3 root root 18 8月 10 20:22 .config -rw-r--r--. 1 root root 100 12月 29 2013 .cshrc -rw-r--r--. 1 root root 1.7K 8月 9 00:17 initial-setup-ks.cfg -rw-r--r-- 1 root root 0 12月 13 00:01 [root@localhost drwx------. 2 root root 80 12月 15 00:37 .ssh -rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc [root@xavi-001 ~]# which xavier alias xavier='ls -lha' /usr/bin/ls [root@xavi-001 ~]# unalias xavier [root@xavi-001 ~]# xavier bash: xavier: 未找到命令...