Linux命令- 文件与用户权限

简介:

文件权限讲解:

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,如需转载请自行联系原作者
目录
相关文章
|
6月前
|
Linux 应用服务中间件 Shell
二、Linux文本处理与文件操作核心命令
熟悉了Linux的基本“行走”后,就该拿起真正的“工具”干活了。用grep这个“放大镜”在文件里搜索内容,用find这个“探测器”在系统中寻找文件,再用tar把东西打包带走。最关键的是要学会使用管道符|,它像一条流水线,能把这些命令串联起来,让简单工具组合出强大的功能,比如 ps -ef | grep 'nginx' 就能快速找出nginx进程。
728 1
二、Linux文本处理与文件操作核心命令
|
6月前
|
Linux
linux命令—stat
`stat` 是 Linux 系统中用于查看文件或文件系统详细状态信息的命令。相比 `ls -l`,它提供更全面的信息,包括文件大小、权限、所有者、时间戳(最后访问、修改、状态变更时间)、inode 号、设备信息等。其常用选项包括 `-f` 查看文件系统状态、`-t` 以简洁格式输出、`-L` 跟踪符号链接,以及 `-c` 或 `--format` 自定义输出格式。通过这些选项,用户可以灵活获取所需信息,适用于系统调试、权限检查、磁盘管理等场景。
431 137
|
6月前
|
安全 Ubuntu Unix
一、初识 Linux 与基本命令
玩转Linux命令行,就像探索一座新城市。首先要熟悉它的“地图”,也就是/根目录下/etc(放配置)、/home(住家)这些核心区域。然后掌握几个“生存口令”:用ls看周围,cd去别处,mkdir建新房,cp/mv搬东西,再用cat或tail看文件内容。最后,别忘了随时按Tab键,它能帮你自动补全命令和路径,是提高效率的第一神器。
1113 58
|
5月前
|
存储 安全 Linux
Linux卡在emergency mode怎么办?xfs_repair 命令轻松解决
Linux虚拟机遇紧急模式?别慌!多因磁盘挂载失败。本文教你通过日志定位问题,用`xfs_repair`等工具修复文件系统,三步快速恢复。掌握查日志、修磁盘、验重启,轻松应对紧急模式,保障系统稳定运行。
1018 2
|
6月前
|
缓存 监控 Linux
Linux内存问题排查命令详解
Linux服务器卡顿?可能是内存问题。掌握free、vmstat、sar三大命令,快速排查内存使用情况。free查看实时内存,vmstat诊断系统整体性能瓶颈,sar实现长期监控,三者结合,高效定位并解决内存问题。
551 0
Linux内存问题排查命令详解
|
6月前
|
Unix Linux 程序员
Linux文本搜索工具grep命令使用指南
以上就是对Linux环境下强大工具 `grep` 的基础到进阶功能介绍。它不仅能够执行简单文字查询任务还能够处理复杂文字处理任务,并且支持强大而灵活地正则表达规范来增加查询精度与效率。无论您是程序员、数据分析师还是系统管理员,在日常工作中熟练运用该命令都将极大提升您处理和分析数据效率。
521 16
|
7月前
|
Linux 网络安全 开发工具
技术栈:这50条最常用的 Linux 命令你一定要会!
建议多在终端中实践,遇到不懂的命令就用 man 或 --help 了解详情!
1160 0
|
7月前
|
安全 Linux Shell
Linux系统中sudo命令的高效运用技巧。
用户可以通过sudo -l来列出自己目前可执行的命令列表,这有助于用户了解自己的权限范围。
263 0
|
7月前
|
监控 Linux Shell
linux命令
常用 Linux 命令汇总
|
8月前
|
Linux C++
每天一个linux命令(8):cp 命令
cp 命令是 Linux 中用于复制文件或目录的命令。它的名字来源于英文单词 copy。这个命令非常常用,特别是在需要备份文件或创建文件副本时。
520 0