copy 拷貝文件html
拷貝過程不指定目標文件名 則目標文件名和源文件名同樣node
[root@WebServer ~]# cp /91xueit/teacher.txt 51cto/
拷貝過程指定目標文件名稱linux
[root@WebServer ~]# cp /91xueit/teacher.txt 51cto/teacher1.txt [root@WebServer ~]# cp 51cto/teacher.txt 51cto/teacher1.txt /tmp
將51cto文件夾中擴展名是txt的文件拷貝到當前目錄windows
[root@WebServer ~]# cp 51cto/*.txt .
將51cto文件夾拷貝到/tmp文件夾,-R 或 -r 遞歸複製目錄及其子目錄的全部內容bash
[root@WebServer ~]# cp -R 51cto/ /tmp
默認狀況下,拷貝文件時文件權限會變化。只有管理員可以將文件拷貝 權限不變,使用-pide
[root@51cto ~]# cp /home/wangyan/wangyan.txt ./ [root@51cto ~]# ll total 20 -rw-------. 1 root root 1041 May 25 05:25 anaconda-ks.cfg -rw-r--r--. 1 root root 9714 May 25 05:25 install.log -rw-r--r--. 1 root root 3161 May 25 05:25 install.log.syslog -rw-r--r--. 1 root root 0 May 30 03:34 wangyan.txt [root@51cto ~]# cp /home/wangyan/wangyan.txt ./ -p cp: overwrite `./wangyan.txt'? y [root@51cto ~]# ll total 20 -rw-------. 1 root root 1041 May 25 05:25 anaconda-ks.cfg -rw-r--r--. 1 root root 9714 May 25 05:25 install.log -rw-r--r--. 1 root root 3161 May 25 05:25 install.log.syslog -rw-rw-r--. 1 wangyan wangyan 0 May 30 03:33 wangyan.txt
-d 保留文件的軟連接屬性ui
-a 保留全部屬性this
你們知道linux下複製目錄能夠經過,cp -r dirname destdir,可是這樣複製的目錄屬性會發生變化,想要使得複製以後的目錄和原目錄徹底同樣,可使用cp -a dirname destdir spa
-p:(小P)複製時保留mode、ownership、timestamps3d
-i : 覆蓋時提示
-n 不覆蓋已存在文件
-f:覆蓋已經存在的目標文件而不給出提示
-u:只有源文件較目標文件新時複製
命令格式爲:cp -u 源文件 目標文件
這個命令很實用,尤爲是在更新文件時。以下圖所示,只有源文件比目標文件新時,纔會將源文件複製給目標文件,不然,及時執行了命令,也不會執行復制。
-s :建立文件的軟連接
命令格式爲:cp -s 源文件 目標文件
也能夠用ln命令實現一樣的功能。當一個文件路徑太深(以下述的a/b/c/d/e/orginalFile.txt),訪問起來十分不方便時,就會建立這個文件的軟連接,使之訪問起來更方便些。軟連接就至關於windows上的快捷方式。
-l:建立文件的硬連接
remove 刪除
刪除單個文件
[root@WebServer ~]# rm 51cto/teacher.txt
-r 遞歸刪除51cto目錄中的文件和文件夾,51cto目錄不刪
[root@WebServer ~]# rm -r 51cto/*
刪除51cto目錄
[root@WebServer ~]# rm -r 51cto
以上刪除,會有提示,由於alias裏面rm時rm -i的別名。-f 強制刪除 沒有提示
[root@WebServer ~]# rm -f /tmp/123
-i:刪除前逐一詢問確認。一般Linux對rm進行了從命名,默認就把-i加上了
[root@localhost ~]# alias rm alias rm='rm -i'
move 移動文件 或 文件夾
http://www.javashuo.com/article/p-fcvbmgvw-bg.html
-b:當文件存在時,覆蓋前,爲其建立一個備份。備份文件以~結尾
[root@localhost Document]# cat >myword <<EOF > this is my word! > EOF [root@localhost Document]# cat >text <<EOF > this is my text! > EOF [root@localhost Document]# mv -b myword text //在一個文件即將覆蓋另外一個文件時,默認是提醒的,因此加上-i參數和不加是同樣的 mv:是否覆蓋"text"? y [root@localhost Document]# cat myword cat: myword: 沒有那個文件或目錄 [root@localhost Document]# cat text this is my word! [root@localhost Document]# ll 總用量 8 drwxr-xr-x. 2 root root 23 5月 5 22:35 mytext //這裏text裏存的是前面myword的內容,text的內容備份到text~中,須要特殊軟件才能查看 -rw-r--r--. 1 root root 17 5月 5 22:41 text -rw-rw-r--. 1 sunjimeng sunjimeng 17 5月 5 22:41 text~
-i:交互式操做,覆蓋前先行詢問用戶,若是源文件與目標文件或目標目錄中的文件同名,則詢問用戶是否覆蓋目標文件。這樣能夠避免誤將文件覆蓋。默認是以alias別名的方式帶-i參數
[root@localhost ~]# alias mv alias mv='mv -i'
-n 不覆蓋已存在文件
-f:強制的意思,若是目標文件已經存在,不會詢問而直接覆蓋
-u:若目標文件已存在需移動的同名文件,且源文件比較新,纔會更新文件
-t : 移動多個源文件到一個目錄的狀況,此時target在前,source在後。
mv dir/ anaconda-ks.cfg
-v:verbose
可以改變文件的時間戳,touch文件一下,文件的3個時間都會改變。
最近一次訪問時間
最近一次修改時間 改變文件的內容。 內容變化——>文件大小變化——>元數據變化
最近一次改變時間 元數據的改變 eg:文件名 大小 權限
單獨更改access時間,-a,change時間也會跟着變
單獨更改modify時間,-m,change時間也會跟着變
所以,也就沒有參數單獨修改change時間。
使用指定時間,而非當前時間更改modify時間。-t 或者 -d
[root@51cto ~]# touch -m -t 199312312359.59 wangyan.txt [root@51cto ~]# stat wangyan.txt File: `wangyan.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 802h/2050d Inode: 783368 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 500/ wangyan) Gid: ( 500/ wangyan) Access: 2018-05-30 03:34:36.776992594 +0800 Modify: 1993-12-31 23:59:59.000000000 +0800 Change: 2018-05-30 04:07:58.569981915 +0800
touch file時file不存在默認建立,file存在則修改3個時間。使用-c能夠取消這種默認行爲,即文件不存在也不建立
查看文件類型
http://www.javashuo.com/article/p-rllqhuyq-bc.html
一般file能夠告訴咱們目標文件是ELF文件仍是腳本文件(得知是腳本文件是經過腳本內部#!後面的信息判斷的)
-b:列出文件辨識結果時,不顯示文件名稱。
[root@localhost ~]# file /usr/bin/sh /usr/bin/sh: symbolic link to `bash' [root@localhost ~]# file /usr/bin/sh -b symbolic link to `bash'
-f :列出文件中文件名的文件類型
[root@localhost ~]# cat haha.txt /usr/bin/cp /usr/bin/gzip [root@localhost ~]# file -f haha.txt /usr/bin/cp: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=47c2259e084c64fb00ec01bda8a57c005e3516d5, stripped /usr/bin/gzip: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=526d77ff7164870f948d8f97aaf0a888cc561b30, stripped
-L:查看對應軟連接指向文件的文件類型
[root@localhost ~]# ll /usr/bin/sh lrwxrwxrwx. 1 root root 4 Oct 5 17:14 /usr/bin/sh -> bash [root@localhost ~]# file /usr/bin/sh /usr/bin/sh: symbolic link to `bash' [root@localhost ~]# file /usr/bin/sh -L /usr/bin/sh: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=765c505bb8a234fcd64ede405fa7fcb25734f06a, stripped
-z:嘗試去解讀壓縮文件的內容
--help:顯示命令在線幫助
-version:顯示命令版本信息
[root@51cto ~]# file /etc/passwd /etc/passwd: ASCII text [root@51cto ~]# file /bin/cat /bin/cat: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
功能和ls同樣,知道就行,沒啥人用