linux中文件的經常使用操做

    cd:切換目錄

    語法:cd <文件目錄>
node

[root@localhost Desktop]#  cd /home/
[root@localhost home]#

    pwd:顯示當前目錄

[root@localhost home]# pwd
/home

  ls:查看當前目錄下的文件

[root@localhost home]# ls
manniu

  由於ls用的比較多,對應參數git

    -a :所有的檔案,連同隱藏檔( 開頭爲 . 的檔案) 一塊兒列出來~
    -A :所有的檔案,連同隱藏檔,但不包括 . 與 .. 這兩個目錄,一塊兒列出來~
    -d :僅列出目錄自己,而不是列出目錄內的檔案數據
    -f :直接列出結果,而不進行排序 (ls 預設會以檔名排序!)
    -F :根據檔案、目錄等信息,給予附加數據結構,例如:
     *:表明可執行檔; /:表明目錄; =:表明 socket 檔案; |:表明 FIFO 檔案;
    -h :將檔案容量以人類較易讀的方式(例如 GB, KB 等等)列出來;
    -i :列出 inode 位置,而非列出檔案屬性;
    -l :長數據串行出,包含檔案的屬性等等數據;
    -n :列出 UID 與 GID 而非使用者與羣組的名稱 (UID與GID會在帳號管理提到!)
    -r :將排序結果反向輸出,例如:本來檔名由小到大,反向則爲由大到小;
    -R :連同子目錄內容一塊兒列出來;
    -S :以檔案容量大小排序!
    -t :依時間排序
    --color=never :不要依據檔案特性給予顏色顯示;
    --color=always :顯示顏色
    --color=auto :讓系統自行依據設定來判斷是否給予顏色
    --full-time :以完整時間模式 (包含年、月、日、時、分) 輸出
    --time={atime,ctime} :輸出 access 時間或 改變權限屬性時間 (ctime)
redis

    mkdir: 創建新的文件目錄(參數-p創建多級目錄)

    mkdir<參數> <文件名>
shell

[root@localhost home]# mkdir test
[root@localhost home]# ls
manniu  test
[root@localhost home]# mkdir test1/one
mkdir: cannot create directory ‘test1/one’: No such file or directory
[root@localhost home]# mkdir -p test1/one
[root@localhost home]# ls
manniu  test  test1

    rmdir:刪除空目錄(參數-p連同上層空目錄一塊兒刪去)

    rmdir<參數> <文件名>數據結構

[root@localhost home]# rmdir  test1/one/
[root@localhost home]# ls
manniu  test1
[root@localhost home]# mkdir test1/two
[root@localhost home]# ls test1/
two
[root@localhost home]# rmdir -p test1/two/
[root@localhost home]# ls
manniu

    cp:複製文檔或目錄,<-r 複製目錄>

    cp <被複制文檔> <目標文檔>socket

[root@localhost home]# cp /software/redis-3.0.5.tar.gz /home/
[root@localhost home]# ls
manniu  redis-3.0.5.tar.gz

[root@localhost home]# cp -r /software/redis-3.0.5/ /home/
[root@localhost home]# ls
manniu  redis-3.0.5  redis-3.0.5.tar.gz
[root@localhost home]# cp  /software/redis-3.0.5/ /home/
cp: omitting directory ‘/software/redis-3.0.5/’

從其餘目錄下面複製文件過來,cp其實不少參數。用的時候再說吧,我通常用的最多的就是-r,其實就是相似於window裏面複製文件,複製文件夾。spa

    rm(移除文檔或目錄)

rm <參數> <文件或目錄>code

不加參數,刪除文件。-r目錄的刪除,-f強制刪除。(我常常用的~.~)
排序

[root@localhost home]# ls
manniu  redis-3.0.5  redis-3.0.5.tar.gz
[root@localhost home]# rm -r redis-3.0.5
rm: descend into directory ‘redis-3.0.5’? y
rm: remove regular file ‘redis-3.0.5/.gitignore’? ^Z
[2]+  Stopped           
[root@localhost home]# rm -rf redis-3.0.5
[root@localhost home]# ls
manniu  redis-3.0.5.tar.gz
[root@localhost home]# rm redis-3.0.5.tar.gz 
rm: remove regular file ‘redis-3.0.5.tar.gz’? y

    mv(移動文件或目錄)

    mv <參數> <被移動文件> <目標目錄>
rem

    參數:

    -f :force 強制的意思,強制直接移動而不詢問;

    -i :若目標檔案 (destination) 已經存在時,就會詢問是否覆蓋!

    -u :若目標檔案已經存在,且 source 比較新,纔會更新 (update)

[root@localhost home]# ls
manniu
[root@localhost home]# mkdir test
[root@localhost home]# mkdir test1
[root@localhost home]# ls
manniu  test  test1
[root@localhost home]# mv test test1/
[root@localhost home]# ls
manniu  test1
[root@localhost home]# ls test1/
test


文件的查找:

which<文件名><-a參數>

通常的which只找出一個結果,加上參數-a,同名的結果也會被列出來。

[root@localhost home]# which mongod 
/usr/bin/mongod
[root@localhost home]# which mongod -a
/usr/bin/mongod
/bin/mongod

whereis(尋找特定檔案)

whereis <參數> <文件名字>

-b :只找 binary 的檔案
-m :只找在說明文件 manual 路徑下的檔案
-s :只找 source 來源檔案
-u :沒有說明檔的檔案!

[root@localhost home]# whereis mongod
mongod: /usr/bin/mongod /etc/mongod.conf /usr/share/man/man1/mongod.1
[root@localhost home]# whereis -m mongod
mongod: /usr/share/man/man1/mongod.1

    find

find [PATH] [option] [action]

下面這個是根據文件的名字來進行尋找,由於find是直接操做硬盤的,我表示在虛擬機上慢的很。這僅僅是-name一個參數,由於我通常也就用這個,其餘還有不少參數。仍是用的時候再加上來

[root@localhost home]# find / -name mongod
find: ‘/run/user/1000/gvfs’: Permission denied
/run/lock/subsys/mongod
/etc/sysconfig/mongod
/etc/rc.d/init.d/mongod
/usr/bin/mongod
相關文章
相關標籤/搜索