1.檔案操作
- touch命令
- 創建檔案,如果檔案名稱不存在,那么直接創建;如果存在,那么更改訪問時間
- touch [option] filename1 filename2...
root@ubuntu:~/Test# touch hello.c
root@ubuntu:~/Test# ls
hello.c
-
rm命令:洗掉檔案或者目錄
- 引數 -r 遞回洗掉子目錄
- rm -rf * 洗掉當前目錄內全部內容(強制洗掉,謹慎使用)
-
cp和mv命令,相當于Windows平臺復制和剪切
- cp [option] srcpath despath
- despath是一個目錄,將srcpath拷貝到despath目錄下
- despath不是一個目錄,在despath上級目錄(.../xxx),在.../下創建一個xxx檔案,并將srcpath的內容拷貝進來
-
cat命令
- cat filename:直接顯示檔案資訊到螢屏
-
more和less,分螢屏顯示檔案資訊
-
more:
- 回車逐行顯示
- 空格,一頁一頁的顯示
-
less:
- 回車或者上下方向鍵可以反復查看檔案內容
-
-
head和tail命令
- head 查看檔案頭,默認顯示10行內容
- head -n 可以指定的行數
- tail查看檔案尾,默認顯示10行內容
- -n 可以指定函式
- -f 可以跟蹤檔案末尾
- head 查看檔案頭,默認顯示10行內容
2.統計資訊相關
- wc命令:英文單詞為word cout,也就是統計檔案內容
- -l 顯示行
- -w 單詞
- -c 位元組數
root@ubuntu:~/Test# wc hello.c
8 10 91 hello.c
root@ubuntu:~/Test# wc -l hello.c
8 hello.c
root@ubuntu:~/Test# wc -w hello.c
10 hello.c
root@ubuntu:~/Test# wc -c hello.c
91 hello.c
- df 顯示磁盤空間資訊
root@ubuntu:~# df -h
檔案系統 容量 已用 可用 已用% 掛載點
udev 973M 0 973M 0% /dev
tmpfs 199M 9.0M 190M 5% /run
/dev/sda1 21G 9.2G 11G 48% /
tmpfs 992M 256K 992M 1% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 992M 0 992M 0% /sys/fs/cgroup
tmpfs 199M 60K 199M 1% /run/user/1000
3.檔案權限和用戶屬性
- 解釋相應的欄位
root@ubuntu:~/Test# ls -l
總用量 4
-rw-r--r-- 1 root root 91 10月 27 14:16 hello.c
-
-表示檔案型別,d代表目錄檔案
-
rw- 歸屬用戶的權限,該用戶具有可讀可寫的權限
-
r-- 歸屬組的權限,該組僅有可讀權限
-
r-- 其他用戶權限,也是只具有可讀權限
-
我們還可以用8進制的數字來表示權限位
- rw- --->110--->6 用戶位
- r-- --->100--->4 組權限位
- r-- --->100--->4 其他權限位
- 最后將他們組合就是起來0664
-
哦,對了,后面還有一個1,那個1代表硬鏈接的計數,下面會有命令來進行演示
-
創建硬鏈接-ln src des
root@ubuntu:~/Test# ln hello.c hello.c.hard
root@ubuntu:~/Test# ls
hello.c hello.c.hard
root@ubuntu:~/Test# ln hello.c hello.c.hard1
root@ubuntu:~/Test# ls -l
總用量 12
-rw-r--r-- 3 root root 91 10月 27 14:16 hello.c
-rw-r--r-- 3 root root 91 10月 27 14:16 hello.c.hard
-rw-r--r-- 3 root root 91 10月 27 14:16 hello.c.hard1
此時的硬鏈接計數變成了3,當我們的硬鏈接的計數變為0的時候,那么檔案也會被洗掉
- 創建軟鏈接:ln -s 檔案或者目錄
root@ubuntu:~/Test# ln -s hello.c hello.c.soft
root@ubuntu:~/Test# ls -l
總用量 12
-rw-r--r-- 3 root root 91 10月 27 14:16 hello.c
-rw-r--r-- 3 root root 91 10月 27 14:16 hello.c.hard
-rw-r--r-- 3 root root 91 10月 27 14:16 hello.c.hard1
lrwxrwxrwx 1 root root 7 10月 27 14:43 hello.c.soft -> hello.c
- 洗掉軟硬鏈接:unlink
4.改變檔案權限
-
chmod命令
- chmod [u|g|o|a] [+|-][r|w|x] filename
- 用數字的方式改變檔案權限 例如:chmod 0664 main.c
-
chown和chgrp改變用戶和改變組
- 如果當前不是root用戶,需要用管理員修改檔案歸屬
- chown 用戶:組 檔案名|目錄
- chgrp 組 檔案名|目錄
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/44940.html
標籤:Linux
