[2] Manage File,Dir,User,Group

Root directory introduce:

dev : Device directory
etc : System software startup and config
home: User main directory
lib :C complier directory/libary
mnt : host plug/unplug device
proc: System directory, process infomation
root: Super user main directory
tmp : temp file

sudo是superuser do的简写,sudo是linux系统管理指令,是允许系统管理员让普通用户执行一些或者全部的root命令的一个工具,如halt,reboot,su等等。这样不仅减少了root用户的登陆 和管理时间,同样也提高了安全性。

apt是个很完整和先进的软件包管理程式,使用他能够让您,又简单,又准确的找到您要的的软件包, 并且安装或卸载都很简洁。 他还能够让您的任何软件都更新到最新状态,而且也能够用来对ubuntu进行升级。

Basic Command:

mkdir
[email protected]:~$ mkdir test2 test3  --Create two diretories
[email protected]:~$ mkdir test1/mydir  --Create a folder under test1

[email protected]:~$ mkdir test100/mydir
mkdir: cannot create directory `test100/mydir‘: No such file or directory
[email protected]:~$ mkdir -p test100/mydir -- Force create the two folders, if test100 doesn‘t exist

touch
[email protected]:~$ touch hello -- Create the hello file in current directory

echo
[email protected]:~/test1$ cat hellobackup
[email protected]:~/test1$ echo "hello" > hellobackup -- Write "hello" to the file
[email protected]:~/test1$ cat hellobackup
hello

mv
[email protected]:~$ mv hello test1 -- move hello to test1 folder
[email protected]:~/test1$ mv hello hellobackup -- rename a file.

cp
[email protected]:~$ cp pse2 test2 -- copy file pse2 to test2 folder

rm/rmdir
[email protected]:~$ rm hello -- remove hello file
[email protected]:~$ rmdir test2 -- remove test2 folder

[Input] redirect:
[email protected]:~$ cat <<EOF >hellobackup
> hello world!
> real func
> EOF
[email protected]:~$ cat hellobackup
hello world!
real func
[email protected]:~$

|------Example(Create,remove file)--------|
[email protected]:~$ cd mhydir
[email protected]:~/mhydir$ ls
[email protected]:~/mhydir$ touch test
[email protected]:~/mhydir$ ls
test
[email protected]:~/mhydir$ rm test
[email protected]:~/mhydir$ ls
[email protected]:~/mhydir$ touch test
[email protected]:~/mhydir$ rm -i test   --Will Confirm whether delete the file
rm: remove regular empty file `test‘? n
[email protected]:~/mhydir$ ls
test
[email protected]:~/mhydir$ rm -i test
rm: remove regular empty file `test‘? y
[email protected]:~/mhydir$ ls
[email protected]:~/mhydir$
|--------End-----------|

File permission:
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 -----|
[email protected]:~$ mkdir mvhello
[email protected]:~$ ls -l mvhello
total 0
[email protected]:~$ 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
[email protected]:~$ sudo chown lewis mvhello
[sudo] password for tangym:
[email protected]:~$ 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
[email protected]:~$ whatis chgrp
chgrp (1)            - change group ownership
[email protected]:~$ sudo chgrp workgroup mvhello
[email protected]:~$ 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----
[email protected]:~$ sudo groupadd workgroup
[sudo] password for tangym:

---Create four users and password----
[email protected]:~$ sudo useradd -G workgroup lucy
[email protected]:~$ sudo passwd lucy
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

[email protected]:~$ sudo useradd -G workgroup lewis
[email protected]:~$ sudo passwd lewis
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

[email protected]:~$ sudo useradd -G workgroup mike
[email protected]:~$ sudo passwd mike
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

[email protected]:~$ sudo useradd -G workgroup peter
[email protected]:~$ sudo passwd peter
Enter new UNIX password:
Retype new UNIX password:

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

时间: 2024-08-07 04:14:10

[2] Manage File,Dir,User,Group的相关文章

Global UNIX file system cylinder group cache

A global?cylinder?group?(CG) cache is stored in file server memory and shared by a plurality of file systems supported by the file server. The global CG cache comprises a number CG entries which are pre-allocated in memory. As different file systems

shell file/dir exist

https://www.cnblogs.com/37yan/p/6962563.html caution!!! if should be end with fi caution!!! there should be a space between [ and ! , also between 1 and ] if [ ! $# -eq 1 ];then #!/bin/bash # 判断传入的参数的个数是不是一个 if [ ! $# -eq 1 ];then echo param error! e

dir cmd、the DIR Command、windows

原因   :如何在windows下的cmd.exe中只列出文件名? solve : dir \a:-d \b Extend Reading : dir [drive:][path][filename] [/A[[:]attributes]] [/B][/C][/D][/L][/N] [/O[[:]sortorder]] [/P][/Q][/S] [/T[[:]timefield]] [/W][/X][/4] Part O: Default Display (每一列分别是modified date

ansible之user和group模块

ansible提供了user模块,这样的话在其他服务器上可以使用user模块创建用户了.. 用法 [[email protected] ~]# ansible-doc -s user less 436 ......................... - name: Manage user accounts   action: user       append                 # If `yes', will only add groups, not set them to 

ansible模块cron、copy、user、group

查询模块的参数: ansible-doc -s moduleName 如 cron 模块 [[email protected] ansible]# ansible-doc -s cron less 436 Copyright (C) 1984-2009 Mark Nudelman less comes with NO WARRANTY, to the extent permitted by law. For information about the terms of redistributio

SaltStack源码分析之file状态模块

file模块用于对普通文件,目录,特殊文件和链接文件进行各种操作 /usr/lib/python2.6/site-packages/salt/states/file.py def managed(name,             source=None,             source_hash='',             user=None,             group=None,             mode=None,             template=No

Linux File System Change Monitoring Technology、Notifier Technology

catalog 1. 为什么要监控文件系统 2: hotplug 3. udev 4. fanotify 5. inotify 6. code example 1. 为什么要监控文件系统 在日常工作中,人们往往需要知道在某些文件(夹)上都有那些变化,比如: 1. 通知配置文件的改变 2. 跟踪某些关键的系统文件的变化 3. 监控某个分区磁盘的整体使用情况 4. 系统崩溃时进行自动清理 5. 自动触发备份进程 6. 向服务器上传文件结束时发出通知 7. 杀软(anti-virus)需要对磁盘上的文

【Ruby】File 类和方法

阅读目录 类方法 实例方法 File 表示一个连接到普通文件的 stdio 对象.open 为普通文件返回该类的一个实例. 类方法 序号 方法 & 描述 1 File::atime( path)返回 path 的最后访问时间. 2 File::basename( path[, suffix])返回 path 末尾的文件名.如果指定了 suffix,则它会从文件名末尾被删除.例如:File.basename("/home/users/bin/ruby.exe") #=> &

Puppet file资源使用

1.文件管理介绍: 可管理的项目: 支持文件和目录 设置文件及目录的所有者及权限 恢复文件(包括文件的内容.权限及所有者) 清理目录以及子目录 2. 可使用参数: ensure :指定文件的状态,状态包括 abent(删除).present(创建),也可指定文件类型 file(文件).directory(目录).link(链接文件) backup :指定在文件内容替换之前进行备份操作,可以备份在本地,也可以集中备份 owner|user : 指定文件属主,可以是用户名或者UID group :指