linux 文件及目录

网友投稿 622 2022-08-27

linux 文件及目录

linux 文件及目录

bin文件夹存放各种命令的文件

bash是shell命令的主程序.

home存放用户文件夹

boot是存放系统启动的相关文件

dev存放各种设备文件  #fd软盘 disk硬盘等

lib存放各种库文件

media存放可移动介质的安装点

proc目录存储进程信息

tmp存放临时文件

sbin存放系统操作文件

我们设一个用户组来练习共享文件操作。

1. 创建用户组并设置用户

2. 文件的创建,移动,删除,复制等操作

3. 重定向操作

链接文件

5. 简单的管道命令

#1#--------------------------------------------------------------------------------------------------------edemon@linux:~$ sudo groupadd myteam# 增加用户及设置密码edemon@linux:~$ sudo useradd -G myteam y2edemon@linux:~$ sudo passwd y2Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully#创建一个myteam的文件夹在/home目录,并把此文件夹设置所属myteam用户组edemon@linux:/home$ sudo mkdir myteamedemon@linux:/home$ sudo chgrp myteam myteam#chmod分配权限 g+ 将权限赋予用户组myteamedemon@linux:/home$ sudo chmod g+rwx myteam#chmod撤销其他用户对myteam文件夹的权限edemon@linux:/home$ sudo chmod o-rwx myteam#确定用户组的组长是y1edemon@linux:/home$ sudo sudo chown y1 myteam#切换用户edemon@linux:~$ su y1Password: #--------------------------------------------------------------------------------------------------------#2#--------------------------------------------------------------------------------------------------------y1@linux:/home/edemon$ cd /homey1@linux:/home$ cd /home/myteam#创建子文件夹y1@linux:/home/myteam$ mkdir t1 t2y1@linux:/home/myteam$ mkdir t1/doc#-p 创建不存在的多级子目录y1@linux:/home/myteam$ mkdir -p t3/doc1 doc2y1@linux:/home/myteam$ lsdoc2 t1 t2 t3#查看文件的属性y1@linux:/home/myteam$ ls -l t1total 4drwxrwxr-x 2 y1 y1 4096 Feb 7 09:14 doc#我们将文件doc2移动到t3中y1@linux:/home/myteam$ mv doc2 t3y1@linux:/home/myteam$ cd t3y1@linux:/home/myteam/t3$ ls doc1 doc2# 存在同名文件再移动会怎样?# 用nano在两个同名文件中写好内容y1@linux:/home/myteam/t3$ touch cpy1@linux:/home/myteam/t3$ nano cp GNU nano 2.2.6 File:cp this is t3/cp document.y1@linux:/home/myteam/t3$ cd ..y1@linux:/home/myteam$ touch cpy1@linux:/home/myteam$ nano cp GNU nano 2.2.6 File: cp this is /myteam/cp.y1@linux:/home/myteam$ mv cp t3/y1@linux:/home/myteam$ cd t3y1@linux:/home/myteam/t3$ nano cp GNU nano 2.2.6 File: cp this is /myteam/cp.#这说明它直接覆盖了原文件#使用 mv -i提高文件移动的安全性y1@linux:/home/myteam/t3$ cd ..y1@linux:/home/myteam$ touch mvy1@linux:/home/myteam$ echo 'myteam'>cpy1@linux:/home/myteam$ mv -i cp t3mv: overwrite ‘t3/cp’? n#输入n,取消移动#带b参数的移动y1@linux:/home/myteam$ lscp mv t1 t2 t3y1@linux:/home/myteam$ mv -b cp t3y1@linux:/home/myteam$ cd /t3bash: cd: /t3: No such file or directoryy1@linux:/home/myteam$ cd t3y1@linux:/home/myteam/t3$ lscp cp~ doc1 doc2y1@linux:/home/myteam/t3$ #递归复制y1@linux:/home/myteam$ cd t1y1@linux:/home/myteam/t1$ lsdocy1@linux:/home/myteam/t1$ touch helloy1@linux:/home/myteam/t1$ cd ..y1@linux:/home/myteam$ cp -r t1 t3 # 关键句y1@linux:/home/myteam$ cd t3y1@linux:/home/myteam/t3$ lscp cp~ doc1 doc2 t1y1@linux:/home/myteam/t3$ cd t1y1@linux:/home/myteam/t3/t1$ lsdoc hello#带提示的删除操作y1@linux:/home/myteam$ touch helloy1@linux:/home/myteam$ rm -i hellorm: remove regular empty file ‘hello’? #试试其他同组的其他用户的使用情况:edemon@linux:~$ su y2Password: y2@linux:/home/edemon$ cd /home/myteamy2@linux:/home/myteam$ lshello t1 t2 t3y2@linux:/home/myteam$ cd t3y2@linux:/home/myteam/t3$ lscp cp~ doc1 doc2 t1y2@linux:/home/myteam/t3$ cat cpmyteam#但是对文件的写操作确是不行的y2@linux:/home/myteam/t3$ echo '\n these are contents for y2'>cpbash: cp: Permission denied#这和文件属性有关的y3@linux:/home/myteam/t3$ ls -ltotal 20-rw-rw-r-- 1 y1 y1 7 Feb 7 09:39 cp-rw-rw-r-- 1 y1 y1 14 Feb 7 09:36 cp~drwxrwxr-x 2 y1 y1 4096 Feb 7 09:17 doc1drwxrwxr-x 2 y1 y1 4096 Feb 7 09:17 doc2drwxrwxr-x 3 y1 y1 4096 Feb 7 09:56 t1y2@linux:/home/myteam/t3$ su y3Password: y3@linux:/home/myteam/t3$ lscp cp~ doc1 doc2 t1y3@linux:/home/myteam/t3$ cat cpmyteamy3@linux:/home/myteam/t3$ #给同组其他用户赋予w权限, 查看效果y1@linux:/home/myteam/t3$ chmod o+w cpy1@linux:/home/myteam/t3$ su y3Password: y3@linux:/home/myteam/t3$ cat cpmyteamy3@linux:/home/myteam/t3$ echo 'y3'>cpy3@linux:/home/myteam/t3$ cat cpy3#关于用户所属者:u 同组其他用户o 所有用户a #其他用户y3@linux:/home/myteam/t3$ su edemonPassword: edemon@linux:/home/myteam/t3$ sudo useradd y4[sudo] password for edemon: edemon@linux:/home/myteam/t3$ sudo passwd y4Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully#新建立的用户目录默认为 /home/***edemon@linux:/home/myteam/t3$ cdedemon@linux:~$ pwd/home/edemon#其他用户是不能进入myteam的,因为没有执行权限 xedemon@linux:/home$ su y4Password: y4@linux:/home$ cd /home/myteambash: cd: /home/myteam: Permission deniedy4@linux:/home$ ls -ltotal 8drwxr-xr-x 22 edemon edemon 4096 Feb 7 17:36 edemondrwxrwx--- 5 y1 myteam 4096 Feb 7 10:03 myteam#给所有用户赋予X权限y4@linux:/home$ su y1Password: y1@linux:/home$ chmod a+x myteamy1@linux:/home$ su y4Password: y4@linux:/home$ cd myteamy4@linux:/home/myteam$ y1@linux:/home$ ls -ltotal 8drwxr-xr-x 22 edemon edemon 4096 Feb 7 17:36 edemondrwxrwx--x 5 y1 myteam 4096 Feb 7 10:03 myteam#快速更改权限:#同组所有用户有读r和执行x的权限y1@linux:/home/myteam/t3$ chmod ug=rx,o=r cpy1@linux:/home/myteam/t3$ ls -ltotal 20-r-xr-xr-- 1 y1 y1 3 Feb 7 18:48 cp-rw-rw-r-- 1 y1 y1 14 Feb 7 09:36 cp~drwxrwxr-x 2 y1 y1 4096 Feb 7 09:17 doc1drwxrwxr-x 2 y1 y1 4096 Feb 7 09:17 doc2drwxrwxr-x 3 y1 y1 4096 Feb 7 09:56 t1#仅有文件创建者有rwx权限,其他用户r权限y1@linux:/home/myteam/t3$ chmod u=rwxx,o=r cpy1@linux:/home/myteam/t3$ ls -ltotal 20-rwxr--r-- 1 y1 y1 3 Feb 7 18:48 cp-rw-rw-r-- 1 y1 y1 14 Feb 7 09:36 cp~drwxrwxr-x 2 y1 y1 4096 Feb 7 09:17 doc1drwxrwxr-x 2 y1 y1 4096 Feb 7 09:17 doc2drwxrwxr-x 3 y1 y1 4096 Feb 7 09:56 t1#--------------------------------------------------------------------------------------------------------#3#--------------------------------------------------------------------------------------------------------#重定向:y1@linux:/home/myteam/t3$ echo "ubuntu linux.">cpy1@linux:/home/myteam/t3$ cat cpubuntu linux.#输入和输出的重定向edemon@linux:~$ cat <3> this > is> <<> ans >> test> !> EOFedemon@linux:~$ cat 3this is<test!edemon@linux:~$ #输入重定向edemon@linux:~$ cat << EOF> hello world> EOFhello world#--------------------------------------------------------------------------------------------------------# 4#--------------------------------------------------------------------------------------------------------/*三种重要的文件:普通文件目录文件 链接文件:ln -s 文件名 参数S表示这是创建符号链接文件*/edemon@linux:~$ ln -s 1.1 link1.1edemon@linux:~$ ls1.1 Desktop link1.1 Pictures -1.2 Documents Music Public 文档2 Downloads my nano file~ Templates 桌面3 examples.desktop myNanoFile Videos#通过了链接文件我们可以访问它所指的文件#关于链接文件: 用于文件共享,隐私文件路径问题的解决#链接文件和源文件建立了一个链接,其中一个文件改变会改变另一个文件.edemon@linux:~$ cat link1.1this is 1.1 fileedemon@linux:~$ nano link1.1edemon@linux:~$ cat link1.1this is 1.1 filelink1.1edemon@linux:~$ cat 1.1this is 1.1 filelink1.1#删除此链接文件对源文件没有影响edemon@linux:~$ rm link1.1edemon@linux:~$ cat 1.1this is 1.1 file#创建指向目录的链接文件edemon@linux:~$ ln -s Desktop linktopedemon@linux:~$ ls1.1 Desktop linktop Pictures -1.2 Documents Music Public 文档2 Downloads my nano file~ Templates 桌面3 examples.desktop myNanoFile Videosedemon@linux:~$ cat linktopcat: linktop: Is a directory#硬链接文件edemon@linux:~$ ln 3 link3edemon@linux:~$ ls1.1 Desktop link3 myNanoFile Videos1.2 Documents linktop Pictures -2 Downloads Music Public 文档3 examples.desktop my nano file~ Templates 桌面#--------------------------------------------------------------------------------------------------------# 5#--------------------------------------------------------------------------------------------------------#管道命令#过滤显示edemon@linux:~$ ls | grep 11.11.2link1.1# >>追加文件内容edemon@linux:~$ echo '\n append 1.1'>>1.1edemon@linux:~$ cat 1.1this is 1.1 filelink1.1\n append 1.1

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:选择Go语言的12个理由(Go语言怎么样)
下一篇:nyist 297 GoroSort
相关文章

 发表评论

暂时没有评论,来抢沙发吧~