博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
环境变量PATH, cp和mv命令,文档查看
阅读量:7053 次
发布时间:2019-06-28

本文共 2388 字,大约阅读时间需要 7 分钟。

hot3.png

9月13日任务

2.10 环境变量PATH

2.11 cp命令

2.12 mv命令

2.13 文档查看cat/more/less/head/tail

 

环境变量PATH

我们运行命令时如ls命令,并不是使用其绝对路径形式/bin/ls,只使用相对路径形式的ls命令就可以执行,

这时因为/bin在环境变量PATH内,所以该目录的ls二进制文件就可以直接执行了。

 

暂时新增目录至PATH环境变量

[root@centos7 ~]# PATH=$PATH:/test

永久追加目录至PATH环境变量

在其最后一行追加 PATH = $PATH:DIR[root@centos7 ~]# vim /etc/profile...PATH=$PATH:/test保存退出,重启后生效

拷贝命令 cp

  • -r参数:拷贝目录

            拷贝目录时,如果目标目录已存在,会将源目录放置到目标目录下;目标目录不存在,将目录改名为目标目录。

  • -p参数:拷贝时保留原属性

  • -i参数:拷贝时询问是否覆盖已存在文件,默认cp命令就加上了-i参数

            约定:目录表示最后需加上/,如 cp /test/

# 将一个目录拷贝到另外一个目录中# 并不是单纯将test目录下的文件拷贝到test1内,# 而是将test目录放置到test1目录下[root@centos7 ~]# cp -r /test /test1[root@centos7 ~]# tree /test1/test1└── test    ├── ls    └── ls.new1 directory, 2 files
[root@centos7 ~]# cp -p /bin/ls /test/[root@centos7 ~]# cp /bin/ls /test/ls.new[root@centos7 ~]# ls -l /test/ls /bin/ls /test/ls.new-rwxr-xr-x. 1 root root 117656 ... /bin/ls-rwxr-xr-x. 1 root root 117656 ... /test/ls-rwxr-xr-x. 1 root root 117656 ... /test/ls.new
[root@centos7 ~]# alias cpalias cp='cp -i'

移动/重命名命令 mv

mv命令(alias mv='mv -i')

 

  • mv的目标是目录但不存在,源目录会重命名为目标目录

  • mv的目标是目录且存在,源文件或目录会被移到该目标目录下

  • mv的目标是文件且存在,询问是否覆盖

  • mv的目标是文件但不存在,重命名为目标文件名

[root@centos7 test]# lsdir1  dir2[root@centos7 test]# mv dir1 dir3[root@centos7 test]# lsdir2  dir3
[root@centos7 test]# lsdir1  dir2[root@centos7 test]# mv dir1 dir2[root@centos7 test]# tree dir2dir2└── dir11 directory, 0 files
[root@centos7 test]# lsfile1  file2[root@centos7 test]# mv file1 file2mv:是否覆盖"file2"? y[root@centos7 test]# lsfile2
[root@centos7 test]# touch file1[root@centos7 test]# lsdir2  dir3  file1[root@centos7 test]# mv file1 file2[root@centos7 test]# lsdir2  dir3  file2

文档信息查看命令

一次性打印出全部:cat | tac(倒序)

分屏显示:more | less

指定打印显示的行数: head | tail(倒序) -n num file

cat

显示文本内容[root@localhost ~]# cat test.txtabcde显示内容同时显示序号[root@localhost ~]# cat -n test.txt     1    a     2    b     3    c     4    d     5    e
[root@localhost ~]# cat > 1.txtthis is a test sentence # 这个是临时输入的,不是读取的,使用ctrl-d退出编辑后会保存内容至1.txt[root@localhost ~]# cat 1.txtthis is a test sentence

tac

倒序显示(没有-n参数,显示序号)[root@localhost ~]# tac test.txtedcba

more 将内容分屏显示,能向下(空格键)查看,向上看(ctrl + B),内容显示完自动跳出。

 

less

可以分屏显示,可以向上(J键或方向键的向下键)/下(K键或方向键的向上键)查看,使用q键跳出;

向后搜索查找的字符:/string ,使用n(向后)、N(向前);

使用 ?string,向前搜索,n(向前)、N(向后)。

快速跳转:gg(跳转到开头)、GG(跳转到末尾)

 

head(不加-n参数,默认显示前十行)

tail(不加-n参数,默认显示后十行)

tail -f file 查看动态变化的文件的后十行,常用于查看日志文件

 

补充说明

!$ 表示上一条命令的最后一个参数

转载于:https://my.oschina.net/u/3964535/blog/2051128

你可能感兴趣的文章
SQL语句集锦
查看>>
linux下进入root
查看>>
JDK动态代理(2)--------反射Method的作用
查看>>
VirtualBox CentOS安装增强功能与设置共享文件夹
查看>>
Unity3dBug - OnEnable
查看>>
selenium之鼠标的操作(python)
查看>>
Linux下原子性操作,类似Windows下的InterLockedXXX
查看>>
MyBatis学习-入门
查看>>
Integer to Roman
查看>>
[转]谷歌搜索技巧
查看>>
Android代码混淆------apk文件代码混淆
查看>>
操作系统课程设计 系统调用
查看>>
微信web页面返回刷新
查看>>
Win2008R2PHP5.4环境加载Zend模块
查看>>
Activity的四种加载模式
查看>>
我的异常集
查看>>
AngularJS购物车
查看>>
四则运算 第二次
查看>>
SVN同步
查看>>
python转移符的使用
查看>>