Linux目录/文件基础操作

1.1 问题

本例要求熟悉Linux系统中的目录/文件基础操作命令,在虚拟机上完成下列任务。

1)列出目录及文件属性

查看根目录 / 下有哪些文档或子目录
列出当前目录下的所有文档(包括隐藏文档)
列出 /root/ 目录下以 ana开头的文档,识别文档大小

2)使用cat查看文件/etc/hostname 的内容

3)使用less分页阅读文件 /proc/cpuinfo 的内容

4)创建目录结构 /notes/linux
1.2 步骤

实现此案例需要按照如下步骤进行。

步骤一:列出目录及文件属性

1)查看根目录 / 下有哪些文档或子目录,这些文档的颜色有什么规律

[root@svr7 ~]# ls  /
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr

在白底黑字的命令行终端上的ls显示结果中,黑色表示常规文件、深蓝色表示目录、浅蓝色表示快捷方式、绿色表示可执行文件、红色表示压缩包文件、黄色表示设备。

2)列出当前目录下的所有文档(包括隐藏文档)

[root@svr7 ~]# ls
anaconda-ks.cfg       公共  视频  文档  音乐
initial-setup-ks.cfg  模板  图片  下载  桌面
[root@svr7 ~]# ls  -A
anaconda-ks.cfg  .cshrc                pass.txt     图片
.bash_history    .dbus                 .ssh         文档
.bash_logout     .esd_auth             .tcshrc      下载
.bash_profile    .ICEauthority         .Xauthority  音乐
.bashrc          initial-setup-ks.cfg  公共         桌面
.cache           .local                模板
.config          .mozilla              视频

3)列出 /root/ 目录下以 ana开头的文档,识别文档大小

[root@svr7 ~]# ls -lh /root/ana*
-rw-------. 1 root root 1.7K 4月  15 11:46 /root/anaconda-ks.cfg

步骤二:使用cat命令查看文件/etc/hostname 的内容

通过查看文件 /etc/hostname 的内容,可以了解当前系统的主机名。

[root@svr7 ~]# cat  /etc/hostname 
svr7.tedu.cn

步骤三:使用less分页阅读文件 /proc/cpuinfo 的内容

通过查看文件 /proc/cpuinfo,可以了解当前计算机的CPU处理器信息。

[root@svr7 ~]# less  /proc/cpuinfo
processor       : 0                                      //CPU核心编号
vendor_id       : GenuineIntel                          //厂商ID
cpu family      : 6
model           : 61
model name      : Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz
stepping        : 4
microcode       : 0x21
cpu MHz         : 2194.923                              //CPU主频
cache size      : 3072 KB                                 //缓存
physical id     : 0                                     //物理CPU编号
siblings        : 1
core id         : 0
cpu cores       : 1
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 20
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt arat
.. ..                                             //按q键可退出浏览
[root@svr7 ~]#

步骤四:创建目录结构 /notes/linux

创建多层目录结构时,注意添加 -p 选项。

1)创建新目录

[root@svr7 ~]# ls  -ld /notes/linux
ls: 无法访问/notes/linux: 没有那个文件或目录
[root@svr7 ~]# mkdir  /notes/linux
mkdir: 无法创建目录"/notes/linux": 没有那个文件或目录
[root@svr7 ~]# mkdir  -p  /notes/linux

2)确认创建结果

[root@svr7 ~]# ls  -ld  /notes/linux/ 
drwxr-xr-x. 2 root root 6 12月 19 11:44 /notes/linux/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

彭淦淦

是你的双手成就了我的生活!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值