日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux基础命令篇一

發布時間:2024/4/17 linux 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux基础命令篇一 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

此篇博客目錄:

1.????linux系統目錄結構

2.????ls命令

3.????文件類型

4.????alias命令

5.????相對路徑和絕對路徑

6.????cd命令

7.????mkdir and rmdir

8.????rm命令

9.????環境變量PATH

10.? cp命令

11.? mv命令

12.? 文檔查看(cat more less head tail)

13.? chmod命令

14.? chown and chgrp 命令

15.? umask命令

?

linux系統目錄結構介紹:

使用 tree -L 1 / 命令查詢整個根目錄:

[root@ln /]# tree -L 1/

.

├── bin -> usr/bin 用來儲存系統命令的文件目錄

├── boot 系統啟動相關文件目錄

├── dev 設備文件目錄

├── etc 系統配置文件目錄

├── home 用戶家目錄

├── lib -> usr/lib 庫文件目錄

├── lib64 -> usr/lib64 庫文件目錄

├── media 媒介目錄

├── mnt 臨時掛載目錄

├── opt 空目錄

├── proc 系統啟動進程目錄 !

├── qq (這個是我自己創建的。。略過)

├── root 用戶家目錄

├── run 一些進程產生的臨時文件

├── sbin -> usr/sbin 用來儲存系統命令的文件目錄

├── srv 空目錄--存服務產生的一些文件

├── sys 存系統內核文件

├── tmp 系統的臨時目錄

├── usr 存儲用戶文件

└── var 存儲系統日志

上圖中有 -> 這個符號 后面跟了個目錄。 這個意思代表是軟鏈接的意思。后面會詳解

系統目錄文件夾圖片:http://www.apelearn.com/study_v2/linux_dir_tree.jpg

?

?

LS 命令:

ls 顯示該目錄下的所有文件(但不包括隱藏文件)

[root@ln ~]# ls

1 1.txt 2.txt 3.txt 4.txt 666 anaconda-ks.cfg qq qw qwe

[root@ln ~]#

?

-a 顯示該目錄下的所有文件(包括隱藏文件)

[root@ln ~]# ls -a

. 1 2.txt 4.txt anaconda-ks.cfg .bash_logout .bashrc qq qwe .tcshrc

.. 1.txt 3.txt 666 .bash_history .bash_profile .cshrc qw .ssh .viminfo

[root@ln ~]#

?

-l 顯示該目錄下所有文件的詳細信息

[root@ln ~]# ls -l

總用量 8

-rw-r--r--. 1 root root 0 5月 3 22:51 1

-rw-rw-r--. 1 root root 0 5月 10 07:16 1.txt

-rw-r--r--. 1 root root 0 5月 10 04:55 2.txt

-rw-r--r--. 1 root root 0 5月 10 07:17 3.txt

-rw-rw-r--. 1 root root 0 5月 10 07:20 4.txt

-rw-r--r--. 1 root root 28 5月 3 23:03 666

-rw-------. 1 root root 1368 5月 4 06:24 anaconda-ks.cfg

drwxrwxrwx. 3 root root 67 5月 10 05:04 qq

drwxrwxr-x. 2 root root 6 5月 10 05:05 qw

drwxrwxr-x. 2 root root 6 5月 10 07:19 qwe

[root@ln ~]#

?

-l 命令 等于 ll 命令

[root@ln ~]# ll

總用量 8

-rw-r--r--. 1 root root 0 5月 3 22:51 1

-rw-rw-r--. 1 root root 0 5月 10 07:16 1.txt

-rw-r--r--. 1 root root 0 5月 10 04:55 2.txt

-rw-r--r--. 1 root root 0 5月 10 07:17 3.txt

-rw-rw-r--. 1 root root 0 5月 10 07:20 4.txt

-rw-r--r--. 1 root root 28 5月 3 23:03 666

-rw-------. 1 root root 1368 5月 4 06:24 anaconda-ks.cfg

drwxrwxrwx. 3 root root 67 5月 10 05:04 qq

drwxrwxr-x. 2 root root 6 5月 10 05:05 qw

drwxrwxr-x. 2 root root 6 5月 10 07:19 qwe

[root@ln ~]#

?

-t 按時間排序

[root@ln ~]# ls -lt

總用量 8

-rw-rw-r--. 1 root root 0 5月 10 07:20 4.txt

