[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: 未找到命令...