Linux学习(四)档案与目录管理
1. 目录与路径
1.1 相对路径与绝对路径
1.2 目录的相关操作: cd, pwd, mkdir, rmdir
1.3 关于执行文件路径的变量: $PATH
2. 档案与目录管理
2.1 档案与目录的检视: ls
2.2 复制、移动与删除: cp, rm, mv
2.3 取得路径的文件名称与目录名称
3. 档案内容查阅:
3.1 直接检视档案内容: cat, tac, nl
3.2 可翻页检视: more, less
3.3 资料撷取: head, tail
3.4 非纯文字文件: od
3.5 修改档案时间与建置新档: touch
4. 档案与目录的预设权限与隐藏权限
4.1 档案预设权限:umask
4.2 档案隐藏属性: chattr, lsattr
4.4 档案特殊权限:SUID/SGID/Sticky Bit
4.3 档案类型:file
5. 档案的搜寻:which, whereis, locate, find
. 代表此层目录
.. 代表上一层目录
- 代表前一个工作目录
~ 代表『目前使用者身份』所在的家目录
~account 代表 account 这个使用者的家目录
常见的处理目录的指令:
• cd:变换目录
• pwd:显示目前的目录
• mkdir:建立一个新的目录
• rmdir:删除一个空的目录
•cd (变换目录)
pwd
[root@linux ~]# pwd [-P]
参数:
-P :显示出确实的路径,而非使用连结 (link) 路径。
范例:
[root@linux ~]# pwd
/root <== 显示出目录啦~
[root@linux ~]# cd /var/mail
[root@linux mail]# pwd
/var/mail
[root@linux mail]# pwd -P
/var/spool/mail <== 怎么回事?有没有加 -P 差很多~
[root@linux mail]# ls -l /var/mail
lrwxrwxrwx 1 root root 10 Jun 25 08:25 /var/mail -> spool/mail
# 看到这里应该知道为啥了吧?因为 /var/mail 是连结档,连结到 /var/spool/mail
# 所以,加上 pwd -P 的参数后,会不以连结文件的数据显示,而是显示正确的完整路径啊!
mkdir
[root@linux ~]# mkdir [-mp] 目录名称
参数:
-m :设定档案的权限喔!直接设定,不需要看预设权限 (umask) 的脸色~
-p :帮助你直接将所需要的目录递归建立起来!
范例:
[root@linux ~]# cd /tmp
[root@linux tmp]# mkdir test <== 建立一名为 test 的新目录
[root@linux tmp]# mkdir test1/test2/test3/test4
mkdir: cannot create directory `test1/test2/test3/test4':
No such file or directory <== 没办法直接建立此目录啊!
[root@linux tmp]# mkdir -p test1/test2/test3/test4
# 加了这个 -p 的参数,可以自行帮您建立多层目录!
[root@linux tmp]# mkdir -m 711 test2
[root@linux tmp]# ls -l
drwxr-xr-x 3 root root 4096 Jul 18 12:50 test
drwxr-xr-x 3 root root 4096 Jul 18 12:53 test1
drwx--x--x 2 root root 4096 Jul 18 12:54 test2
# 仔细看上面的权限部分,如果没有加上 -m 来强制设定属性,系统会使用预设属性。
# 那么您的预设属性为何?这要透过底下介绍的 umask才能了解喔! ^_^
rmdir (删除『空』的目录)
[root@linux ~]# rmdir [-p] 目录名称
参数:
-p :连同上层『空的』目录也一起删除
范例:
[root@linux tmp]# ls -l
drwxr-xr-x 3 root root 4096 Jul 18 12:50 test
drwxr-xr-x 3 root root 4096 Jul 18 12:53 test1
drwx--x--x 2 root root 4096 Jul 18 12:54 test2
[root@linux tmp]# rmdir test
[root@linux tmp]# rmdir test1
rmdir: `test1': Directory not empty
[root@linux tmp]# rmdir -p test1/test2/test3/test4
[root@linux tmp]# ls -l
drwx--x--x 2 root root 4096 Jul 18 12:54 test2
# 瞧!利用 -p 这个参数,立刻就可以将 test1/test2/test3/test4 一次删除~
# 不过要注意的是,这个 rmdir 仅能『删除空的目录』
如果要将所有目录下的东西都杀掉呢?! 这个时候就必须使用 rm -rf test
关于执行文件路径的变量: $PATH
[root@linux ~]# echo $PATH
/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin
将 /root 的路径加入 PATH 当中
[root@linux ~]# PATH="$PATH":/root
使用完整文件名来下达指令, 亦即直接使用相对或绝对路径来执行,例如:
[root@linux ~]# /root/ls
[root@linux ~]# ./ls
档案与目录的检视: ls
[root@linux ~]# ls [-aAdfFhilRS] 目录名称
[root@linux ~]# ls [--color={none,auto,always}] 目录名称
[root@linux ~]# ls [--full-time] 目录名称
参数:
-a :全部的档案,连同隐藏档( 开头为 . 的档案) 一起列出来~
-A :全部的档案,连同隐藏档,但不包括 . 与 .. 这两个目录,一起列出来~
-d :仅列出目录本身,而不是列出目录内的档案数据
-f :直接列出结果,而不进行排序 (ls 预设会以档名排序!)
-F :根据档案、目录等信息,给予附加数据结构,例如:
*:代表可执行档; /:代表目录; =:代表 socket 档案; |:代表 FIFO 档案;
-h :将档案容量以人类较易读的方式(例如 GB, KB 等等)列出来;
-i :列出 inode 位置,而非列出档案属性;
-l :长数据串行出,包含档案的属性等等数据;
-n :列出 UID 与 GID 而非使用者与群组的名称 (UID 与 GID 会在账号管理提到!)
-r :将排序结果反向输出,例如:原本档名由小到大,反向则为由大到小;
-R :连同子目录内容一起列出来;
-S :以档案容量大小排序!
-t :依时间排序
--color=never :不要依据档案特性给予颜色显示;
--color=always :显示颜色
--color=auto :让系统自行依据设定来判断是否给予颜色
--full-time :以完整时间模式 (包含年、月、日、时、分) 输出
--time={atime,ctime} :输出 access 时间或 改变权限属性时间 (ctime)
而非内容变更时间 (modification time)
范例一:将家目录下的所有档案列出来(含属性与隐藏文件)
[root@linux ~]# ls -al ~
total 252
drwxr-x--- 9 root root 4096 Jul 16 23:40 .
drwxr-xr-x 24 root root 4096 Jul 16 23:45 ..
-rw------- 1 root root 1491 Jun 25 08:53 anaconda-ks.cfg
-rw------- 1 root root 12543 Jul 18 01:23 .bash_history
-rw-r--r-- 1 root root 24 Dec 4 2004 .bash_logout
-rw-r--r-- 1 root root 191 Dec 4 2004 .bash_profile
-rw-r--r-- 1 root root 395 Jul 4 11:45 .bashrc
-rw-r--r-- 1 root root 68495 Jun 25 08:53 install.log
-rw-r--r-- 1 root root 5976 Jun 25 08:53 install.log.syslog
drwx------ 2 root root 4096 Jul 4 16:03 .ssh
-rw------- 1 root root 12613 Jul 16 23:40 .viminfo
# 这个时候您会看到以 . 为开头的几个档案,以及目录文件 ./../.ssh 等等,
# 不过,目录文件都是以深蓝色显示,有点不容易看清楚就是了。
范例二:承上题,不显示颜色,但在文件名末显示出该文件名代表的类型(type)
[root@linux ~]# ls -alF --color=never ~
total 252
drwxr-x--- 9 root root 4096 Jul 16 23:40 ./
drwxr-xr-x 24 root root 4096 Jul 16 23:45 ../
-rw------- 1 root root 1491 Jun 25 08:53 anaconda-ks.cfg
-rw------- 1 root root 12543 Jul 18 01:23 .bash_history
-rw-r--r-- 1 root root 24 Dec 4 2004 .bash_logout
-rw-r--r-- 1 root root 191 Dec 4 2004 .bash_profile
-rw-r--r-- 1 root root 395 Jul 4 11:45 .bashrc
-rw-r--r-- 1 root root 68495 Jun 25 08:53 install.log
-rw-r--r-- 1 root root 5976 Jun 25 08:53 install.log.syslog
drwx------ 2 root root 4096 Jul 4 16:03 .ssh/
-rw------- 1 root root 12613 Jul 16 23:40 .viminfo
# 注意看到显示结果的第一行,嘿嘿~知道为何我们会下达类似 ./command
# 之类的指令了吧?因为 ./ 代表的是『目前目录下』的意思啊!至于什么是 FIFO/Socket ?
# 请参考前一章节的介绍啊!
范例三:完整的呈现档案的修改时间 *(modification time)
[root@linux ~]# ls -al --full-time ~
total 252
drwxr-x--- 9 root root 4096 2005-07-16 23:40:13.000000000 +0800 .
drwxr-xr-x 24 root root 4096 2005-07-16 23:45:05.000000000 +0800 ..
-rw------- 1 root root 1491 2005-06-25 08:53:37.000000000 +0800 anaconda-ks.cfg
-rw------- 1 root root 12543 2005-07-18 01:23:33.000000000 +0800 .bash_history
-rw-r--r-- 1 root root 24 2004-12-04 05:44:13.000000000 +0800 .bash_logout
-rw-r--r-- 1 root root 191 2004-12-04 05:44:13.000000000 +0800 .bash_profile
-rw-r--r-- 1 root root 395 2005-07-04 11:45:16.000000000 +0800 .bashrc
-rw-r--r-- 1 root root 68495 2005-06-25 08:53:34.000000000 +0800 install.log
-rw-r--r-- 1 root root 5976 2005-06-25 08:53:28.000000000 +0800 install.log.syslog
drwx------ 2 root root 4096 2005-07-04 16:03:24.000000000 +0800 .ssh
-rw------- 1 root root 12613 2005-07-16 23:40:13.000000000 +0800 .viminfo
# 请仔细看,上面的『时间』字段变了喔!变成较为完整的格式。
# 一般来说, ls -al 仅列出目前短格式的时间,有时不会列出年份,
# 藉由 --full-time 可以查阅到比较正确的完整时间格式啊!
复制、移动与删除: cp, rm, mv
Linux学习(四)档案与目录管理的更多相关文章
- linux学习笔记----文件与目录管理
一.目录处理命令 cd:切换目录 pwd:显示当前目录 mkdir:新建一个新的目录 rmdir:删除一个空的目录 1)pwd:显示当前目录 pwd [-P] P:显示出当前的路径,而非使用连接(li ...
- Linux 档案与目录管理
『 cd /etc 』这个情况,这也就是所谓的『绝对路径』,他是从根目录连续写上来的一个情况,所以不论你在哪一个路径现执行这一个指令,都会将你移动到该路径下.那如果我是使用『 cd etc 』呢?那表 ...
- 鸟哥的linux私房菜 - 第5/6/7/9章(在线求助 man page、Linux档案权限与目录配置、Linux档案与目录管理、压缩与打包)
第五章.在线求助 man page X window与文本模式的切换 Ctrl+Alt+F1~F6:文字接口登入tty1~tty6终端机: Ctrl+Alt+F7:图形接口桌面. 注销当前用户:exi ...
- linux:档案与目录管理
几个常见的目录处理命令: cd(change directory):变更目录 pwd(print working directory):显示当前目录[目录为连结档,则只显示连结档的路径]([-P]不以 ...
- Linux档案与目录管理
Linux档案与目录管理1. 目录与路径1.1 相对路径与绝对路径1.2 目录的相关操作: cd, pwd, mkdir, rmdir cd [相对路径或绝对路径]cd ~ [用户]: 切换家目录cd ...
- linux杂记(七)linux档案与目录管理指令
1.目录的相关操作:cd,pwd,mkdir,rmdir 路径(PATH): 绝对路径:路径的写法[一定由根目录/写起],例如/usr/share/doc这个目录 相对路径:路径的写法[不是由/写起] ...
- [转帖]Linux学习笔记之rpm包管理功能全解
Linux学习笔记之rpm包管理功能全解 https://www.cnblogs.com/JetpropelledSnake/p/11177277.html rpm 的管理命令 之前学习过 yum 的 ...
- linux档案和目录管理(后续)
资料来自鸟哥的linux私房菜 四:档案和目录的预设权限和隐藏权限 umask:预设权限,相比与chomd的4,2,1权限,档案满分为666,目录满分为777,umask可以预设消除部分权限,比如一个 ...
- 01 Linux档案与目录管理
1. 目录与路径 1.1绝对路径和相对路径 绝对路径:一定有根目录/写起,例如:/usr/share/doc 相对路径:不是由根目录/写起,例如:由/usr/sha ...
随机推荐
- SpringAOP来监控service层中每个方法的执行时间
使用AOP来说,太方便了,并且特别适合这类场景. 代码如下,这里是将要统计的信息写到log文件中,也可以设计成写入表中. package com.ecsoft.interceptor; import ...
- HDU 5289 Assignment(多校2015 RMQ 单调(双端)队列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5289 Problem Description Tom owns a company and he is ...
- json数据 提示框flash.now[:notice] flash.now[:alert]
实现json.做出提示框 1.在controller中使用flash.now[:alert] = "str"方法来做print def topodata #@vnic = Vnic ...
- python + opencv: 解决不能读取视频的问题
博主一开始使用python2.7和Opencv2.4.10来获取摄像头图像,程序如下: cap = cv2.VideoCapture(0) ret, frame = cap.read() 使用这个程序 ...
- Convolution Network及其变种(反卷积、扩展卷积、因果卷积、图卷积)
今天,主要和大家分享一下最近研究的卷积网络和它的一些变种. 首先,介绍一下基础的卷积网络. 通过PPT上的这个经典的动态图片可以很好的理解卷积的过程.图中蓝色的大矩阵是我们的输入,黄色的小矩阵是卷积核 ...
- Unity3D深入浅出 -创造 物理材质(Physics Materials)
在Unity3d中已经配置好了5种常用的物理材质,Bouncy.Ice.Metal.Rubber.Wood,在菜单中依次选择Assets - Import Package - Physics Mate ...
- Eclipse最经常使用快捷键总结
1. ctrl+shift+r:打开资源 这可能是全部快捷键组合中最省时间的了. 这组快捷键能够让你打开你的工作区中不论什么一个文件,而你仅仅须要按下文件名称或mask名中的前几个字母,比方appl ...
- QTableView修改数据后弹出是否保存的提示框。
自定义CustomDelegate继承自QStyledItemDelegate,重写setModelData(self, editor, model, index)方法 def setModelDat ...
- 转载:【原译】Erlang常见注意事项(Efficiency Guide)
转自:http://www.cnblogs.com/futuredo/archive/2012/10/17/2726416.html Common Caveats(常见注意事项) Erlang/OTP ...
- Java回调方法的设计思路
package com.test; /** * 回调方法的设计技巧,例如hibernate的getHibernateTemplate().execute(Handler h)方法 */ public ...