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下crontab命令的用法Linux
- Linux下echo命令的用法Linux
- Linux下touch命令的用法Linux
- Linux下history命令用法Linux
- linux下date命令用法Linux
- Linux下find命令的用法(轉)Linux
- Linux——基礎命令用法(下)Linux
- linux命令下jq的用法簡介Linux
- Linux下more命令高階用法Linux
- Linux下mv命令高階用法Linux
- linux下xargs命令用法詳解Linux
- LINUX下RPM命令基本用法Linux
- Linux下crontab命令的用法:sudo crontab -lLinux
- Linux下 ls 命令的高階用法8例Linux
- linux下grep命令用法例項教程Linux
- linux 的xargs命令用法Linux
- Linux 命令“ls ” 的用法Linux
- Linux下RPM 命令用法中文簡介Linux
- linux中的掩碼 umaskLinux
- 關閉 linux下的umask( )函式、setsid( )函式Linux函式
- linux的nohup命令的用法。Linux
- Linux 下使用 killall 命令終止程式的 8 大用法Linux
- linux下find(檔案查詢)命令的用法總結Linux
- linux 中 date命令的用法Linux
- Linux sed命令用法Linux
- linux du命令用法Linux
- Linux 命令 indent 用法Linux
- 修改linux預設檔案建立許可權-umask命令解析Linux
- linux下 date的用法Linux
- Linux 下的 vi 用法Linux
- Linux下scp的用法Linux
- linux 下 free的用法Linux
- Linux高階命令——cut命令用法Linux
- linux useradd命令的基本用法Linux
- Linux 的 fmt 命令用法與案例Linux
- rocky與linux的nmcli命令用法Linux