Linux文件管理学习

版权声明:本文为博主原创文章,仅代博主个人观点,未经博主允许不得转载。 https://blog.csdn.net/qq_19645105/article/details/83451625
业精于勤,荒于嬉,行成于思,毁于随
Linux中 数据和程序都是以文件形式保存的。

-:普通文件

----------.   1 root root   1244 99 08:07 shadow
----------.   1 root root   1215 99 07:52 shadow-
-rw-r--r--.   1 root root     51 815 19:58 shells

d :目录文件

drwxr-xr-x.   3 root root   4096 815 19:56 sound
drwxr-xr-x.   2 root root   4096 815 20:00 ssh
drwxr-xr-x.   2 root root   4096 815 19:54 ssl
drwx------.   2 root root   4096 622 2012 sssd

l :链接文件

lrwxrwxrwx. 1 root root           3 1027 01:00 dvd -> sr0
lrwxrwxrwx. 1 root root           3 1027 01:00 dvd1 -> sr1
lrwxrwxrwx. 1 root root           3 1027 01:00 dvdrw -> sr0
lrwxrwxrwx. 1 root root           3 1027 01:00 dvdrw1 -> sr1
lrwxrwxrwx. 1 root root           3 1027 01:00 fb -> fb0

b,c:设备文件

brw-rw----. 1 root cdrom    11,   0 1027 01:00 sr0
brw-rw----. 1 root cdrom    11,   1 1027 01:00 sr1
crw-rw----. 1 vcsa tty       7,   1 1027 01:00 vcs1
crw-rw----. 1 vcsa tty       7,   2 1027 01:01 vcs2
crw-rw----. 1 vcsa tty       7,   3 1027 01:01 vcs3

p:管道文件 特殊的文件用于不同的进程间的传递

s:套接字文件 用于网络不同的计算机进程通信
p和s 没搞懂 还要查询资料
Linux目录结构

  • / Linux文件系统的入口
  • /bin 可执行二进制文件的目录。例如ls,tar,cat
  • /boot
  • /dev
  • /etc 系统配置文件
  • /home
  • /lib 存放系统使用的额函数库
  • /mnt外部设备挂接点
  • /proc用于提供系统的运行信息
  • /root
  • /sbin 存放管理员可执行的命令 root可以使用的命令
  • /srv 服务启动后要访问的数据目录
  • /tmp
  • /usr应用程序存放的目录
  • /var存放系统经常变化的文件
  • /lost+found 一些丢失的文件可以在这里找到
    绝对路径 相对路径 要知道是什么
    文件和目录的属性
    在这里插入图片描述
  1. i节点号
  2. 文件类型
  3. 文件权限
  4. 连接计数 表明系统中有几个文件共用该文件的inode,
  5. 文件拥有者
  6. 文件群组
  7. 文件或目录的大小
  8. 访问或修改时间 这里的是最后修改文件内容的时间
    每个文件或目录都有9个权限位每三个一组分别是拥有者,组群,其他
    在目录中的文件不管什么权限跟随目录的权限

修改文件和目录的拥有者

       chown [-Rh] 文件的新拥有者 文件名
       -R 递归
       -h 改变符号链接文件的拥有者时不影响链接所指向的目标文件

修改文件和目录的组群

       chgrp [-Rh] 文件的新组群名 文件名
       -R 递归
       -h 改变符号链接文件的拥有者时不影响链接所指向的目标文件

修改文件和目录存取权限

       chmod [-R] 文件名1 文件名2···
       -R 递归

权限值 r 4 w 2 x1
文件的隐藏属性和默认权限
chattr lsattr 默认权限umask
文件的特殊权限除了 rwx 还有3个特殊的权限 setuid , setgid ,stick bit
权限中 s 普通用户暂时有root权限 ,t 指stick bit(粘贴位)
setuid ,4 setgid 2 , stick bit 1
例如设置text文件的特殊权限
setuid:

#chmod 4755 text  
[root@localhost zhang]# chmod 4755 text
[root@localhost zhang]# ll
总用量 4
-rwsr-xr-x. 1 root  root     0 1027 02:41 text

setgid:

[root@localhost zhang]# chmod 2755 text
[root@localhost zhang]# ll
总用量 4
-rwxr-sr-x. 1 root  root     0 1027 02:41 text

stick bit:

[root@localhost zhang]# chmod 1755 text
[root@localhost zhang]# ll
总用量 4
-rwxr-xr-t. 1 root  root     0 1027 02:41 text 

hwclock -w 系统时间同步到硬件 -s 相反
常用的文件和目录管理指令命令

  • ls [-Radlrtupi] [目录或文件名]
  • pwd
  • cd [目录名]
  • mkdir
 mkdir [OPTION]... DIRECTORY...
DESCRIPTION
       Create the DIRECTORY(ies), if they do not already exist.
       Mandatory arguments to long options are mandatory for short
       options too.
       -m, --mode=MODE
              set file mode (as in chmod), not a=rwx - umask
       -p, --parents
              no error if existing, make parent directories as needed
       -v, --verbose
              print a message for each created directory
       -Z, --context=CTX
              set the SELinux security context of each created
              directory to CTX
       --help display this help and exit
       --version
              output version information and exit
  • mv
  • rm

查看文件内容的指令

  • cat
  • more [-cdflrsuw]
  • less
  • head
  • tail
  • nl [-bnw] nl命令读取文件(缺省情况下读取标准输入),
  • tac 与cat相反最后一行先显示 然后倒数第二行

查询指令

  • which 可执行文件名
  • whereis [-bmsu] [BMS 目录名 -f] 文件名 ##定位可执行文件,源代码文件,帮助文件在系统中的位置.
  • find [path] -option [-print] [-exec -ok command] {} ; ##要多学习多使用
  • locate [参数] [样式] 配合数据库查看文件位置

链接文件 要会区分软连接 硬链接区别
软链接 指向目标文件
硬链接 指向inode 不能夸分区
用ln 命令可创建链接文件 -s 软链接

猜你喜欢

转载自blog.csdn.net/qq_19645105/article/details/83451625
今日推荐