Linux命令- 文件与用户权限

本文涉及的产品
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
云数据库 Tair(兼容Redis),内存型 2GB
简介:

文件权限讲解:

drwxr-xr-x  2           tangym            tangym           4096        May 29  2015 Desktop
          [LinkCount]  [CurrentUser]    [CurrentGroup]   [FileSize]  [CreationTime]
Field1: self permission
drwxr-
d:direcory
rwx: read,write,Execute,

Field2: current group's user permission
r-x:

Field3: other group's user permission
r-x


|------Change file owner and workgroup -----|
tangym@ubuntu:~$ mkdir mvhello
tangym@ubuntu:~$ ls -l mvhello
total 0
tangym@ubuntu:~$ ls -l
total 204136
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Desktop
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Documents
drwxr-xr-x  3 tangym tangym         4096 May 14 08:53 Downloads
-rw-r--r--  1 tangym tangym         8445 May 29  2015 examples.desktop
-rw-rw-r--  1 tangym tangym        10240 Jan 20  2011 ez_setup.py
drwxrwxr-x  2 tangym tangym         4096 May 24 23:37 mhydir
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Music
drwxrwxr-x  2 tangym tangym         4096 May 24 23:49 mvhello
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Pictures
-rw-rw-r--  1 tangym tangym            0 May 24 22:42 pse
-rw-rw-r--  1 tangym tangym            0 May 24 23:12 pse2
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Public
drwxrwxr-x  9 tangym tangym         4096 May 14 08:18 pycharm-community-2016.1.3
-rwxrw-rw-  1 tangym tangym    207707566 May 14 08:09 pycharm-community-2016.1.3.tar.gz
drwxrwxr-x  3 tangym tangym         4096 May 14 08:25 PycharmProjects
drwxrwxr-x  6 tangym tangym         4096 May 14 08:55 redis-2.8.12
-rw-rw-r--  1 tangym tangym      1215331 Jun 23  2014 redis-2.8.12.tar.gz
drwxrwxr-x 10 tangym tangym         4096 May 14 08:54 redis-py-master
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Templates
drwxrwxr-x  3 tangym tangym         4096 May 24 23:11 test1
drwxrwxr-x  3 tangym tangym         4096 May 24 22:38 test100
drwxrwxr-x  2 tangym tangym         4096 May 24 22:36 test3
drwxrwxr-x  2 tangym tangym         4096 May 17 21:52 TestFolder
drwxrwxr-x  2 tangym tangym         4096 May 29  2015 Ubuntu One
-rw-rw-r--  1 tangym tangym            0 May 17 21:49 Untitled Document
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Videos
drwxrwx---  2 lewis  workgroup      4096 May 24 22:25 work
tangym@ubuntu:~$ sudo chown lewis mvhello
[sudo] password for tangym: 
tangym@ubuntu:~$ ls -l
total 204136
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Desktop
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Documents
drwxr-xr-x  3 tangym tangym         4096 May 14 08:53 Downloads
-rw-r--r--  1 tangym tangym         8445 May 29  2015 examples.desktop
-rw-rw-r--  1 tangym tangym        10240 Jan 20  2011 ez_setup.py
drwxrwxr-x  2 tangym tangym         4096 May 24 23:37 mhydir
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Music
drwxrwxr-x  2 lewis  tangym         4096 May 24 23:49 mvhello
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Pictures
-rw-rw-r--  1 tangym tangym            0 May 24 22:42 pse
-rw-rw-r--  1 tangym tangym            0 May 24 23:12 pse2
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Public
drwxrwxr-x  9 tangym tangym         4096 May 14 08:18 pycharm-community-2016.1.3
-rwxrw-rw-  1 tangym tangym    207707566 May 14 08:09 pycharm-community-2016.1.3.tar.gz
drwxrwxr-x  3 tangym tangym         4096 May 14 08:25 PycharmProjects
drwxrwxr-x  6 tangym tangym         4096 May 14 08:55 redis-2.8.12
-rw-rw-r--  1 tangym tangym      1215331 Jun 23  2014 redis-2.8.12.tar.gz
drwxrwxr-x 10 tangym tangym         4096 May 14 08:54 redis-py-master
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Templates
drwxrwxr-x  3 tangym tangym         4096 May 24 23:11 test1
drwxrwxr-x  3 tangym tangym         4096 May 24 22:38 test100
drwxrwxr-x  2 tangym tangym         4096 May 24 22:36 test3
drwxrwxr-x  2 tangym tangym         4096 May 17 21:52 TestFolder
drwxrwxr-x  2 tangym tangym         4096 May 29  2015 Ubuntu One
-rw-rw-r--  1 tangym tangym            0 May 17 21:49 Untitled Document
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Videos
drwxrwx---  2 lewis  workgroup      4096 May 24 22:25 work
tangym@ubuntu:~$ whatis chgrp
chgrp (1)            - change group ownership
tangym@ubuntu:~$ sudo chgrp workgroup mvhello
tangym@ubuntu:~$ ls -l
total 204136
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Desktop
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Documents
drwxr-xr-x  3 tangym tangym         4096 May 14 08:53 Downloads
-rw-r--r--  1 tangym tangym         8445 May 29  2015 examples.desktop
-rw-rw-r--  1 tangym tangym        10240 Jan 20  2011 ez_setup.py
drwxrwxr-x  2 tangym tangym         4096 May 24 23:37 mhydir
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Music
drwxrwxr-x  2 lewis  workgroup      4096 May 24 23:49 mvhello
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Pictures
-rw-rw-r--  1 tangym tangym            0 May 24 22:42 pse
-rw-rw-r--  1 tangym tangym            0 May 24 23:12 pse2
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Public
drwxrwxr-x  9 tangym tangym         4096 May 14 08:18 pycharm-community-2016.1.3
-rwxrw-rw-  1 tangym tangym    207707566 May 14 08:09 pycharm-community-2016.1.3.tar.gz
drwxrwxr-x  3 tangym tangym         4096 May 14 08:25 PycharmProjects
drwxrwxr-x  6 tangym tangym         4096 May 14 08:55 redis-2.8.12
-rw-rw-r--  1 tangym tangym      1215331 Jun 23  2014 redis-2.8.12.tar.gz
drwxrwxr-x 10 tangym tangym         4096 May 14 08:54 redis-py-master
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Templates
drwxrwxr-x  3 tangym tangym         4096 May 24 23:11 test1
drwxrwxr-x  3 tangym tangym         4096 May 24 22:38 test100
drwxrwxr-x  2 tangym tangym         4096 May 24 22:36 test3
drwxrwxr-x  2 tangym tangym         4096 May 17 21:52 TestFolder
drwxrwxr-x  2 tangym tangym         4096 May 29  2015 Ubuntu One
-rw-rw-r--  1 tangym tangym            0 May 17 21:49 Untitled Document
drwxr-xr-x  2 tangym tangym         4096 May 29  2015 Videos
drwxrwx---  2 lewis  workgroup      4096 May 24 22:25 work