drwxrwxr-x. 2 root root 6 5月 10 07:19 qwe

-rw-r--r--. 1 root root 0 5月 10 07:17 3.txt

-rw-rw-r--. 1 root root 0 5月 10 07:16 1.txt

drwxrwxr-x. 2 root root 6 5月 10 05:05 qw

drwxrwxrwx. 3 root root 67 5月 10 05:04 qq

-rw-r--r--. 1 root root 0 5月 10 04:55 2.txt

-rw-------. 1 root root 1368 5月 4 06:24 anaconda-ks.cfg

-rw-r--r--. 1 root root 28 5月 3 23:03 666

-rw-r--r--. 1 root root 0 5月 3 22:51 1

[root@ln ~]#

?

-d 只顯示目錄

[root@ln ~]# ls -d

.

[root@ln ~]#

?

?

文件類型:

?

普通文件(-表示,可用ls -l查看)

目錄(d)

字符設備文件(c)

塊設備文件(b)

套接口文件(s)

管道(p)

符號鏈接文件(l)

?

?

Alias命令:

?

查看系統里面所有的命令別名

[root@ln ~]# 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-tilde'

[root@ln ~]#

?

創建一個別名 alias ln=‘ls -l’

[root@ln ~]# alias ln='ls -l'

[root@ln ~]# ln

總用量 8

-rw-r--r--. 1 root root 0 5月 3 22:51 1

-rw-rw-r--. 1 root root 0 5月 10 07:16 1.txt

-rw-r--r--. 1 root root 0 5月 10 04:55 2.txt

-rw-r--r--. 1 root root 0 5月 10 07:17 3.txt

-rw-rw-r--. 1 root root 0 5月 10 07:20 4.txt

-rw-r--r--. 1 root root 28 5月 3 23:03 666

-rw-------. 1 root root 1368 5月 4 06:24 anaconda-ks.cfg

drwxrwxrwx. 3 root root 67 5月 10 05:04 qq

drwxrwxr-x. 2 root root 6 5月 10 05:05 qw

drwxrwxr-x. 2 root root 6 5月 10 07:19 qwe

[root@ln ~]#

?

取消別名 unalias ln

[root@ln ~]# unalias ln

[root@ln ~]# ln

ln: 缺少了文件操作數

Try 'ln --help' for more information.

[root@ln ~]#

?

?

相對路徑和絕對路徑:

?

絕對路徑:

從根開始的路徑,它指定到的目錄或者文件具有唯一性,意思是不管目前在哪一個目錄下面,你只要使用絕對路徑就可以定位到系統任何一個目錄或文件。

相對路徑:

相對于當前目錄,要定位到一個目錄或文件所經過的路徑

?

CD命令:

cd 進入用戶的家目錄 等同于 cd ~

[root@ln /]# pwd

/

[root@ln /]# cd

[root@ln ~]# pwd

/root

[root@ln ~]#

?

cd . 表示當前的目錄

[root@ln ~]# pwd

/root

[root@ln ~]# cd .

[root@ln ~]# pwd

/root

[root@ln ~]#

?

cd .. 表示進入上一級目錄

[root@ln ~]# pwd

/root

[root@ln ~]# cd ..

[root@ln /]# pwd

/

[root@ln /]#

?

cd - 表示在當前目錄和上一個目錄之間來回切換

[root@ln ~]# cd -

/

[root@ln /]# cd -

/root

[root@ln ~]#

?

?

MKDIR and RMDIR:

?

MKDIR:創建目錄

?

-p 遞歸創建目錄

[root@ln ~]# mkdir -p /qw/ln/1

[root@ln ~]# tree /qw

/qw

└── ln

└── 1

2 directories, 0 files

[root@ln ~]#

?

RMDIR:刪除目錄

[root@ln ~]# rmdir /qw/ln/1

[root@ln ~]# tree /qw

/qw

└── ln

1 directory, 0 files

[root@ln ~]#

但僅能刪除非空目錄

[root@ln ~]# rmdir /qw/ln

rmdir: 刪除 "/qw/ln" 失敗: 目錄非空

[root@ln ~]#

?

?

RM命令:

?

[root@ln ~]# ls

2.txt 3.txt 4.txt 666 anaconda-ks.cfg qq qw qwe

[root@ln ~]# rm 2.txt

rm:是否刪除普通文件 "2.txt"?y

[root@ln ~]# ls

