一、Linux下的文件类型

  • 普通文件:在由 ls –al 所显示出来的属性方面,第一个属性为 [ - ]
  • 目录文件:在由 ls –al 所显示出来的属性方面,第一个属性为 [ d ]
  • 设备文件:一般都在dev目录,有[b][c]

二、普通文件

2.1、文本文件

以ASCII码形式存储在计算机中

2.2、二进制文件

以文本的二进制形式存储在计算机中,如声音,图像等,只有通过相应的软件才能将其显示出来

2.3、连接文件

就是类似 Windows 底下的快捷方式啦!第一个属性为 [ l ];

三、目录文件

设计目录文件的主要目的是用于管理和组织系统中的大量文件,它存储一组相关文件的位置,大小与文件 有关的信息目录文件简称目录

四、设备文件

设备文件是Linux系统很重要的一个角色,Linux把每个I/O设备看成一个文件,与普通文件一样处理,这样可以使用文件 与设备的操作尽可能统一,从用户角度来看,对I/O设备的使用和一般文件使用一样,用户不必了解I/O细节,

设备文件又为块设备、和字符设备

4.1、块设备

成块读取数据的设备,硬盘,内存等 就是一些储存数据,以提供系统存取的接口设备,简单的说就是硬盘啦!

例如你的一号硬盘的代码是 /dev/hda1 等等的文件啦!第一个属性为 [ b ]

4.2、字符设备

 亦即是一些串行端口的接口设备,例如键盘、鼠标等等!第一个属性为 [ c ]。

五、文件相关的一些命令

5.1、touch

创建新文件

touch /data/text.txta

ls /data 查看

或者进入/data目录后,再创建

cd /data

touch text.txt

创建多个文件

touch .txt .txt .txt

或者

touch {a,b,c,d}.txt

touch /data/{q,w,e,r,t,y}.txt

大于号创建

>c.txt

重定向

ehco > a.txt

5.2、cp

复制文件或者目录

cp a.txt test4   //复制文件到test4文件下
[root@model Documents]# cp a.txt hh.txt test test4/ -i
cp: overwrite `test4/a.txt'? y //有相同文件是提示覆盖
[root@model Documents]# ll test4 //查看tests4目录
total
-rw-r--r--. root root Feb : a.txt
-rw-r--r--. root root Feb : hh.txt
-rw-r--r--. root root Feb : test
[root@model Documents]#
[root@model Documents]# cp test4/  tests/  -rip     //将test4整个目录cp到tests目录下
[root@model Documents]# ls tests/
a.txt c.txt test1 test4 x.txt z.txt
[root@model Documents]# ll tests/
total
-rw-r--r--. root root Feb : a.txt
-rw-r--r--. root root Feb : c.txt
drwxr-xr-x. root root Feb : test1
drwxr-xr-x. root root Feb : test4
-rw-r--r--. root root Feb : x.txt
-rw-r--r--. root root Feb : z.txt
[root@model Documents]#

5.3、rm

删除文件或者目录

[root@model Documents]# ll
total
-rw-r--r--. root root Feb a.txt
drwxr-xr-x. root root Feb com
drwxr-xr-x. root root Feb dir2
-rw-r--r--. root root Feb file1.txt
-rw-r--r--. root root Feb file2.doc
-rw-r--r--. root root Feb hh.txt
-rw-r--r--. root root Feb n.txt~
-rw-r--r--. root root Feb test
drwxr-xr-x. root root Feb test1
drwxr-xr-x. root root Feb test4
drwxr-xr-x. root root Feb tests
[root@model Documents]# rm -rf n.txt~ //删除文件不提示
[root@model Documents]# ll
total
-rw-r--r--. root root Feb a.txt
drwxr-xr-x. root root Feb com
drwxr-xr-x. root root Feb dir2
-rw-r--r--. root root Feb file1.txt
-rw-r--r--. root root Feb file2.doc
-rw-r--r--. root root Feb hh.txt
-rw-r--r--. root root Feb test
drwxr-xr-x. root root Feb test1
drwxr-xr-x. root root Feb test4
drwxr-xr-x. root root Feb tests
[root@model Documents]#
ls
a.txt dir2 file2.doc test test4
com file1.txt hh.txt test1 tests
[root@model Documents]# rm hh.txt //删除文件会默认提示
rm: remove regular empty file `hh.txt'? y
[root@model Documents]#
[root@model Documents]# ll test5
total
-rw-r--r--. root root Feb : .txt
-rw-r--r--. root root Feb : .txt
-rw-r--r--. root root Feb : .txt
-rw-r--r--. root root Feb : .txt
-rw-r--r--. root root Feb : .txt
[root@model Documents]# rm -rf test5 //删除整个目录不提示文件一起删除
[root@model Documents]# ll
total
-rw-r--r--. root root Feb a.txt
drwxr-xr-x. root root Feb com
drwxr-xr-x. root root Feb dir2
-rw-r--r--. root root Feb file1.txt
-rw-r--r--. root root Feb file2.doc
-rw-r--r--. root root Feb test
drwxr-xr-x. root root Feb test1
drwxr-xr-x. root root Feb test4
drwxr-xr-x. root root Feb tests
[root@model Documents]#