[Example-------Create Users and share group-----]
---Create workgroup----
tangym@ubuntu:~$ sudo groupadd workgroup
[sudo] password for tangym:

---Create four users and password----
tangym@ubuntu:~$ sudo useradd -G workgroup lucy
tangym@ubuntu:~$ sudo passwd lucy 
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

tangym@ubuntu:~$ sudo useradd -G workgroup lewis
tangym@ubuntu:~$ sudo passwd lewis
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

tangym@ubuntu:~$ sudo useradd -G workgroup mike
tangym@ubuntu:~$ sudo passwd mike
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

tangym@ubuntu:~$ sudo useradd -G workgroup peter
tangym@ubuntu:~$ sudo passwd peter
Enter new UNIX password: 
Retype new UNIX password:

-----Create direcories
tangym@ubuntu:~$ cd /home
tangym@ubuntu:/home$ sudo mkdir work -- Create direcory
tangym@ubuntu:/home$ sudo chgrp workgroup work -- update a directory belonged group.
tangym@ubuntu:/home$ sudo chmod g+rwx work -- g+  rws: read,write,execute
tangym@ubuntu:/home$ sudo chmod o-rwx work -- o: other, remove other group's permission.
tangym@ubuntu:/home$ sudo chown lewis work -- set the group lead to lewis.