3.txt 4.txt 666 anaconda-ks.cfg qq qw qwe

[root@ln ~]#

?

-r 刪除目錄

[root@ln qw]# tree /qw

/qw

└── ln

└── 1

├── 2

└── 3

4 directories, 0 files

[root@ln qw]# rm -r /qw/ln/1/2

rm:是否刪除目錄 "/qw/ln/1/2"?y

[root@ln qw]# tree /qw

/qw

└── ln

└── 1

└── 3

3 directories, 0 files

[root@ln qw]#

?

-rf 沒有提示直接刪除

[root@ln ~]# ls

3.txt 4.txt 666 anaconda-ks.cfg qq qw qwe

[root@ln ~]# rm -rf 666

[root@ln ~]# ls

3.txt 4.txt anaconda-ks.cfg qq qw qwe

[root@ln ~]#

?

?

PATH環境變量:

新定義一個環境變量

[root@ln ~]# export HELLO='ln'

[root@ln ~]# echo $HELLO

ln

[root@ln ~]#

?

在環境變量中,可以直接查找,不用絕對路徑。用echo $PATH查看環境變量

[root@ln ~]# echo $PATH

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

由于 ls 在/usr/bin/ 下 所以輸入ls命令就不需要輸入它的絕對路徑。

[root@ln ~]# ls

3.txt 4.txt anaconda-ks.cfg qq qw qwe

[root@ln ~]# cp /usr/bin/ls /tmp/ls2

[root@ln ~]# /tmp/ls2

3.txt 4.txt anaconda-ks.cfg qq qw qwe

[root@ln ~]# ls2

-bash: ls2: 未找到命令

[root@ln ~]#

?

現在我在環境變量中增加一個 /tmp/ 目錄 這樣 ls2也就可以直接執行

1. 第一步 先 輸入命令: vi /etc/profile

2. 進入后 把光標移動到最后 在最末尾增加一行命令 PATH=$PATH:/TMP/ 后 wq保存退出

完成之后 輸入命令查看 echo $PATH 就會看到增加了一個 /tmp/

[root@ln ~]# echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/tmp/:/root/bin

[root@ln ~]#

現在 輸入 ls2 命令 就可以直接使用了.

[root@ln ~]# ls2

3.txt 4.txt anaconda-ks.cfg qq qw qwe

[root@ln ~]#

如果你不需要增加這個環境變量那么就還是進入/etc/profile 刪除掉你增加的那一行就可以了

再次 echo $PATH 就沒有這個環境變量了

[root@ln ~]# echo $PATH

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

[root@ln ~]# ls2

-bash: ls2: 未找到命令

[root@ln ~]#

這是在目錄里增加環境變量的方法,還有一種 直接復制增加就行,步驟如下:

[root@ln ~]# echo $PATH

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

[root@ln ~]# PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/

[root@ln ~]# echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/

[root@ln ~]# ls2

3.txt 4.txt anaconda-ks.cfg qq qw qwe

[root@ln ~]#

先查詢PATH 然后直接復制你需要保留的部分,在末尾甚至其他地方增加你所需要加入的環境變量,格式 :/目錄/

保存后在查詢 就可以看到你后加的變量了。在輸入ls2 也可以生效

?

?

CP命令:

-a:此參數的效果和同時指定"-dpR"參數相同;

-d:當復制符號連接時,把目標文件或目錄也建立為符號連接,并指向與源文件或目錄連接的原始文件或目錄;

-f:強行復制文件或目錄,不論目標文件或目錄是否已存在;

-i:覆蓋既有文件之前先詢問用戶;

-l:對源文件建立硬連接,而非復制文件;

-p:保留源文件或目錄的屬性;

-R/r:遞歸處理,將指定目錄下的所有文件與子目錄一并處理;

-s:對源文件建立符號連接,而非復制文件;

-u:使用這項參數后只會在源文件的更改時間較目標文件更新時或是名稱相互對應的目標文件并不存在時,才復制文件;

-S:在備份文件時,用指定的后綴“SUFFIX”代替文件的默認后綴;

-b:覆蓋已存在的文件目標前將目標文件備份;

-v:詳細顯示命令執行的操作。

?

復制3.txt文檔到當前目錄 并改名為 1.txt

[root@ln ~]# ls

3.txt 4.txt anaconda-ks.cfg qq qw qwe

[root@ln ~]# cp 3.txt 1.txt