5.4、mv

移动文件或者目录

常用参数:

-b :若需覆盖文件,则覆盖前先行备份。

-f :force 强制的意思,如果目标文件已经存在,不会询问而直接覆盖;

-i :若目标文件 (destination) 已经存在时,就会询问是否覆盖!

-u :若目标文件已经存在,且 source 比较新,才会更新(update)

[root@model Documents]# ll
total
-rw-r--r--. root root Feb a.txt
drwxr-xr-x. root root Feb com
drwxr-xr-x. root root Feb dir2
-rw-r--r--. root root Feb file1.txt
-rw-r--r--. root root Feb file2.doc
-rw-r--r--. root root Feb test
drwxr-xr-x. root root Feb test1
drwxr-xr-x. root root Feb test4
drwxr-xr-x. root root Feb tests
[root@model Documents]# mv a.txt b.doc //文件重命名
[root@model Documents]# ll
total
-rw-r--r--. root root Feb b.doc
drwxr-xr-x. root root Feb com
drwxr-xr-x. root root Feb dir2
-rw-r--r--. root root Feb file1.txt
-rw-r--r--. root root Feb file2.doc
-rw-r--r--. root root Feb test
drwxr-xr-x. root root Feb test1
drwxr-xr-x. root root Feb test4
drwxr-xr-x. root root Feb tests
[root@model Documents]#
[root@model Documents]# ls
b.doc dir2 file2.doc test1 tests
com file1.txt test test4
[root@model Documents]# mv b.doc test4/yy.txt //移动文件并重命名
[root@model Documents]# ll test4/
total
-rw-r--r--. root root Feb a.txt
-rw-r--r--. root root Feb hh.txt
-rw-r--r--. root root Feb test
-rw-r--r--. root root Feb yy.txt
[root@model Documents]#
[root@model Documents]# ll
total
drwxr-xr-x. root root Feb com
drwxr-xr-x. root root Feb dir2
-rw-r--r--. root root Feb file1.txt
-rw-r--r--. root root Feb file2.doc
-rw-r--r--. root root Feb test
drwxr-xr-x. root root Feb test1
drwxr-xr-x. root root Feb : test4
drwxr-xr-x. root root Feb tests
[root@model Documents]# mv dir2/ test1/ //移动整个文件夹
[root@model Documents]# ll test1/
total
-rw-r--r--. root root Feb a.txt
-rw-r--r--. root root Feb b.txt
drwxr-xr-x. root root Feb dir2
-rw-r--r--. root root Feb n.txt
drwxr-xr-x. root root Feb : test2
[root@model Documents]#

5.5、find

