一些基本概念

檢視當前目錄路徑命令:pwd

根目錄:cd /:此目錄稱為linux的根目錄,餘下所有目錄都是以根目錄向下延伸。根目錄是大數的根,後續所有路徑都是根的分支路徑,類似圖X。

使用者home目錄:cd ~;pwd,即可看到個人的home目錄,即個人的家目錄,使用者可以在自己home目錄任意操作。同理到切換到不同使用者後,cd ~會到新使用者的home目錄,比如 /home/zhangsan ,/home/lisi 。

linux支援多使用者操作,如果防止衝突,即每個使用者有自己獨立的home目錄,使用者只有在自己home下面操作的許可權,無在其他使用者home操作許可權。

絕對路徑:以根路徑起始的路徑,比如/home/zhangsan/xxx/

相對路徑:以當前路徑起始的路徑,比如。。/zhangsan/xx/; 。/zhangsan/xx

基礎目錄介紹

寫在前面,

linux啟動後存在的目錄,均有各自的含義和作用,切不可隨意刪改或到其目錄進行開發。建議新手建立普通賬戶,到自己home目錄下學習和開發,形成良好的習慣,切不可直接使用root操作,防止做出“刪庫跑路”(例如rm /*; rm /lib64/*)的低端操作。當然以我多年作業系統經驗,我會告訴你如何恢復。

初次登陸系統後,會進入到~目錄,

$ ls /

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

1./bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin

系統命令目錄,這裡存放著系統命令二進位制,比如which mkdir,即可看到/bin/mkdir;

影響:系統命令執行

疑問1:為什麼命令可以直接使用,而不是/bin/mkdir執行?因PATH環境變數

echo $PATH

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

執行命令時,系統會從PATH變數目錄尋找二進位制命令,如果找不到報錯

疑問2:有什麼區別

bin和sbin的區別:

/sbin 下的命令屬於基本的系統命令;/bin下存放一些普通的基本命令,比如/sbin/ifconfig,/bin/ls

/bin,/usr/bin,/usr/local/bin

/bin是系統的一些指令,/usr/bin是普通使用者命令 /usr/local/bin是你在後期安裝的一些軟體的執行命令

比如/bin/ls, /usr/bin/gcc, /usr/local/bin/ccmake(安裝cmake)

2./etc

This is the nerve center of your system, it contains all system related configuration files in here or in its sub-directories。

系統配置檔案目錄,包括檔案系統配置,服務配置等等

影響:系統某些服務或基礎服務正常啟動

比如

/etc/fstab配置fs掛載目錄和格式,系統啟動時會根據此配置進行目錄掛載;

/etc/network/是網路配置,重啟network時會根據此配置進行網路初始化;

等等

3./lib /lib64

庫目錄,所有動態的二進位制檔案都依賴。so庫檔案

影響:二進位制執行,系統命令也是二進位制哦

比如:

ldd /usr/bin/gcc

linux-vdso。so。1 => (0x00007ffdbecc5000)

libc。so。6 => /lib/x86_64-linux-gnu/libc。so。6 (0x00007f8d8e559000)

/lib64/ld-linux-x86-64。so。2 (0x00007f8d8e923000)

gcc執行依賴以上庫,求別亂動庫,比如mv libc。so後,可能再也無法mv回來了,因為mv已經無法執行了。

4./opt

This directory is reserved for all the software and add-on packages that are not part of the default installation。

為後續軟體安裝預留目錄,安裝軟體預設路徑

5./usr

/usr usually contains by far the largest share of data on a system。

/usr通常存放共享、只讀的檔案或者資料,當然root許可權下都是可讀,但此目錄下檔案建議不要改動

比如 /usr/include 存放標頭檔案,編譯器依賴

6./root

root賬號的home目錄

影響:可有可無

7./srv

/srv contains site-specific data which is served by this system。

存放某些特定服務程序資料

8./sys

linux和裝置驅動建立互動目錄,透過此目錄可檢視一些裝置驅動屬性,操作硬體裝置(比如enable,disable或引數設定)

比如

/sys/devices/platform/ 對應系統platform裝置資訊

/sys/devices/system/cpu/ 對應cpu裝置資訊,可根據此目錄對cpu裝置進行上下線操作

/sys/devices/system/memory/ 對應記憶體資訊,可根據此目錄對記憶體塊進行上下線操作

9./boot

This directory contains everything required for the boot process except for configuration files not needed at boot time (the most notable of those being those that belong to the GRUB boot-loader) and the map installer。 Thus, the /boot directory stores data that is used before the kernel begins executing user-mode programs。 This may include redundant (back-up) master boot records, sector/system map files, the kernel and other important boot files and data that is not directly edited by hand。 Programs necessary to arrange for the boot loader to be able to boot a file are placed in /sbin。 Configuration files for boot loaders are placed in /etc。 The system kernel is located in either / or /boot (or as under Debian in /boot but is actually a symbolically linked at / in accordance with the FSSTND)。

系統啟動依賴目錄,裡面存放了系統映象、檔案系統以及載入啟動的grub檔案

影響:系統啟動

核心映象:/boot/vmlinuz-xxx

檔案系統:/boot/initrdxxx

grub目錄:/boot/grub/

10./dev

/dev is the location of special or device files。 It is a very interesting directory that highlights one important aspect of the Linux filesystem - everything is a file or a directory。 Look through this directory and you should hopefully see hda1, hda2 etc。。。。 which represent the various partitions on the first master drive of the system。

/dev是一個特殊的,裝置驅動目錄,裡面檔案大部分都是裝置驅動檔案。linux中“everything is a file or a directory”在此體現得淋漓盡致。

/dev/cdrom and /dev/fd0 represent your CD-ROM drive and your floppy drive。 This may seem strange but it will make sense if you compare the characteristics of files to that of your hardware。 Both can be read from and written to。

Take /dev/dsp, for instance。 This file represents your speaker device。 Any data written to this file will be re-directed to your speaker。 If you try ‘cat /boot/vmlinuz > /dev/dsp’ (on a properly configured system) you should hear some sound on the speaker。

A file sent to /dev/lp0 gets printed。

Sending data to and reading from /dev/ttyS0 will allow you to communicate with a device attached there - for instance, your modem。

比如

/dev/cdrom和/dev/fd0是CD-ROM的驅動檔案,你可以透過此介面讀寫cdrom中內容;

/dev/ttyS0是串列埠驅動,登陸作業系統介面,即使透過此驅動介面建立;

11./home

Linux is a multi-user environment so each user is also assigned a specific directory that is accessible only to them and the system administrator。 These are the user home directories, which can be found under ‘/home/$USER’ (~/)。 It is your playground: everything is at your command, you can write files, delete them, install programs, etc。。。。

多使用者操作環境,每個使用者在此建立自己的home目錄:‘/home/$USER’,使用者可以在自己目錄讀寫檔案、刪除檔案、安裝指令碼等等。

12./mnt

This is a generic mount point under which you mount your filesystems or devices。 Mounting is the process by which you make a filesystem available to the system。 After mounting your files will be accessible under the mount-point。

系統掛載目錄,掛載任意映象或目錄均可掛載在此目錄,當然不掛也沒事~

13./proc

/proc is very special in that it is also a virtual filesystem。 It‘s sometimes referred to as a process information pseudo-file system。 It doesn’t contain ‘real’ files but runtime system information (e。g。 system memory, devices mounted, hardware configuration, etc)。

/proc是一個虛擬檔案目錄,內部檔案均是linux建立的虛擬檔案,可以透過這些檔案,呼叫到linux的鉤子函式,從而和linux核心進行互動,對應linux fs/proc/目錄的。c實現

比如

cat /proc/iomem 可以檢視到系統地址劃分

說明:因為此目錄是linux建立,所以讀寫許可權均已固定,不可更改。

14./var

Contains variable data like system logging files, mail and printer spool directories, and transient and temporary files。

系統資料或臨時資料存放目錄,包括系統log、mail或其他檔案。

比如:

/var/log/kern。log存放核心的日誌

更多可參考

https://www。

tldp。org/LDP/Linux-File

system-Hierarchy/html/c23。html