[root@ln ~]# ls

1.txt 3.txt 4.txt anaconda-ks.cfg qq qw qwe

[root@ln ~]#

?

復制 qw目錄下的所有文件至 wq下

[root@ln ~]# ls

1.txt 3.txt 4.txt anaconda-ks.cfg qq qw qwe

[root@ln ~]# ls /qw

ln

[root@ln ~]# tree /qw

/qw

└── ln

└── 1

└── 3

3 directories, 0 files

[root@ln ~]# cp -r /qw /wq

[root@ln ~]# tree /wq

/wq

└── ln

└── 1

└── 3

3 directories, 0 files

[root@ln ~]#

?

?

MV命令:

用來對文件或目錄重新命名,或者將文件從一個目錄移到另一個目錄中

將 1.txt 改名為 2.txt

[root@ln ~]# ls

1.txt 3.txt 4.txt anaconda-ks.cfg qq qw qwe

[root@ln ~]# mv 1.txt 2.txt

[root@ln ~]# ls

2.txt 3.txt 4.txt anaconda-ks.cfg qq qw qwe

[root@ln ~]#

?

將 qw目錄下的所有文件 移動至 當前目錄

[root@ln ~]# ls

2.txt 3.txt 4.txt anaconda-ks.cfg qq qw qwe

[root@ln ~]# mv /qw/ln/* .

[root@ln ~]# ls

1 2.txt 3.txt 4.txt anaconda-ks.cfg qq qw qwe

[root@ln ~]# tree 1

1

└── 3

1 directory, 0 files

[root@ln ~]#

?

?

查看命令:cat more less head tail

?

cat 查看一個文件內容

[root@ln ~]# cat 2.txt

qwertyuiop

[root@ln ~]#

?

同時查看多個文件

[root@ln ~]# cat 2.txt 3.txt

qwertyuiop

sdfgh

[root@ln ~]#

?

more 以全屏幕的方式按頁顯示文本文件的內容

按Space鍵:顯示文本的下一屏內容。

按Enier鍵:只顯示文本的下一行內容。

按斜線符|:接著輸入一個模式,可以在文本中尋找下一個相匹配的模式。

按H鍵:顯示幫助屏,該屏上有相關的幫助信息。

按B鍵:顯示上一屏內容。

按Q鍵:退出rnore命令

?

less 作用與more十分相似,都可以用來瀏覽文字檔案的內容,不同的是less命令允許用戶向前或向后瀏覽文件,而more命令只能向前瀏覽 用PageUp鍵向上翻頁,用PageDown鍵向下翻頁。要退出less程序,應按Q鍵。

-e:文件內容顯示完畢后,自動退出;

-f:強制顯示文件;

-g:不加亮顯示搜索到的所有關鍵詞,僅顯示當前顯示的關鍵字,以提高顯示速度;

-l:搜索時忽略大小寫的差異;

-N:每一行行首顯示行號;

-s:將連續多個空行壓縮成一行顯示;

-S:在單行顯示較長的內容,而不換行顯示;

-x<數字>:將TAB字符顯示為指定個數的空格字符。

?

head 用于顯示文件的開頭的內容 不輸入參數,默認顯示頭十行

-n<數字>:指定顯示頭部內容的行數;

-c<字符數>:指定顯示頭部內容的字符數;

-v:總是顯示文件名的頭信息;

-q:不顯示文件名的頭信息。

head + 文件名 默認查看前十行

[root@ln ~]# head 2.txt

qwee

qwertyuiop

a

s

d

f

g

h

h

j

[root@ln ~]#

?

查看前3行

[root@ln ~]# head -n 3 2.txt

qwee

qwertyuiop

a

[root@ln ~]#

?

tail 用于輸入文件中的尾部內容。tail命令默認在屏幕上顯示指定文件的末尾10行

顯示尾部十行

[root@ln ~]# tail 2.txt

h

j

k

k

?

l

?

l

?

l

[root@ln ~]#

?

?

CHMOD命令:

用來變更文件或目錄的權限

chmod u+x,g+w f01  //為文件f01設置自己可以執行,組員可以寫入的權限

chmod u=rwx,g=rw,o=r f01

chmod 764 f01

chmod a+x f01  //對文件f01的u,g,o都設置可執行屬性

?

[root@ln ~]# ll

總用量 12

drwxr-xr-x. 3 root root 15 5月 10 12:05 1