查找文件或者目录

  • -name:可以用通配符来查找如:* ?
  • -size:可以用+,-来设置大小+表示大于多少,-表示少于多少
  • -user:属于哪个用户
  • -type:文件类型,普通文件有f,目录用d,块设备用b,字符设备用c
[root@model Documents]# find /etc/ -name resol*.conf   //-name使用
/etc/resolv.conf
/etc/sysconfig/networking/profiles/default/resolv.conf
[root@model Documents]#
[root@model Documents]# find /boot/ -type d       //-type使用查找boot目录下的所有目录
/boot/
/boot/efi
/boot/efi/EFI
/boot/efi/EFI/redhat
/boot/lost+found
/boot/grub
[root@model Documents]#
//查找当前目录中属于root用户的.txt的所有文件
[root@model test1]# ll
total
-rw-r--r--. root root Feb a.txt
-rw-r--r--. root root Feb b.txt
drwxr-xr-x. root root Feb dir2
-rw-r--r--. root root Feb n.txt
drwxr-xr-x. root root Feb : test2
[root@model test1]# find ./*.txt -user root
./a.txt
./b.txt
./n.txt
[root@model test1]#

5.6、which

查找命令文件的位置

//查找命令所在位置
[root@model test1]# which ls
alias ls='ls --color=auto'
/bin/ls
[root@model test1]# which cat
/bin/cat
[root@model test1]# which rm
alias rm='rm -i'
/bin/rm
[root@model test1]# which touch
/bin/touch
[root@model test1]# which mv
alias mv='mv -i'
/bin/mv
[root@model test1]#

5.7、file

查看文件类型

