有趣生活

当前位置:首页>科技>linux用脚本创建10个文件Linux编程入门5-读取目录

linux用脚本创建10个文件Linux编程入门5-读取目录

发布时间:2026-07-25阅读(0)

导读学习目标通过分析ls指令,来学习Linux目录和文件属性相关的知识。代码实验环境操作系统:Ubuntu18.04LTS编译器gcc版本:gcc(Ubuntu....学习目标

通过分析 ls 指令,来学习 Linux 目录和文件属性相关的知识。

代码实验环境

操作系统:Ubuntu 18.04 LTS

编译器 gcc 版本:gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

ls 指令介绍

ls 指令可以列出目录中所有文件的名字,以及这些文件的其他信息。

在命令行输入 ls:

$ lsbin etc lib media root srv usrboot home lib32 mnt run swapfile varcdrom initrd.img lib64 opt sbin sys vmlinuzdev initrd.img.old lost found proc snap tmp vmlinuz.old

ls 的默认动作是找出当前目录中所有文件的名字,并按字典序排列后输出。

ls 还能显示其他信息,如果加上 -l 选项,ls 会列出每个文件的详细信息,也叫 ls 的长格式:

$ ls -ltotal 2097260drwxr-xr-x 2 root root 4096 9月 26 16:19 bindrwxr-xr-x 3 root root 4096 11月 10 09:11 bootdrwxrwxr-x 2 root root 4096 4月 18 2021 cdromdrwxr-xr-x 18 root root 4180 11月 16 22:57 devdrwxr-xr-x 147 root root 12288 11月 16 22:58 etcdrwxr-xr-x 3 root root 4096 6月 22 14:43 homelrwxrwxrwx 1 root root 34 11月 9 10:21 initrd.img -> boot/initrd.img-4.15.0-162-genericlrwxrwxrwx 1 root root 34 11月 9 10:21 initrd.img.old -> boot/initrd.img-4.15.0-161-genericdrwxr-xr-x 22 root root 4096 4月 18 2021 libdrwxr-xr-x 2 root root 4096 4月 18 2021 lib32drwxr-xr-x 2 root root 4096 4月 18 2021 lib64drwx------ 2 root root 16384 4月 18 2021 lost founddrwxr-xr-x 4 root root 4096 4月 21 2021 mediadrwxr-xr-x 2 root root 4096 4月 27 2018 mntdrwxr-xr-x 3 root root 4096 10月 29 13:08 optdr-xr-xr-x 240 root root 0 11月 16 22:57 procdrwx------ 7 root root 4096 5月 21 09:39 rootdrwxr-xr-x 31 root root 960 11月 16 22:58 rundrwxr-xr-x 2 root root 12288 11月 16 22:58 sbindrwxr-xr-x 15 root root 4096 9月 29 08:53 snapdrwxr-xr-x 2 root root 4096 4月 27 2018 srv-rw------- 1 root root 2147483648 4月 18 2021 swapfiledr-xr-xr-x 13 root root 0 11月 16 23:02 sysdrwxrwxrwt 14 root root 4096 11月 16 23:03 tmpdrwxr-xr-x 15 root root 4096 4月 18 2021 usrdrwxr-xr-x 15 root root 4096 8月 13 17:37 varlrwxrwxrwx 1 root root 31 11月 9 10:21 vmlinuz -> boot/vmlinuz-4.15.0-162-genericlrwxrwxrwx 1 root root 31 11月 9 10:21 vmlinuz.old -> boot/vmlinuz-4.15.0-161-generic

每一行代表一个文件和它的多个属性。

Linux 系统中会有很多的目录,每个目录中又会有很多文件。如果要列出一个非当前目录的内容或者是特定文件的信息,则需要在参数中给出目录名或文件名。

TAGS标签:  linux  脚本  创建  10个  文件  linux用脚本创建

Copyright © 2024 有趣生活 All Rights Reserve吉ICP备19000289号-5 TXT地图HTML地图XML地图