Linux file system All In One
图解 Linux 文件系统
file type
-
file
d
directory
b
block
l
symbol link (soft link / hard link)
file permissions
3 个字组,共三组;
user
permission 用户权限group
permission 组权限other
permission 其他权限
每组符号表示的含义(权重):
w
===4
r
===2
x
===1
可以能的组合,枚举值
wrx
===7
wr-
=== 6w-x
===5
w--
=== 4-rx
=== 3-r-
=== 2--x
=== 1---
=== 0
wrxw-xw-x
=== 755
$ chmod +x
# 等价于
$ chmod 755
chown
changing
ownership
in Linux
$ chown name filename
$ chown name foldername
shell script to change directory
permissions
??? ch dir / change folder ???
$ mkdir folder_test
# chown -R
$ chown -R folder_test
$ man chown > man-chown.md
#!/bin/bash
source /generic/utils/etc/environments/perm.conf
cd $ENVR
DIRS=`ls -l $ENVR | egrep '^d' | awk '{print $9}'`
for DIR in "${DIRS[@]}";
do
echo "$DIR"
echo "Which environment do you want?: "
echo -n "> "
read i
echo "Changing permissions now..."
sudo chown -R $OWN:$GRP "$i" && sudo chmod -R $MOD1 "$i"
#cd $ENVR/$i
#sudo chmod -R $MOD2 *
echo "Permissions are changed!"
done
demos
system environment variables
# global variable
$ export NVM_USER=xgqfrms_pi4b
$ echo $NVM_USER
xgqfrms_pi4b
$ touch test.sh
$ vim test.sh
$ sudo chmod +x ./test.sh
#!/usr/bin/env bash
echo $NVM_USER
echo "string with a variable $NVM_USER"
echo string with a variable $NVM_USER
echo "string with a variable ${NVM_USER}"
# hard link
$ ln test.sh test-hard-link.sh
# soft link
$ ln -s test.sh test-soft-link.sh
$ ls -al
总用量 152
drwxr-xr-x 17 eric eric 4096 10月 8 16:45 .
drwxr-xr-x 4 root root 4096 9月 19 15:51 ..
-rw------- 1 eric eric 16213 10月 8 12:51 .bash_history
-rw-r--r-- 1 eric eric 220 5月 3 10:53 .bash_logout
-rw-r--r-- 1 eric eric 3912 9月 21 13:08 .bashrc
drwxr-xr-x 2 eric eric 4096 5月 3 11:02 Bookshelf
drwxr-xr-x 6 eric eric 4096 9月 20 22:55 .cache
drwx------ 6 eric eric 4096 5月 3 11:24 .config
drwxr-xr-x 4 eric eric 4096 10月 6 23:16 Desktop
drwxr-xr-x 2 eric eric 4096 5月 3 11:24 Documents
drwxr-xr-x 2 eric eric 4096 5月 3 11:24 Downloads
drwxr-xr-x 3 eric eric 4096 5月 3 11:02 .local
drwxr-xr-x 2 eric eric 4096 5月 3 11:24 Music
-rw------- 1 eric eric 111 10月 7 15:37 .node_repl_history
drwxr-xr-x 5 eric eric 4096 10月 7 01:27 .npm
drwxr-xr-x 8 eric eric 4096 9月 21 11:01 .nvm
-rw-r--r-- 1 eric eric 411 9月 21 11:37 nvm_echo_test.sh
drwxr-xr-x 2 eric eric 4096 5月 3 11:24 Pictures
-rw-r--r-- 1 eric eric 807 5月 3 10:53 .profile
drwxr-xr-x 2 eric eric 4096 5月 3 11:24 Public
drwxrwxrwx 2 eric eric 4096 9月 16 04:21 Share
-rwxr-xr-x 1 eric eric 172 9月 21 18:03 shell-env-variable-test.sh
-rwxr-xr-x 1 eric eric 196 9月 21 16:58 shell-variable.sh
drwxr-xr-x 2 eric eric 4096 5月 3 11:24 Templates
-rwxr-xr-x 2 eric eric 156 9月 21 13:15 test-hard-link.sh
-rwxr-xr-x 2 eric eric 156 9月 21 13:15 test.sh
lrwxrwxrwx 1 eric eric 7 10月 8 16:44 test-soft-link.sh -> test.sh
drwxr-xr-x 2 eric eric 4096 5月 3 11:24 Videos
-rw------- 1 eric eric 19119 10月 7 20:47 .viminfo
-rw------- 1 eric eric 50 9月 30 11:48 .Xauthority
-rw------- 1 eric eric 2604 9月 30 11:48 .xsession-errors
-rw------- 1 eric eric 2604 9月 25 22:17 .xsession-errors.old
eric@rpi4b:~ $
$ ls -alh
总用量 152K
drwxr-xr-x 17 eric eric 4.0K 10月 8 16:45 .
drwxr-xr-x 4 root root 4.0K 9月 19 15:51 ..
-rw------- 1 eric eric 16K 10月 8 12:51 .bash_history
-rw-r--r-- 1 eric eric 220 5月 3 10:53 .bash_logout
-rw-r--r-- 1 eric eric 3.9K 9月 21 13:08 .bashrc
drwxr-xr-x 2 eric eric 4.0K 5月 3 11:02 Bookshelf
drwxr-xr-x 6 eric eric 4.0K 9月 20 22:55 .cache
drwx------ 6 eric eric 4.0K 5月 3 11:24 .config
drwxr-xr-x 4 eric eric 4.0K 10月 6 23:16 Desktop
drwxr-xr-x 2 eric eric 4.0K 5月 3 11:24 Documents
drwxr-xr-x 2 eric eric 4.0K 5月 3 11:24 Downloads
drwxr-xr-x 3 eric eric 4.0K 5月 3 11:02 .local
drwxr-xr-x 2 eric eric 4.0K 5月 3 11:24 Music
-rw------- 1 eric eric 111 10月 7 15:37 .node_repl_history
drwxr-xr-x 5 eric eric 4.0K 10月 7 01:27 .npm
drwxr-xr-x 8 eric eric 4.0K 9月 21 11:01 .nvm
-rw-r--r-- 1 eric eric 411 9月 21 11:37 nvm_echo_test.sh
drwxr-xr-x 2 eric eric 4.0K 5月 3 11:24 Pictures
-rw-r--r-- 1 eric eric 807 5月 3 10:53 .profile
drwxr-xr-x 2 eric eric 4.0K 5月 3 11:24 Public
drwxrwxrwx 2 eric eric 4.0K 9月 16 04:21 Share
-rwxr-xr-x 1 eric eric 172 9月 21 18:03 shell-env-variable-test.sh
-rwxr-xr-x 1 eric eric 196 9月 21 16:58 shell-variable.sh
drwxr-xr-x 2 eric eric 4.0K 5月 3 11:24 Templates
-rwxr-xr-x 2 eric eric 156 9月 21 13:15 test-hard-link.sh
-rwxr-xr-x 2 eric eric 156 9月 21 13:15 test.sh
lrwxrwxrwx 1 eric eric 7 10月 8 16:44 test-soft-link.sh -> test.sh
drwxr-xr-x 2 eric eric 4.0K 5月 3 11:24 Videos
-rw------- 1 eric eric 19K 10月 7 20:47 .viminfo
-rw------- 1 eric eric 50 9月 30 11:48 .Xauthority
-rw------- 1 eric eric 2.6K 9月 30 11:48 .xsession-errors
-rw------- 1 eric eric 2.6K 9月 25 22:17 .xsession-errors.old
(? 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
软链接 vs 硬链接
软链接,是创建一个新的链接文件(内容为空), 链接到原文件(指向原文件),文件小 7
Bytes,创建时间更新;
硬链接,是创建一个全新的原文件副本(内容完全复制),文件大 156
Bytes,创建时间不变;
lrwxrwxrwx 1 eric eric 7 10月 8 16:44 test-soft-link.sh -> test.sh
-rwxr-xr-x 2 eric eric 156 9月 21 13:15 test-hard-link.sh
-rwxr-xr-x 2 eric eric 156 9月 21 13:15 test.sh
# 按时间排序 (逆序)
$ ls -alht
总用量 152K
drwxr-xr-x 17 eric eric 4.0K 10月 8 16:45 .
lrwxrwxrwx 1 eric eric 7 10月 8 16:44 test-soft-link.sh -> test.sh
-rw------- 1 eric eric 16K 10月 8 12:51 .bash_history
-rw------- 1 eric eric 19K 10月 7 20:47 .viminfo
-rw------- 1 eric eric 111 10月 7 15:37 .node_repl_history
drwxr-xr-x 5 eric eric 4.0K 10月 7 01:27 .npm
drwxr-xr-x 4 eric eric 4.0K 10月 6 23:16 Desktop
-rw------- 1 eric eric 2.6K 9月 30 11:48 .xsession-errors
-rw------- 1 eric eric 50 9月 30 11:48 .Xauthority
-rw------- 1 eric eric 2.6K 9月 25 22:17 .xsession-errors.old
-rwxr-xr-x 1 eric eric 172 9月 21 18:03 shell-env-variable-test.sh
-rwxr-xr-x 1 eric eric 196 9月 21 16:58 shell-variable.sh
-rwxr-xr-x 2 eric eric 156 9月 21 13:15 test-hard-link.sh
-rwxr-xr-x 2 eric eric 156 9月 21 13:15 test.sh
-rw-r--r-- 1 eric eric 3.9K 9月 21 13:08 .bashrc
-rw-r--r-- 1 eric eric 411 9月 21 11:37 nvm_echo_test.sh
drwxr-xr-x 8 eric eric 4.0K 9月 21 11:01 .nvm
drwxr-xr-x 6 eric eric 4.0K 9月 20 22:55 .cache
drwxr-xr-x 4 root root 4.0K 9月 19 15:51 ..
drwxrwxrwx 2 eric eric 4.0K 9月 16 04:21 Share
drwx------ 6 eric eric 4.0K 5月 3 11:24 .config
drwxr-xr-x 2 eric eric 4.0K 5月 3 11:24 Documents
drwxr-xr-x 2 eric eric 4.0K 5月 3 11:24 Downloads
drwxr-xr-x 2 eric eric 4.0K 5月 3 11:24 Music
drwxr-xr-x 2 eric eric 4.0K 5月 3 11:24 Pictures
drwxr-xr-x 2 eric eric 4.0K 5月 3 11:24 Public
drwxr-xr-x 2 eric eric 4.0K 5月 3 11:24 Templates
drwxr-xr-x 2 eric eric 4.0K 5月 3 11:24 Videos
drwxr-xr-x 2 eric eric 4.0K 5月 3 11:02 Bookshelf
drwxr-xr-x 3 eric eric 4.0K 5月 3 11:02 .local
-rw-r--r-- 1 eric eric 220 5月 3 10:53 .bash_logout
-rw-r--r-- 1 eric eric 807 5月 3 10:53 .profile
refs
https://www.pluralsight.com/blog/it-ops/linux-file-permissions
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 ?️,侵权必究⚠️!