[root@model test1]# file a.txt
a.txt: ASCII text
[root@model test1]# file dir2/
dir2/: directory
[root@model test1]#
[root@model test1]# file ls
ls: cannot open `ls' (No such file or directory)
[root@model test1]# which ls
alias ls='ls --color=auto'
/bin/ls
[root@model test1]# file /bin/ls
/bin/ls: ELF -bit LSB executable, x86-, version (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6., stripped
[root@model test1]# file /etc/init.d/network
/etc/init.d/network: Bourne-Again shell script text executable
[root@model test1]# file /dev/sda1
/dev/sda1: block special
[root@model test1]# file /dev/lp3
/dev/lp3: character special
[root@model test1]#

5.8、ln

建立快捷方式:硬连接和符号连接(软件连接)

不能对目录,创建硬连接,也不能跨越分区创建硬链拉文件

创建软件连接时需要加参数[-s]

如果你用ls察看一个目录时,发现有的文件后面有一个@的符号,那就是一个用ln命令生成的文件

[root@model Downloads]# ln ../Documents/test1/a.txt
[root@model Downloads]# ll
total
-rw-r--r--. root root Feb a.txt

Linux文件类型(学习笔记六)的更多相关文章

  1. Linux文件权限学习笔记

    文件权限共10个字符,第一个字符表示该文件是[文件夹]或[文件]——如果是字符“d"则表示该文件是文件夹:如果是字符“-”则表示是文件. 后九个字符,三个一组,共三组,分别表示[所有者权限] ...

  2. Linux System Programming 学习笔记(六) 进程调度

    1. 进程调度 the process scheduler is the component of a kernel that selects which process to run next. 进 ...

  3. linux命令学习笔记(24):Linux文件类型与扩展名

    Linux文件类型和Linux文件的文件名所代表的意义是两个不同的概念.我们通过一般应用程序 而创建的比如file.txt.file.tar.gz ,这些文件虽然要用不同的程序来打开,但放在Linux ...

  4. java之jvm学习笔记六-十二(实践写自己的安全管理器)(jar包的代码认证和签名) (实践对jar包的代码签名) (策略文件)(策略和保护域) (访问控制器) (访问控制器的栈校验机制) (jvm基本结构)

    java之jvm学习笔记六(实践写自己的安全管理器) 安全管理器SecurityManager里设计的内容实在是非常的庞大,它的核心方法就是checkPerssiom这个方法里又调用 AccessCo ...

  5. Linux学习笔记(六) 进程管理

    1.进程基础 当输入一个命令时,shell 会同时启动一个进程,这种任务与进程分离的方式是 Linux 系统上重要的概念 每个执行的任务都称为进程,在每个进程启动时,系统都会给它指定一个唯一的 ID, ...

  6. 兄弟连Linux运维学习笔记

    最新经典linux运维兄弟连Linux运维学习笔记... --------------- 全程1.5倍播放.加油我一定可以学完Linux----------------------Unix与Linux ...

  7. 【opencv学习笔记六】图像的ROI区域选择与复制

    图像的数据量还是比较大的,对整张图片进行处理会影响我们的处理效率,因此常常只对图像中我们需要的部分进行处理,也就是感兴趣区域ROI.今天我们来看一下如何设置图像的感兴趣区域ROI.以及对ROI区域图像 ...

  8. Spring Boot 学习笔记(六) 整合 RESTful 参数传递

    Spring Boot 学习笔记 源码地址 Spring Boot 学习笔记(一) hello world Spring Boot 学习笔记(二) 整合 log4j2 Spring Boot 学习笔记 ...

  9. Java IO学习笔记六:NIO到多路复用

    作者:Grey 原文地址:Java IO学习笔记六:NIO到多路复用 虽然NIO性能上比BIO要好,参考:Java IO学习笔记五:BIO到NIO 但是NIO也有问题,NIO服务端的示例代码中往往会包 ...

随机推荐

  1. Codeforces Round #259 (Div. 1) A. Little Pony and Expected Maximum 数学公式结论找规律水题

    A. Little Pony and Expected Maximum Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.c ...

  2. poj 3660 Cow Contest Flyod

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5989   Accepted: 3234 Descr ...

  3. Nginx学习之一-惊群现象

    惊群问题(thundering herd)的产生 在建立连接的时候,Nginx处于充分发挥多核CPU架构性能的考虑,使用了多个worker子进程监听相同端口的设计,这样多个子进程在accept建立新连 ...

  4. IO流-批量修改文件名称案例

    /* *   源文件名:   桌面-我们今天学习IO流了哈哈哈哈-001.jpg *   修改后文件名:  桌面-000x.jpg */public class File_listFiles_upda ...

  5. xamarin其实也是一个鸡肋

    刚刚体验了一把VS 2015,后来因为部分sdk和工具下载太慢,还是最终决定卸载.顺道了解了下xamarin studio.个人感觉Xamarin完全也是一个鸡肋,没必要过多的时间在xamarin上面 ...

  6. MVC动态添加文本框,后台使用FormCollection接收

    在"MVC批量添加,增加一条记录的同时添加N条集合属性所对应的个体"中,对于前台传来的多个TextBox值,在控制器方法中通过强类型来接收.使用FormCollection也可以接 ...

  7. IOS开发之深拷贝与浅拷贝(mutableCopy与Copy)详解

    copy与retain的区别: copy是创建一个新对象,retain是创建一个指针,引用对象计数加1.Copy属性表示两个对象内容相同,新的对象retain为1 ,与旧有对象的引用计数无关,旧有对象 ...

  8. linux-修改时区时间

    所有笔记基于-CentOS release 6.8 (Final) ntpdate 202.120.2.101 同步上海时间 cp -f /usr/share/zoneinfo/Asia/Shangh ...

  9. Oracle学习中,重点是sql语句的学习,而所有的sql语句都要在scott用户下完成。

    熟悉这个用户下的四张表,是必要的. 查看所有表名: SELECT * FROM tab; 查看每张表的结构: DESC 表名称: 1.部门表:dept no  名称 类型 描述 1 DEPTNO NU ...

  10. Tomcat集群Spring+Quartz多次执行解决方案记录

    由于在集群环境下定时器会出现并发和重复执行的问题,我再三考虑记录有5 一.把定时器模块单独拿出来放到一台tomcat或者新建一个Java工程手动启动定时器,这样定时器的任务就可以从原来的集群中抽离开来 ...