本文转自 yuanzhitang 51CTO博客,原文链接:http://blog.51cto.com/yuanzhitang/1783023,如需转载请自行联系原作者
相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
目录
相关文章
|
2月前
|
监控 Linux 网络安全
Linux命令大全:从入门到精通
日常使用的linux命令整理
622 13
|
2月前
|
存储 数据管理 Linux
区分Linux中.tar文件与.tar.gz文件的不同。
总之,".tar"文件提供了一种方便的文件整理方式,其归档但不压缩的特点适用于快速打包和解压,而".tar.gz"文件通过额外的压缩步骤,尽管处理时间更长,但可以减小文件尺寸,更适合于需要节约存储空间或进行文件传输的场景。用户在选择时应根据具体需求,考虑两种格式各自的优劣。
327 13
|
3月前
|
Linux 网络安全 数据安全/隐私保护
使用Linux系统的mount命令挂载远程服务器的文件夹。
如此一来,你就完成了一次从你的Linux发车站到远程服务器文件夹的有趣旅行。在这个技术之旅中,你既探索了新地方,也学到了如何桥接不同系统之间的距离。
442 21
|
3月前
|
JSON 自然语言处理 Linux
linux命令—tree
tree是一款强大的Linux命令行工具,用于以树状结构递归展示目录和文件,直观呈现层级关系。支持多种功能,如过滤、排序、权限显示及格式化输出等。安装方法因系统而异常用场景包括:基础用法(显示当前或指定目录结构)、核心参数应用(如层级控制-L、隐藏文件显示-a、完整路径输出-f)以及进阶操作(如磁盘空间分析--du、结合grep过滤内容、生成JSON格式列表-J等)。此外,还可生成网站目录结构图并导出为HTML文件。注意事项:使用Tab键补全路径避免错误;超大目录建议限制遍历层数;脚本中推荐禁用统计信息以优化性能。更多详情可查阅手册mantree。
linux命令—tree
|
3月前
|
监控 Linux
Linux系统中使用df命令详解磁盘使用情况。
`df`命令是Linux系统管理员和用户监控和管理磁盘空间使用的重要工具。掌握它的基本使用方法和选项可以帮助在必要时分析和解决空间相关问题。简洁但功能丰富,`df`命令确保了用户可以快速有效地识别和管理文件系统的空间使用情况。
215 13
|
1月前
|
监控 Linux Shell
linux命令
常用 Linux 命令汇总
|
3月前
|
Linux
Linux命令拓展:为cp和mv添加进度显示
好了,就这样,让你的Linux复制体验充满乐趣吧!记住,每一个冷冰冰的命令背后,都有方法让它变得热情起来。
241 8
|
3月前
|
安全 Linux
Linux赋予文件000权限的恢复技巧
以上这些步骤就像是打开一扇锁住的门,步骤看似简单,但是背后却有着严格的逻辑和规则。切记,在任何时候,变更文件权限都要考虑安全性,不要无谓地放宽权限,那样可能
120 16
|
2月前
|
Linux C++
每天一个linux命令(8):cp 命令
cp 命令是 Linux 中用于复制文件或目录的命令。它的名字来源于英文单词 copy。这个命令非常常用,特别是在需要备份文件或创建文件副本时。
76 0
|
3月前
|
安全 Linux 定位技术
Linux环境下必备的基础命令概览
以上就是Linux系统中的基本命令和工具,掌握它们就能帮你在Linux世界里游刃有余。这其实就像是学习驾驭一辆新车,熟悉了仪表盘,调整好了座椅,之后的旅程就只需要享受风驰电掣的乐趣了。
90 4