-rw-r--r--. 1 root root 45 5月 13 09:50 2.txt

-rw-r--r--. 1 root root 6 5月 13 09:42 3.txt

-rw-rw-r--. 1 root root 0 5月 10 07:20 4.txt

-rw-------. 1 root root 1368 5月 4 06:24 anaconda-ks.cfg

drwxrwxrwx. 3 root root 67 5月 10 05:04 qq

drwxrwxr-x. 2 root root 6 5月 10 05:05 qw

drwxrwxr-x. 2 root root 6 5月 10 07:19 qwe

[root@ln ~]#

d 開頭的是目錄, - 開頭的是普通文件。

rwx 為權限 以數字表示 r=4 w=2 x=1 滿權限為 7

按ll 顯示的內容 除去第一個字符外 后為 九個字符

分為3組 屬主 屬組 其他人 每組都是一個rwx 滿權限為777

?

修改 1文件夾 權限為777

[root@ln ~]# chmod 777 1

[root@ln ~]# ll

總用量 12

drwxrwxrwx. 3 root root 15 5月 10 12:05 1

-rw-r--r--. 1 root root 45 5月 13 09:50 2.txt

-rw-r--r--. 1 root root 6 5月 13 09:42 3.txt

-rw-rw-r--. 1 root root 0 5月 10 07:20 4.txt

-rw-------. 1 root root 1368 5月 4 06:24 anaconda-ks.cfg

drwxrwxrwx. 3 root root 67 5月 10 05:04 qq

drwxrwxr-x. 2 root root 6 5月 10 05:05 qw

drwxrwxr-x. 2 root root 6 5月 10 07:19 qwe

[root@ln ~]#

?

1文件夾所有用戶都不允許寫入

[root@ln ~]# chmod a-w 1

[root@ln ~]# ll

總用量 12

dr-xr-xr-x. 3 root root 15 5月 10 12:05 1

-rw-r--r--. 1 root root 45 5月 13 09:50 2.txt

-rw-r--r--. 1 root root 6 5月 13 09:42 3.txt

-rw-rw-r--. 1 root root 0 5月 10 07:20 4.txt

-rw-------. 1 root root 1368 5月 4 06:24 anaconda-ks.cfg

drwxrwxrwx. 3 root root 67 5月 10 05:04 qq

drwxrwxr-x. 2 root root 6 5月 10 05:05 qw

drwxrwxr-x. 2 root root 6 5月 10 07:19 qwe

[root@ln ~]#

?

- R 修改目錄下的目錄及文件 權限

[root@ln ~]# ll 1

總用量 0

-rw-r--r--. 1 root root 0 5月 13 10:56 1.txt

drwxr-xr-x. 2 root root 6 5月 10 12:03 3

[root@ln ~]# chmod -R 440 1

[root@ln ~]# ll 1

總用量 0

-r--r-----. 1 root root 0 5月 13 10:56 1.txt

dr--r-----. 2 root root 6 5月 10 12:03 3

[root@ln ~]#

?

?

CHGRP and CHOWN命令:

CHGRP 用來改變文件或目錄所屬的用戶組

?

[root@ln ~]# groupadd user1

[root@ln ~]# ll

總用量 12

dr--r-----. 3 root root 28 5月 13 10:56 1

-rw-r--r--. 1 root root 45 5月 13 09:50 2.txt

-rw-r--r--. 1 root root 6 5月 13 09:42 3.txt

-rw-rw-r--. 1 root root 0 5月 10 07:20 4.txt

-rw-------. 1 root root 1368 5月 4 06:24 anaconda-ks.cfg

drwxrwxrwx. 3 root root 67 5月 10 05:04 qq

drwxrwxr-x. 2 root root 6 5月 10 05:05 qw

drwxrwxr-x. 2 root root 6 5月 10 07:19 qwe

[root@ln ~]# chgrp user1 2.txt

[root@ln ~]# ll

總用量 12

dr--r-----. 3 root root 28 5月 13 10:56 1

-rw-r--r--. 1 root user1 45 5月 13 09:50 2.txt

-rw-r--r--. 1 root root 6 5月 13 09:42 3.txt

-rw-rw-r--. 1 root root 0 5月 10 07:20 4.txt

-rw-------. 1 root root 1368 5月 4 06:24 anaconda-ks.cfg

drwxrwxrwx. 3 root root 67 5月 10 05:04 qq

