2017-7-19-每日博客-关于Linux下的CentOS中文件夹基本操作命令.doc
CentOS中文件夹基本操作命令
文件(夹)查看类命令
ls--显示指定目录下内容
说明:ls 显示结果以不同的颜色来区分文件类别。蓝色代表目录,灰色代表普通文件,绿色代表可执行文件,红色代表压缩文件,浅蓝色代表链接文件。
-a---显示所有内容,包括隐藏文件
说明:在Linux系统中,以“.”开头的就是隐藏文件或隐藏目录。
-l---以长格式(内容更详细)显示文件或目录的详细信息。
说明:ls -l命令可以简写成ll,
输出的信息共分为7组:
文件类别和文件权限、链接数或子目录个数、文件所有者、文件所属组、文件大小(单位为字节B)、文件创建或修改时间、文件名。
文件类别:第一组前1位表示文件类别,“-”代表普通文件,“d”代表目录,“l”代表符号链接,“c”代表字符设备,“b”代表块设备
文件权限:第一组后9位表示文件权限,前3位为user、中间3位为group、后三位为other的权限
-d---显示目录本身的属性而不是目录中的内容。
|
1 2 3 4 5 |
[root@localhost ~]# ls -ld /home drwxr-xr-x. 4 root root 4096 9月 22 10:41 /home [root@localhost ~]# ls -d /home /home [root@localhost ~]# |
-h---以K、M、G等单位显示文件大小(默认为字节)
|
1 2 3 4 5 6 7 |
[root@localhost ~]# ls -h /home justin lost+found [root@localhost ~]# ls -lh /home 总用量 20K drwx------. 27 justin justin 4.0K 9月 22 13:19 justin drwx------. 2 root root 16K 9月 18 15:30 lost+found [root@localhost ~]# |
-R---若目录下有档案,也将档案依序列出
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
[root@localhost ~]# ls -lR /home /home: 总用量 20 drwx------. 27 justin justin 4096 9月 22 13:19 justin drwx------. 2 root root 16384 9月 18 15:30 lost+found /home/justin: 总用量 32 drwxr-xr-x. 2 justin justin 4096 9月 22 10:49 公共的 drwxr-xr-x. 2 justin justin 4096 9月 22 10:49 模板 drwxr-xr-x. 2 justin justin 4096 9月 22 10:49 视频 drwxr-xr-x. 2 justin justin 4096 9月 22 10:49 图片 drwxr-xr-x. 2 justin justin 4096 9月 22 10:49 文档 drwxr-xr-x. 2 justin justin 4096 9月 22 10:49 下载 drwxr-xr-x. 2 justin justin 4096 9月 22 10:49 音乐 drwxr-xr-x. 2 justin justin 4096 9月 22 10:49 桌面 /home/justin/公共的: 总用量 0 /home/justin/模板: 总用量 0 /home/justin/视频: 总用量 0 /home/justin/图片: 总用量 0 /home/justin/文档: 总用量 0 /home/justin/下载: 总用量 0 /home/justin/音乐: 总用量 0 /home/justin/桌面: 总用量 0 /home/lost+found: 总用量 0 [root@localhost ~]# |
-t---将档案按照建立时间的先后次序列出
|
1 2 3 4 5 6 7 8 9 10 11 |
[root@localhost ~]# ls -l /home 总用量 20 drwx------. 27 justin justin 4096 9月 22 13:19 justin drwx------. 2 root root 16384 9月 18 15:30 lost+found -rw-r--r--. 1 root root 0 9月 22 15:21 t [root@localhost ~]# ls -lt /home 总用量 20 -rw-r--r--. 1 root root 0 9月 22 15:21 t drwx------. 27 justin justin 4096 9月 22 13:19 justin drwx------. 2 root root 16384 9月 18 15:30 lost+found [root@localhost ~]# |
说明:ls命令还可以结合通配符“?”或“*”一起使用,问号“?”可以匹配文件名中的一个任意字符,而“*”可以匹配文件名中的任意多个字符。这两个通配符同样也适用于Shell环境中的其他大多数命令。
|
1 2 3 4 5 6 7 8 9 10 11 12 |
gssapi_mech.conf popt.d xml gtk-2.0 portreserve yp.conf hal postfix yum host.conf ppp yum.conf hosts prelink.cache yum.repos.d hosts.allow prelink.conf hosts.deny prelink.conf.d [root@localhost etc]# ll -d /etc/po*.d drwxr-xr-x. 2 root root 4096 1月 11 2010 /etc/popt.d [root@localhost etc]# ll -d /etc/po?.d ls: 无法访问/etc/po?.d: 没有那个文件或目录 [root@localhost etc]# |
du---显示文件或目录大小
-h或--human-readable---以K,M,G为单位,提高信息的可读性
|
1 2 3 4 5 |
[root@localhost src]# du -h nagios-3.5.0.tar.gz 1.8M nagios-3.5.0.tar.gz [root@localhost src]# du nagios-3.5.0.tar.gz 1748 nagios-3.5.0.tar.gz [root@localhost src]# |
-a---显示全部目录和其次目录下的每个档案所占的磁盘空间
-b或-bytes---显示目录或文件大小时,以byte为单位
|
1 2 3 |
[root@localhost local]# du -b src/nagios-3.5.0.tar.gz 1789376 src/nagios-3.5.0.tar.gz [root@localhost local]# |
-c或--total---显示每个目录或文件的大小外,同时也显示所有目录或文件的总和
-m或--megabytes---以1MB为单位
-s---只显示各档案大小的总合
|
1 2 3 |
[root@localhost local]# du -sh src/ 41M src/ [root@localhost local]# |
-x---只计算同属同一个档案系统的档案
-L---计算所有的档案大小
df---显示档案系统的状况;主要用来了解系统中已经挂载的各个文件系统的磁盘使用情况
-h 显示更易读的容量单位
-T 显示文件系统的类型
|
1 2 3 4 5 6 7 8 |
[root@localhost ~]# df -Th 文件系统 类型 容量 已用 可用 已用%% 挂载点 /dev/sda2ext49.9G 2.6G 6.9G 28% / tmpfs tmpfs 504M 112K 504M 1% /dev/shm /dev/sda1ext4194M 27M 158M 15% /boot /dev/sda5ext47.7G 147M 7.2G 2% /home /dev/sr0iso96602.9G 2.9G 0 100% /media/RHEL_6.3 i386 Disc 1 [root@localhost ~]# |
file---查看文件类型
|
1 2 3 4 5 6 |
[root@localhost home]# file justin/ justin/: directory [root@localhost home]# file justin1 justin1: empty [root@localhost ~]# file install.log install.log: UTF-8 Unicode text |
说明:file命令用于查看文件的类型,可以根据文件的内部存储结构来进行判别,而不根据文件的扩展名来进行判别。在Linux系统中,文件扩展名与文件类型没有绝对的关系。
文件内容查看
cat---显示文件内容
|
1 |
[root@localhost log]# cat /var/log/messages |
说明:cat在显示文本文件的内容时不进行停顿,对于内容较长的文件,在快速滚屏显示之后,只有最后一页的文件内容保留在屏幕中显示,因此cat不适合查看长文件。
more---分页显示文件内容
-num--- 一次显示的行数
-s ---当遇到有连续两行以上的空白行,就代换为一行的空白行
+num ---从第 num 行开始显示
|
1 2 3 4 5 6 7 |
[root@localhost log]# more -5s /var/log/messages Sep 22 10:36:06 localhost kernel: imklog 5.8.10, log source= /proc/kmsgstarted. Sep 22 10:36:06 localhost rsyslogd: [origin software="rsyslogd"swVersion="5.8.10"x-pid ="1323"x-info="http://www.rsyslog.com"] start Sep 22 10:36:06 localhost kernel: Initializing cgroup subsys cpuset Sep 22 10:36:06 localhost kernel: Initializing cgroup subsys cpu --More--(0%) |
说明:类似 cat ,不过会以一页一页的显示方便使用者逐页阅读,空白键(space):显示下一页,b 键:显示上一页,q 键 :退出
less----分页显示文件内容
说明:less命令的用法与more命令类似,它们之间的区别是当文件内容显示到文件尾时,more命令会自动退出阅读环境,而less命令不自动退出,用户仍然可以利用上下键来卷动文件,这样更加有利于对文件内容的反复阅读。当要结束浏览时,要在less命令的提示符“:”后按Q键退出
head---查看文件开头部分的内容
-n 指定显示的具体行数。
|
1 2 3 4 5 6 7 |
[root@localhost ~]# head -5 /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin [root@localhost ~]# |
说明:默认情况下,head显示前10行内容
tail---查看文件末尾部分的内容
|
1 2 3 4 5 6 7 |
[root@localhost ~]# tail -5 /etc/passwd nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin abrt:x:173:173::/etc/abrt:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin justin:x:500:500:justin_peng:/home/justin:/bin/bash [root@localhost ~]# |
说明:tail命令用法与head命令类似
创建文件(夹)命令
touch---改变档案的时间记录,档案不存在则创建一个空文件
|
1 2 3 4 |
[root@localhost home]# touch file1 file2 [root@localhost home]# ls file1 file2 justin lost+found t [root@localhost home]# |
-a 改变档案的读取时间记录。
-m 改变档案的修改时间记录。
-c 假如目的档案不存在,不会建立新的档案
说明:在实际使用中经常用于创建新的测试文件。使用文件名作为参数,可以同时创建多个文件。当目标文件已经存在时,将更新该文件的时间标记,否则将创建指定名称的空文件。
mkdir---Make Directory---创建新的目录
-p 确保目录名称存在,不存在的就建一个。
|
1 2 3 4 5 6 7 |
[root@localhost home]# ls justin lost+found t [root@localhost home]# mkdir dir1 [root@localhost home]# mkdir dir2/dir mkdir: 无法创建目录"dir2/dir": 没有那个文件或目录 [root@localhost home]# mkdir -p dir2/dir [root@localhost home]# |
同时创建多级目录
|
1 2 3 4 5 6 7 8 |
[root@localhost home]# ls justin lost+found t [root@localhost home]# mkdir -p {dir1,dir2/{dir3,dir4}} [root@localhost home]# ls dir1 dir2 justin lost+found t [root@localhost home]# ls dir2 dir3 dir4 [root@localhost home]# |
删除文件(夹)命令
rmdir---删除空目录(若目录非空删除中会报错)
-p 当子目录被删除后也成为空目录的话,则顺便一并删除
|
1 2 3 4 5 6 7 8 9 10 |
[root@localhost home]# mkdir -p {dir1,dir2/dir3} [root@localhost home]# ls dir1 dir2 justin lost+found t [root@localhost home]# rmdir dir1 [root@localhost home]# rmdir dir2 rmdir: 删除 "dir2"失败: 目录非空 [root@localhost home]# rmdir -p dir2/dir3/ [root@localhost home]# ls justin lost+found t [root@localhost home]# |
rm---删除档案或目录
-i 删除前逐一询问确认。
-f 即使原档案属性设为唯读,亦直接删除,无需逐一确认。
-r 将目录及以下档案也逐一删除。
|
1 2 3 4 5 6 |
[root@localhost home]# mkdir -p dir1/dir2 [root@localhost home]# rm -r dir1/ rm:是否进入目录"dir1"? y rm:是否删除目录 "dir1/dir2"?y rm:是否删除目录 "dir1"?y [root@localhost home]# |
2017-7-19-每日博客-关于Linux下的CentOS中文件夹基本操作命令.doc的更多相关文章
- 2017-7-18-每日博客-关于Linux下的鲜为人知的10条命令.doc
这篇文章的目的是介绍一些少有人知的Linux命令,它们一定会高效地帮你管理你的桌面/服务器. 1. sudo !!命令 没有特定输入sudo命令而运行,将给出没有权限的错误.那么,你不需要重写整个命令 ...
- 2017-7-18-每日博客-关于Linux下的history的常用命令.doc
History history命令可以用来显示曾执行过的命令.执行过的命令默认存储在HOME目录中的.bash_history文件中,可以通过查看该文件来获取执行命令的历史记录.需要注意的是.bash ...
- 2017-7-18-每日博客-关于Linux下的软链接和硬链接.doc
ln命令 该命令在文件之间创建链接.这种操作实际上是给系统中已有的某个文件指定另外一个可用于访问它的名称.对于这个新的文件名,我们可以为之指定不同的访问权限,以控制对信息的共享和安全性的问题. 如果链 ...
- Linux下对比两个文件夹的方法
最近拿到一份源代码,要命的是这份源代码是浅克隆模式的git包,所以无法完整显示里面的修改的内容. 今天花了一点点时间,找了一个在Linux对比两个文件夹的方法. 其实方法很简单,用meld 去对比两个 ...
- 2017-7-18-每日博客-关于Linux下的通配符.doc
*:匹配零个或多个字符 ?:匹配任意单个字符 ~:当前用户家目录 ~username:用户家目录 ~+:当前工作目录 ~-:上一个工作目录 [0-9]:匹配任意数字范围 [a-z]:匹配任意小写字母( ...
- linux下合并两个文件夹
一.我想把自己自定义的软件统一放到man手册路径里.如何和现有的/usr/local/share文件夹合并起来,原来的文件还在? (1)下面是解压出的自定义的bashdb调试软件==>
- linux下在多个文件夹中查找指定字符串的命令
例如,想要在当前文件夹下的多个.c或者.txt文件中查找“shutdown”字符串, 可以使用“grep shutdown ./*.c”或“grep shutdown ./*.txt”即可 使用fin ...
- linux 下怎样查找一个文件夹在哪个目录下?
如果只显示所在目录的路径: find 目录 -type d -name "查询目录名" -printf "%h\n" 如果同时显示目录名称和所在目录的路径: f ...
- linux 下查看有当前文件夹有多少个文件
ls |wc -w
随机推荐
- 【rich-text】 富文本组件说明
[rich-text] 富文本组件可以显示HTML代码样式. 1)支持事件:tap.touchstart.touchmove.touchcancel.touchend和longtap 2)信任的HTM ...
- Leetcode-跳跃游戏
跳跃游戏 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个位置. 示例 1: 输入: [2,3,1,1,4] ...
- spark dataset join 使用方法java
dataset<Row> df1,df2,df3 //该方法可以执行成功 df3= df1.join(df2,"post_id").selectExpr("h ...
- ntp服务:实现时间同步
一. 引言 目前的项目为分布式系统,采用dubbo+zookeepe,排查BUG,发现各个服务器的时间不一致,遂网上查找资源,使得时间保持一致. 二. 步骤 1)以第一台服务器为“服务端”,其他台服务 ...
- Executor Framework
Why? look at the following 2 pieces of code for implementing a simple web server based on socket, ca ...
- 迭代器类型:iterator & const_iterator
vector<int> ivec{1, 3, 4, 1, 3, 4}; vector<int>::iterator iter; // iter能读写vector<int& ...
- Thunder团队第五周 - Scrum会议6
Scrum会议6 小组名称:Thunder 项目名称:i阅app Scrum Master:邹双黛 工作照片: 宋雨同学在拍照,所以不在照片内. 参会成员: 王航:http://www.cnblogs ...
- Android之Bluetooth编程
Android Bluetopth 编程大牛文章 http://my.oschina.net/u/994235/blog?catalog=313604 ViewGroup 相关资料 : http:// ...
- Java内存区域划分和GC机制
Java 内存区域和GC机制 目录 Java垃圾回收概况 Java内存区域 Java对象的访问方式 Java内存分配机制 Java GC机制 垃圾收集器 Java垃圾回收概况 Java GC(Ga ...
- k邻近算法理解及代码实现
github:代码实现 本文算法均使用python3实现 1 KNN KNN(k-nearest neighbor, k近邻法),故名思议,是根据最近的 $ k $ 个邻居来判断未知点属于哪个类别 ...