Linux指令手册 (一)
指令格式
指令主体 [选项] [操作对象]
一个完整的指令是由“指令主体”、“选项”和“操作对象”组成的,其中指令主体只能有一个,选项有零个或多个,操作对象有零个或多个。
在操作文件时,经常会使用到绝对路径和相对路径:
- 相对路径:指当前工作路径;
- 绝对路径:以“/”目录为工作路径。
./表示当前目录下;../表示上一级目录下
ls
ls,用于列出当前目录下的所有文件。
语法:ls [options] [target]
options:选项;target:操作的目标目录。
参数:
- -l:除文件名称外,亦将文件型态、权限、拥有者、文件大小等资讯详细列出;
- -a:显示所有文件及目录 (. 开头的隐藏文件也会列出);
- -h:显示大小;
- -r:将文件以相反次序显示(原定依英文字母次序);
- -t:将文件依建立时间之先后次序列出;
- 组合使用:-la、-lh、-lr、-lt。
ls -l
-l,以列表形式列出当前目录下的文件和目录,不包含隐藏的。
[root@VM-0-6-centos /]# ls -l /
total 108
lrwxrwxrwx. 1 root root 7 Aug 8 2018 bin -> usr/bin
dr-xr-xr-x. 5 root root 4096 May 24 17:33 boot
drwxr-xr-x 2 root root 4096 Jan 21 2019 data
drwxr-xr-x 19 root root 2980 May 24 17:38 dev
drwxr-xr-x. 88 root root 12288 May 24 14:33 etc
......
total显示数为108
ls -la
-la,以列表形式列出当前目录下的所有文件和目录,包括隐藏的
[root@VM-0-6-centos /]# ls -la /
total 116
dr-xr-xr-x. 21 root root 4096 Jun 4 11:03 .
dr-xr-xr-x. 21 root root 4096 Jun 4 11:03 ..
lrwxrwxrwx. 1 root root 7 Aug 8 2018 bin -> usr/bin
dr-xr-xr-x. 5 root root 4096 May 24 17:33 boot
drwxr-xr-x 2 root root 4096 Jan 21 2019 data
drwxr-xr-x 19 root root 2980 May 24 17:38 dev
drwxr-xr-x. 88 root root 12288 May 24 14:33 etc
......
total显示数为116,比ls -l列出的文件和目录数更多
ls -lh
-lh,以列表形式列出文件和目录,并显示大小,不包含隐藏的
[root@VM-0-6-centos /]# ls -lh /
total 108K
lrwxrwxrwx. 1 root root 7 Aug 8 2018 bin -> usr/bin
dr-xr-xr-x. 5 root root 4.0K May 24 17:33 boot
drwxr-xr-x 2 root root 4.0K Jan 21 2019 data
drwxr-xr-x 19 root root 3.0K May 24 17:38 dev
drwxr-xr-x. 88 root root 12K May 24 14:33 etc
......
ls -lr
以列表形式将文件以相反次序显示(原定依英文字母次序)
[root@VM-0-6-centos /]# ls -lr /
total 108
drwxr-xr-x 7 root root 4096 May 24 11:06 www
drwxr-xr-x. 19 root root 4096 May 24 14:06 var
drwxr-xr-x. 13 root root 4096 Aug 8 2018 usr
......
drwxr-xr-x 2 root root 4096 Jan 21 2019 data
dr-xr-xr-x. 5 root root 4096 May 24 17:33 boot
lrwxrwxrwx. 1 root root 7 Aug 8 2018 bin -> usr/bin
ls -lt
-lt,以列表形式将文件依建立时间之先后次序列出
[root@VM-0-6-centos /]# ls -lt /
total 108
drwxrwxrwt. 16 root root 4096 Jun 4 11:16 tmp
dr-xr-x---. 10 root root 4096 May 28 15:01 root
drwxr-xr-x 2 root root 4096 Jan 21 2019 data
drwxr-xr-x. 13 root root 4096 Aug 8 2018 usr
drwxr-xr-x. 2 root root 4096 Apr 11 2018 srv
pwd
pwd,即print work directory,用于显示目前所在的工作目录的绝对路径名称。
[root@VM-0-6-centos training]# pwd
/opt/web-application/training
mkdir
mkdir,即make directory,用于创建目录。
语法:mkdir [options] [target]
options:选项;target:操作的目标目录。
参数:
- -p:一次性创建多层目录。
当操作对象有多个时,分别在当前目录下创建同级目录:
[root@VM-0-6-centos opt]# mkdir temp1 temp2 temp3
[root@VM-0-6-centos opt]# ls
temp1 temp2 temp3
mkdir -p
一次性创建多层级的目录
[root@VM-0-6-centos opt]# mkdir -p ./temp1/temp2/temp3
[root@VM-0-6-centos opt]# cd temp1
[root@VM-0-6-centos temp1]# cd temp2
[root@VM-0-6-centos temp2]# cd temp3
[root@VM-0-6-centos temp3]# pwd
/opt/temp1/temp2/temp3
touch
touch,用于修改文件或者目录的时间属性,包括存取时间和更改时间。若文件不存在,系统会建立一个新的文件。
语法:touch [target]
target:文件名+后缀,如test.txt。
[root@VM-0-6-centos opt]# touch test.txt
[root@VM-0-6-centos opt]# ls -l
-rw-r--r-- 1 root root 0 Jun 4 15:05 test.txt
[root@VM-0-6-centos opt]# vim test.txt
hello world! 2021年6月4日15:05:00
~
~
"test.txt" 2L, 38C
使用ls指令列出目录信息,test.txt最后一次修改时间为15:05,再次touch test.txt时,会修改为当前操作的时间,且不会修改文件的内容。
[root@VM-0-6-centos opt]# touch test.txt
[root@VM-0-6-centos opt]# vim test.txt
hello world! 2021年6月4日15:05:00
~
~
"test.txt" 2L, 38C
cp
cp,即copy file,主要用于复制文件或目录。
语法:cp [options] [target] [destination]
options:选项;target:操作的目标目录;destination:复制的目标目录。
参数:
- -r:若给出的源文件是一个目录文件,此时将复制该目录下所有的子目录和文件;
- -f:覆盖已经存在的目标文件而不给出提示。
cp -r
若给出的是一个目录,则将该目录下所有的子目录和文件都复制到目标位置。
[root@VM-0-6-centos opt]# cp -r demo/ temp
[root@VM-0-6-centos opt]# cd temp
[root@VM-0-6-centos temp]# ls
demo.html demo.js demo.text
cp -f
若直接覆盖目标目录下的同名文件,会提示是否覆盖
[root@VM-0-6-centos opt]# cp demo/demo.html temp/demo.html
cp: overwrite ‘temp/demo.html’? y
而在选项中加上-f,就不会提示。
mv
mv,即move file,用于为文件或目录改名、或将文件或目录移入其它位置。
语法:mv [target] [destination]
target:操作的目标目录;destination:移动的目标目录。
参数:
- -b: 当目标文件或目录存在时,在执行覆盖前,会为其创建一个备份;
- -i: 如果指定移动的源目录或文件与目标的目录或文件同名,则会先询问是否覆盖旧文件,输入 y 表示直接覆盖,输入 n 表示取消该操作;
- -f: 如果指定移动的源目录或文件与目标的目录或文件同名,不会询问,直接覆盖旧文件;
- -n: 不要覆盖任何已存在的文件或目录;
- -u:当源文件比目标文件新或者目标文件不存在时,才执行移动操作。
mv -b
通常情况下移动目录或文件后,不会保留原来工作目录下文件或目录。
[root@VM-0-6-centos temp1]# ls
temp2 test.txt
[root@VM-0-6-centos temp1]# mv test.txt temp2
[root@VM-0-6-centos temp1]# ls
temp2
[root@VM-0-6-centos temp2]# ls
test.txt
执行mv test.txt temp2之后,temp1目录下的test.txt不会保留。
加入选项-b后,在执行覆盖前,会为其创建一个备份。
[root@VM-0-6-centos temp1]# ls
temp2 test.txt
[root@VM-0-6-centos temp1]# mv test.txt temp2
[root@VM-0-6-centos temp1]# ls
temp2
[root@VM-0-6-centos temp1]# cd temp2
[root@VM-0-6-centos temp2]# ls
test.txt
执行mv -b test.txt temp2之后,temp1目录下的test.txt将会保留。
rm
rm,即remove,用于删除一个文件或者目录。
语法:rm [options] [target]
options:选项;target:操作目标的文件或目录。
参数:
- -i: 删除前逐一询问确认;
- -f: 直接删除,无需逐一确认;
- -r: 将目录及以下的文件或子目录逐一删除。
通常删除操作使用的是rm -rf [target]指令。
Linux指令手册 (一)的更多相关文章
- Linux指令手册 (二)
free free,显示系统中可用内存和已使用内存的数量. 语法:free [options] [target] 参数: -b: 以字节(bytes)显示内存量: -k: 以千字节(kilo)为单位显 ...
- Linux指令范例速查手册
linux命令繁多,命令就是AK的子弹,对上口径,百发百中! 无意发现一本介绍Linux命令的手册--->[Linux指令范例速查手册] 下载: https://pan.baidu.com/s/ ...
- Solaris/Linux 命令手册
无意翻到之前收藏的一个文档,共享一下. Solaris/Linux 命令手册 1. 系统 # passwd:修改口令 # exit:退出系统 2. 文件 # cp:复制文件或目录,参数:-a递归目录, ...
- linux实用指令 | 程序员线上排查必知必会linux指令(持续更新中)
Linux线上排查程序员实用指南 一.乱码问题 二.帮助指令 1. help命令 2. man命令 3. info命令 三.性能监测与优化 1. top命令 参考资源 Linux线上排查程序员实用指南 ...
- Linux 指令大全
作为一个小前端,以前有我们的运维大神在的时候,要给服务器做什么配置的时候就找他(那时幸福到哭),如今他走了,公司也没招人(想把这个钱省下来,让我发现了,毕竟我能当小运维用,虽然很这方面很渣渣,哈哈,偷 ...
- Linux 指令。
从16年11月21号开始吧,加班变得特别频繁,基本上一周加5天,周六也会加,下班也很晚,一般都是10点9点,回家之后很疲惫,已经很久没有给自己充过电了,自己的学习计划和健身计划也打乱了,对工作的压力也 ...
- 04 Linux 指令语法结构与帮助命令
一.Linux指令语法结构 [tyang3@localhost Desktop]$ command [-options] [arguments] 指令 选项 参 ...
- linux指令大全(完整篇)(转)
http://blog.chinaunix.net/uid-9681606-id-1998590.html linux指令大全(完整篇)(转) 2009-03-17 01:21:46 分类: ...
- linux 指令备忘
linux 指令备忘 1.ls [选项] [目录名 | 列出相关目录下的所有目录和文件 -a 列出包括.a开头的隐藏文件的所有文件 -A 通-a,但不列出"."和"..& ...
随机推荐
- OpenStack neutron vlan 模式下的网络包流向
时间:2015-01-15 18:09:41 1.什么是Neutron? Neutron是OpenStack的network project ,是NaaS(networking-as-a-servic ...
- MySQL8 配置远程连接
引言 MySQL8 默认安装后只有本机能访问,如果需要远程连接 MySQL 将无法访问 查看 root 用户权限 进入 mysql 表 select user,host,plugin from use ...
- Linux 核心系统命令目录
S5 Linux信息显示与搜索文件命令 S6 文件备份与压缩命令 S7 Linux用户管理及用户信息查询命令 S8 Linux磁盘与文件系统管理命令 S9 Linux 进程管理命令 S10 Linux ...
- 【长期更新】Ubuntu常用命令备忘录
Error Could not get lock /var/lib/dpkg/lock 出现这个问题可能是有另外一个程序正在运行,导致资源被锁不可用.而导致资源被锁的原因可能是上次运行安装或更新时没 ...
- Python中if name == 'main':的作用
一个python文件通常有两种使用方法, 第一是作为脚本直接执行. 第二是 import 到其它的 python 脚 本中被调用(模块重用)执行. 因此 if name == 'main': 的作用就 ...
- 使用Selenium从IEEE与谷歌学术批量爬取BibTex文献引用
搞科研的小伙伴总是会被期刊严苛的引用文献格式搞的很头疼.虽然常用的文献软件可以一键导出BibTex,但由于很多论文在投稿之前都会先发上Arxiv占坑,软件就很可能会把文献引出为来自Arxiv.我用的是 ...
- SystemVerilog数组(一)
- 【MybatisPlus】数据库的datetime类型字段为空的时候,报错空指针?
一.发现经历 事情是这样的,我今天本来要演示系统,就去前端同学的页面上点一点.不小心点到了其他同事编写的服务,然后界面就报错了.这给我吓得,这还能演示吗这.然后,我就去服务器查看了一下日志,发现了如下 ...
- springboot对mybatis的整合
1. 导入依赖 首先新建一个springboot项目,勾选组件时勾选Spring Web.JDBC API.MySQL Driver pom.xml配置文件导入依赖 <!--mybatis-sp ...
- Python+Selenium - windows安全中心的弹窗(账号登录)
当出现如下图所示的 Windows安全中心弹窗,需要输入用户名和密码时 如何用Python+selenium跳过这个登录. 步骤: 1.在注册表中三个位置各添加两个东西:iexplore.exe 和 ...