drwxrwxr-x. 2 root root 6 5月 10 05:05 qw

drwxrwxr-x. 2 root root 6 5月 10 07:19 qwe

[root@ln ~]#

?

-R 修改目錄下的所有目錄及文件的 組

[root@ln ~]# ll 1

總用量 0

-r--r-----. 1 root root 0 5月 13 10:56 1.txt

dr--r-----. 2 root root 6 5月 10 12:03 3

[root@ln ~]# chgrp -R user1 1

[root@ln ~]# ll 1

總用量 0

-r--r-----. 1 root user1 0 5月 13 10:56 1.txt

dr--r-----. 2 root user1 6 5月 10 12:03 3

[root@ln ~]#

?

CHOWN 用來改變文件或目錄所屬的用戶組

[root@ln ~]# chown apache 3.txt

[root@ln ~]# ll

總用量 12

dr--r-----. 3 root user1 28 5月 13 10:56 1

-rw-r--r--. 1 root user1 45 5月 13 09:50 2.txt

-rw-r--r--. 1 apache root 6 5月 13 09:42 3.txt

-rw-rw-r--. 1 root root 0 5月 10 07:20 4.txt

-rw-------. 1 root root 1368 5月 4 06:24 anaconda-ks.cfg

drwxrwxrwx. 3 root root 67 5月 10 05:04 qq

drwxrwxr-x. 2 root root 6 5月 10 05:05 qw

drwxrwxr-x. 2 root root 6 5月 10 07:19 qwe

[root@ln ~]#

?

- R 修改目錄下的所有目錄及文件的 組

[root@ln ~]# ls -la /qq

總用量 0

drwxr-xr-x. 3 root root 19 5月 10 04:59 .

dr-xr-xr-x. 20 root root 275 5月 13 09:17 ..

drwxr-xr-x. 2 root root 6 5月 10 04:59 1.txt

[root@ln ~]# chown -R apache /qq/

[root@ln ~]# ls -la /qq

總用量 0

drwxr-xr-x. 3 apache root 19 5月 10 04:59 .

dr-xr-xr-x. 20 root root 275 5月 13 09:17 ..

drwxr-xr-x. 2 apache root 6 5月 10 04:59 1.txt

[root@ln ~]#

這里由于 ' .. ' 是代表上級目錄 所以沒有修改 而代表本級目錄的 ' . ' 已經被修改了

?

?

UMASK命令:

umask 設置默認權限

輸入umask 顯示 系統 默認權限 0022 只看后三位 也就是 022 新建目錄的權限為 755

[root@ln ~]# umask

0022

[root@ln ~]# mkdir asd

[root@ln ~]# ll

總用量 4

-rw-------. 1 root root 1368 5月 4 06:24 anaconda-ks.cfg

drwxr-xr-x. 2 root root 6 5月 13 11:24 asd

[root@ln ~]#

?

在umask不自定義前,目錄權限值為:755,普通文件權限值為:644

[root@ln ~]# touch 1.txt

[root@ln ~]# ll

總用量 4

-rw-r--r--. 1 root root 0 5月 13 11:26 1.txt

-rw-------. 1 root root 1368 5月 4 06:24 anaconda-ks.cfg

drwxr-xr-x. 2 root root 6 5月 13 11:24 asd

[root@ln ~]#

?

設置umask為001 后新建目錄及文件

[root@ln ~]# umask 001

[root@ln ~]# umask

0001

[root@ln ~]# mkdir zxc

[root@ln ~]# touch 2.txt

[root@ln ~]# ll

總用量 4

-rw-rw-rw-. 1 root root 0 5月 13 11:29 2.txt

-rw-------. 1 root root 1368 5月 4 06:24 anaconda-ks.cfg

drwxr-xr-x. 2 root root 6 5月 13 11:24 asd

drwxrwxrw-. 2 root root 6 5月 13 11:29 zxc

[root@ln ~]#

?

文件權限算法是: rw-rw-rw- (666) -- - - - - - - - -x(001 umask權限) = 666 由于 1權限是x 默認 666是 rw-rw-rw- 沒有x的,所以權限就還是666

目錄的權限則就是 777 - 001(umask權限) = 776

?

?

?

轉載于:https://my.oschina.net/u/3851489/blog/1811585

總結

以上是生活随笔為你收集整理的linux基础命令篇一的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。