環境變量PATH, cp和mv命令,文檔查看

9月13日任務vim

2.10 環境變量PATHcentos

2.11 cp命令bash

2.12 mv命令less

2.13 文檔查看cat/more/less/head/tailthis

 

環境變量PATHcentos7

咱們運行命令時如ls命令,並非使用其絕對路徑形式/bin/ls,只使用相對路徑形式的ls命令就能夠執行,spa

這時由於/bin在環境變量PATH內,因此該目錄的ls二進制文件就能夠直接執行了。日誌

 

暫時新增目錄至PATH環境變量code

[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.new

1 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 cp
alias cp='cp -i'

移動/重命名命令 mv

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

 

  • mv的目標是目錄但不存在,源目錄會重命名爲目標目錄

  • mv的目標是目錄且存在,源文件或目錄會被移到該目標目錄下

  • mv的目標是文件且存在,詢問是否覆蓋

  • mv的目標是文件但不存在,重命名爲目標文件名

[root@centos7 test]# ls
dir1  dir2
[root@centos7 test]# mv dir1 dir3
[root@centos7 test]# ls
dir2  dir3
[root@centos7 test]# ls
dir1  dir2
[root@centos7 test]# mv dir1 dir2
[root@centos7 test]# tree dir2
dir2
└── dir1

1 directory, 0 files
[root@centos7 test]# ls
file1  file2
[root@centos7 test]# mv file1 file2
mv:是否覆蓋"file2"? y
[root@centos7 test]# ls
file2
[root@centos7 test]# touch file1
[root@centos7 test]# ls
dir2  dir3  file1
[root@centos7 test]# mv file1 file2
[root@centos7 test]# ls
dir2  dir3  file2

文檔信息查看命令

一次性打印出所有:cat | tac(倒序)

分屏顯示:more | less

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

cat

顯示文本內容
[root@localhost ~]# cat test.txt
a
b
c
d
e

顯示內容同時顯示序號
[root@localhost ~]# cat -n test.txt
     1    a
     2    b
     3    c
     4    d
     5    e
[root@localhost ~]# cat > 1.txt
this is a test sentence # 這個是臨時輸入的,不是讀取的,使用ctrl-d退出編輯後會保存內容至1.txt

[root@localhost ~]# cat 1.txt
this is a test sentence

tac

倒序顯示(沒有-n參數,顯示序號)
[root@localhost ~]# tac test.txt
e
d
c
b
a

more 將內容分屏顯示,能向下(空格鍵)查看,向上看(ctrl + B),內容顯示完自動跳出。

 

less

能夠分屏顯示,能夠向上(J鍵或方向鍵的向下鍵)/下(K鍵或方向鍵的向上鍵)查看,使用q鍵跳出;

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

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

快速跳轉:gg(跳轉到開頭)、GG(跳轉到末尾)

 

head(不加-n參數,默認顯示前十行)

tail(不加-n參數,默認顯示後十行)

tail -f file 查看動態變化的文件的後十行,經常使用於查看日誌文件

 

補充說明

!$ 表示上一條命令的最後一個參數

相關文章
相關標籤/搜索