[2] Manage File,Dir,User,Group

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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.



本文出自 “软件设计与开发” 博客,请务必保留此出处http://yuanzhitang.blog.51cto.com/2769219/1783023

以上是关于[2] Manage File,Dir,User,Group的主要内容,如果未能解决你的问题,请参考以下文章

ansbile

使用java系统属性user.dir读取配置文件

Django Manage File

django model操作

xtrabackup的简单用法及其原理

java 获取路径