Linux下umask命令的用法
umask設定新文件的預設屬性,有字元表達形式(Symbolic values)和八進位制表達形式(Octal values)兩種。
1 為所有使用者統一修改預設的umask
You can setup umask in /etc/bashrc or /etc/profile file for all users. By default most Linux distro set it to 0022 (022) or 0002 (002). Open /etc/profile or ~/.bashrc file, enter:
# vi /etc/profile
OR
$ vi ~/.bashrc
Append/modify following line to setup a new umask:
umask 022
Save and close the file. Changes will take effect after next login. All UNIX users can override the system umask defaults in their /etc/profile file, ~/.profile (Korn / Bourne shell) ~/.cshrc file (C shells), ~/.bash_profile (Bash shell) or ~/.login file (defines the user’s environment at login).
2 常用的umask
1)A umask of 022 allows only you to write data, but anyone can read data.
2)A umask of 077 is good for a completely private system. No other user can read or write your data if umask is set to 077.
3)A umask of 002 is good when you share data with other users in the same group. Members of your group can create and modify data files; those outside your group can read data file, but cannot modify it.
4)Set your umask to 007 to completely exclude users who are not group members.
3 數字的詳細含義
Octal value : Permission
0 : read, write and execute
1 : read and write
2 : read and execute
3 : read only
4 : write and execute
5 : write only
6 : execute only
7 : no permissions
To set the umask 077 type the following command at shell prompt:
$ umask 077
$ mkdir dir1
$ touch file
$ ls -ld dir1 file
Sample outputs:
drwx------ 2 vivek vivek 4096 2011-03-04 02:05 dir1
-rw------- 1 vivek vivek 0 2011-03-04 02:05 file
理解上:
**(1)講umask看做【Owner,Group,Others】三個物件的原始預設屬性中需要去掉哪些許可權(r=4, w=2, x=1, -=0)。例如,umask=003則表示Owner不用去掉任何許可權,Group不需要去掉任何許可權,Others需要去掉2+1即為w和x許可權。
(2)檔案的原始預設屬性是666(-rw-rw-rw-),目錄的原始預設屬性為777(drwxrwxrwx)。**
4 用字元表達形式設定umask
r : read
w : write
x : execute
u : User ownership (user who owns the file)
g : group ownership (the permissions granted to other users who are
members of the file’s group)
o : other ownership (the permissions granted to users that are in
neither of the two preceding categories)
The following command will set umask to 077 i.e. a umask set to u=rwx,g=,o= will result in new files having the modes -rw——-, and new directories having the modes drwx——:
$ umask u=rwx,g=,o=
$ mkdir dir2
$ touch file2
$ ls -ld dir2 file2
相關文章
- linux基礎命令—umaskLinux
- Linux基礎命令---umaskLinux
- Linux umask 命令詳解Linux
- Linux——基礎命令用法(下)Linux
- linux命令下jq的用法簡介Linux
- Linux下more命令高階用法Linux
- Linux下mv命令高階用法Linux
- Linux下crontab命令的用法:sudo crontab -lLinux
- Linux下 ls 命令的高階用法8例Linux
- linux 中 date命令的用法Linux
- linux useradd命令的基本用法Linux
- Linux sed命令用法Linux
- Linux 下使用 killall 命令終止程式的 8 大用法Linux
- 修改linux預設檔案建立許可權-umask命令解析Linux
- rocky與linux的nmcli命令用法Linux
- Linux命令-Sed用法教程Linux
- 常用的Linux命令;Linux常用命令用法及實現方式Linux
- Linux——基礎命令用法(上)Linux
- Linux 命令列:find 的 26 個用法示例Linux命令列
- Linux常用命令之使用者許可權管理chmod、chown、chgrp、umask命令講解Linux
- linux下mail的簡單用法LinuxAI
- Linux之程序掩碼umask詳解。Linux
- Linux命令列:cURL的十種常見用法Linux命令列
- linux後臺執行命令:&與nohup的用法Linux
- linux中查詢find命令的複雜用法Linux
- linux下source命令Linux
- Linux下Ollama命令Linux
- linux下查詢命令的技巧Linux
- 命令列中常見命令用法及explainshell.com的用法命令列AI
- Linux常用命令用法及實現方式Linux
- 在Linux中,umask 和 ulimit有什麼區別?LinuxMIT
- Linux最常用的5個重啟命令基本用法講解!Linux
- Linux 命令列下的好東西Linux命令列
- Linux下 ln 命令詳解Linux
- Linux下常用命令Linux
- Linux 下 常見操作命令Linux
- linux下的命令列播放器mocLinux命令列播放器
- Linux下刪除資料夾的命令Linux
- Linux系統下強大的ethtool命令Linux