一起来学Linux命令(一)

前言

目前正在出一个Linux命令系列教程, 篇幅会较多, 喜欢的话,给个关注❤️ ~

作为服务端开发,linux命令还是要掌握一下的,可以做做基础性的运维。好了, 废话不多说直接开整吧~

ls & 列出有关文件的信息(默认为当前目录)

例如: 列出指定目录下的文件

[root@iZ2ze5vrnucj8nu52fq932Z ~]# ls linux_study

ls  test

语法: ls [OPTION]... [FILE]...



-a  列出指定目录下的所有文件,包括隐藏文件

[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# ls -a
.  ..  .cache  ls  test
[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# 





-c 使用最后一次更改文件状态以进行排序(-t)或长时间打印(-l)的时间

[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# ls -c -a
.  .cache  test  ls  ..
[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# 




-l 长格式列表。(见下文)。如果输出到终端,则所有文件大小的总和将输出到长清单前面的一行中

root@iZ2ze5vrnucj8nu52fq932Z linux_study]# ls -l
total 8
drwxr-xr-x 2 root root 4096 Jul 20 09:59 ls
drwxr-xr-x 2 root root 4096 Jul 20 09:59 test
[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# 




-h 与-l选项一起使用时,显示的更直观

[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# ls -l -h

total 8.0K

drwxr-xr-x 2 root root 4.0K Jul 20 09:59 ls

drwxr-xr-x 2 root root 4.0K Jul 20 09:59 test

[root@iZ2ze5vrnucj8nu52fq932Z linux_study]#



-n 以数字形式显示用户和组id,而不是在长(-l)输出中转换为用户或组名。这个选项默认打开-l选项

[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# ls -n -l
total 8
drwxr-xr-x 2 0 0 4096 Jul 20 09:59 ls
drwxr-xr-x 2 0 0 4096 Jul 20 09:59 test
[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# 



-o 以长格式列出,但省略组id

[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# ls -o
total 8
drwxr-xr-x 2 root 4096 Jul 20 09:59 ls
drwxr-xr-x 2 root 4096 Jul 20 09:59 test
[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# 


-s 显示每个文件实际使用的文件系统块的数量,以512字节为单位,其中部分单元四舍五入为下一个整数值

[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# ls -s
total 8
4 ls  4 test
[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# 



-t 在按照字典顺序对操作数排序之前,先按修改的时间排序(最近修改的是first)

[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# ls -t -a
.  .cache  test  ls  ..
[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# 



-u 使用最后一次访问的时间,而不是最后一次修改文件进行排序

[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# ls -u
ls  test
[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# 

pwd & 打印当前工作目录的完整路径名

[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# pwd
/root/linux_study
[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# 

touch

将每个文件的访问和修改时间更新为当前时间,文件不存在则会创建文件。除非提供-c-h,否则将不存在的FILE参数创建为空。



[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# touch test1.txt test2.txt test3.txt
[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# ls
ls  test  test1.txt  test2.txt  test3.txt
[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# 





-a  或--time=atime或--time=access或--time=use 只更改存取时间。

-c  或--no-create 不建立任何文档。

[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# touch -c test4.txt 
[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# ls
ls  test  test1.txt  test2.txt  test3.txt
[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# 



-d 使用指定的日期时间,而非现在的时间。

-f 此参数将忽略不予处理,仅负责解决BSD版本touch指令的兼容性问题。

-m  或--time=mtime或--time=modify 只更改变动时间。

-r 把指定文档或目录的日期时间,统统设成和参考文档或目录的日期时间相同。


-t 使用指定的日期时间,而非现在的时间。

[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# touch -t 202307201000 test1.txt 
[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# ls -l -h

total 8.0K

drwxr-xr-x 2 root root 4.0K Jul 20 09:59 ls

drwxr-xr-x 2 root root 4.0K Jul 20 09:59 test

-rw-r--r-- 1 root root    0 Jul 20 10:00 test1.txt # 可以看到时间被更改了
-rw-r--r-- 1 root root    0 Jul 20 10:20 test2.txt
-rw-r--r-- 1 root root    0 Jul 20 10:20 test3.txt
[root@iZ2ze5vrnucj8nu52fq932Z linux_study]# 

结束语

命令很多,大家不用去背,可以放到便签之类的工具中,用到的时候翻一下就好~

本着把自己知道的都告诉大家,如果本文对您有所帮助,点赞+关注鼓励一下呗~

往期面试题相关文章

项目源码(源码已更新 欢迎star⭐️)

往期设计模式相关文章

设计模式项目源码(源码已更新 欢迎star⭐️)

Kafka 专题学习

项目源码(源码已更新 欢迎star⭐️)

ElasticSearch 专题学习

项目源码(源码已更新 欢迎star⭐️)

往期并发编程内容推荐

推荐 SpringBoot & SpringCloud (源码已更新 欢迎star⭐️)

博客(阅读体验较佳)

© 版权声明
THE END
喜欢就支持一下吧
点赞0

Warning: mysqli_query(): (HY000/3): Error writing file '/tmp/MYQhahlK' (Errcode: 28 - No space left on device) in /www/wwwroot/583.cn/wp-includes/class-wpdb.php on line 2345
admin的头像-五八三
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

图形验证码
取消
昵称代码图片