LINUX

LINUX檔案系統介紹

家目錄(Home directories)

使用者的個人檔案通常都會在/home(一般使用者)或是/root(超級使用者),你的家目錄位於/home/<your-username> (/home/mt, /home/john, etc.)。以下為幾種查看家目錄的方法:

cd指令在沒有指定目錄的情況下,會將你正在工作的目錄變更到家目錄。

環境變數HOME~存放著家目錄的路徑:

⤍ echo $HOME
/home/mt

⤍ echo ~
/home/mt

⤍ echo ~/Documents
/home/mt/Documents

~加上使用者名稱會輸出該使用者的家目錄:

⤍ cd ~john

⤍ pwd
/home/john

系統目錄(System directories)

Linux系統內有非常多的系統目錄,裡面包含了作業系統檔案、應用程式及資料文件等等,基本上除了使用者個人檔案以外的資料都在系統目錄。

除非你是系統管理員,不然應該很少有機會碰到系統目錄,但稍微了解一下你可以對系統內部更熟悉也可以理解到它們存在的用途。

系統目錄名稱可以分成Scope、Category及Application,如下:

/usr/local/  share/  emacs
 ---------   -----   -----
   Scope   Category   App

常見的Scope:

/           System files supplied with Linux.

/usr        More system files supplied with Linux.

/usr/local  System files developed "locally," either your organization or your individual computer.

/usr/games  Games.

常見的Category:

bin          Programs (usually binary files).

sbin         Programs (usually binary files) intended to be run by the superuser.

lib          Libraries of code used by programs.

doc          Documentation.

info         Documentation files for emacs's built-in help system.

man          Documentation files (manual pages) displayed by the man program; the files are often compressed and are sprinkled with typesetting commands for man to interpret.

share        Program-specific files, such as examples and installation instructions.

etc          Configuration files for the system (and other miscellaneous stuff).

init.d       Configuration files for booting Linux.

rc.d         Configuration files for booting Linux; also rc1.d, rc2.d, ...

include      Header files for programming.

src          Source code for programs.

cgi-bin      Scripts/programs that run on web pages.

html         Web pages.

public_html  Web pages, typically in users' home directories.

www          Web pages.

fonts        Fonts.

X11          X window system files.

dev          Device files for interfacing with disks and other hardware.

media        Mount points: directories that provide access to disks.

mnt          Mount points: directories that provide access to disks.

var          File specific to this computer, created and updated as the computer runs.

lock         Lock files, created by programs to say, "I am running"; the existence of a lock file may prevent another program, or another instance of the same program, from running or performing an action.

log          Log files that track important system events, containing error, warning, and informational messages.

mail         Mailboxes for incoming mail.

run          PID files, which contain the IDs of running processes; these files are often consulted to track or kill particular processes.

spool        Files queued or in transit, such as outgoing email, print jobs, and scheduled jobs.

tmp          Temporary storage for programs and/or people to use.

proc         Operating system state.

檔案權限(File permissions)

在Linux系統裡,權限管理分為三個不同的類別:擁有者(Owner)、群組(Group)及其他(Others)。每個類別裡分別又有讀取(Read)、寫入(Write)及執行(Execute)的權限。

要查看一個檔案的擁有者及權限,執行:

⤍ ls -l file
-rw-r--r--  1  mt  eecsmt  2048  Oct  18  2020  file

要查看一個檔案夾的擁有者及權限,需要加上-d

⤍ ls -ld dir
drwxr-x---  2  mt  eecsmt  4096  Mar  20  2019  dir

在輸出中,左邊十個位元所組成的字串就是權限字串,如下:

-rw-r--r--

位置與意義:

Position  Meaning

   1      File type: - = file, d = directory, l = symbolic link, p = named pipe, c = character device, b = block device.

  2-4     Read, write, and execute permissions for the file's owner.

  5-7     Read, write, and execute permissions for the file's group.

  8-10    Read, write, and execute permissions for all other users.

由上表可知權限字串最左邊是檔案的類別,接下來每三個一組分別為擁有者、群組及其他的權限。以-rw-r--r--為例,代表這個檔案可以被擁有者讀(r)與寫(w),可以被群組使用者讀(r),也可以被任何使用者讀(r)

發佈留言