1. 基本命令(注意參數的大小寫)
學習linux如果使用的是windows 建議使用一個很好用的工具git,下載安裝即可使用linux下的命令來操作windows
1.1目錄及文件
注意/ 有表示根目錄 無表示當前目錄
1. pwd
pwd #顯示當前工作目錄的名稱
pwd -P #顯示連接的真是路徑
2. cd
cd /usr/src #切換到/usr/src下面的目錄
cd .. #返回上級目錄
cd - #返回上個目錄
cd ~ #返回用戶的工作空前目錄
3. ls
ls #顯示目錄和文件信息
ls -a #顯示所有的信息
ls -d #顯示目錄本身的信息
ls -h #人性化顯示容量信息
ls -c #顯示文件或目錄屬性最後修改的時間
ls -u #顯示文件或目錄最後被訪問的時間
ls -t #以修改時間排序,默認按照文件名排序
4. touch
touch hello.txt #創建或者修改文件,存在修改,不存在則創建
5. mkdir
mkdir test #創建test目錄
mkdir -p test/test/test #創建多級目錄
6. cp
cp /test/hello.txt /temp/ #將hello.txt文件複製到temp目錄下
cp /test/hello.txt /temp/hi.txt #將文件複製到目錄下並改名字爲hi.txt
7.rm
rm hello.txt #刪除hello.txt文件
rm -rf test #強制刪除目錄且不提示
8. mv
mv hello.txt hi.txt #將hello.txt修改名字爲hi.txt
mv hello.txt /test/ #將hello.txt移動至test目錄下
9. find
find -name hello.txt #查找當前目錄下名爲hello.txt的文件
find /root -name "*.log" #查找/root目錄下所有以.log結尾的文件
find iname "hello" #不區分大小寫查找
find / -empty #查找所有的空文檔
find / -group tom #查找所屬組爲tom的文件
find /-mtime -3 #查找三天內被修改過的檔案
find /-mtime +4 #查找計算機中所有4天前被修改的文檔
find /mtime 2 #查找計算兩天前的當天被修改的文檔
find / -size+10M #查找當前目錄下大於10M的文檔
find ./ -type f #查找當前目錄所有的普通文件
find / -user tom # 查找計算機中tom所擁有的文檔
10. du
du -sh /test #查看test所佔的磁盤空間的綜合
1.2 查看文件內容
1. cat
cat -b hello.txt #顯示hello.txt的內容並顯示行號(空白行不顯示行號)
cat -h hello.txt #顯示內容和行號,空白行顯示行號
cat hello.txt #顯示文件內容
2. more
more hello.txt #分頁查看文件內容(空格 下一頁,q鍵退出)
3. less
less hello.txt #分頁查看文件內容(空格 下一頁,方向鍵 上下回翻,q鍵 退出)
4. head
head -c 2K hello.txt #顯示文件前2K的內容
head -n20 hello.txt #顯示前20行的內容
5. tail
tail -c 2k hello.txt #顯示文件後2K的內容
tail -n20 hello.txt #顯示文件後20行的內容
tail -n20 hello.txt -f #實時動態的顯示hello.txt 後20行的內容
6. wc
wc hello.txt #依次顯示文件的行數,單詞書,字節數
wc -c hello.txt #顯示文件的字節信息
wc -l hello.txt #顯示文件的行數
wc -w hello.txt #顯示文件的單詞個數
7. grep
grep th hello.txt #在test.txt文件中過濾包含th的行
grep --color th hello.txt #對匹配的關鍵字顯示顏色
grep -i th hello.txt #不匹配大小寫
grep -w th hello.txt #過濾單詞,單詞爲th的
grep -v th hello.txt #取反,過濾不好喊th的行
8. echo
echo "test" #顯示test文本
echo -e "\a" #計算機蜂鳴器響
1.3 鏈接文件
有時間可以百度看看軟連接和硬鏈接的區別
1. 軟連接(相當於快捷方式)
ln -s /test/hello.txt /tmp/hi.txt
2. 硬鏈接(可刪除源文件)
ln /test/hello.txt /tem/hi.txt
1.4 壓縮及解壓縮
1. gzip
gzip hello.txt #壓縮文件,文件壓縮後名字爲hello.txt.gz
gzip -d hello.txt.gz #解壓gz文件
2. bzip2
bzip2 hello.txt #壓縮文件,文件壓縮後名字爲 hello.txt.bz2
bzip2 -d hello.txt.bz2 #解壓bz2文件
3. tar
tar -cf etc.tar /etc/ #將etc目錄打包保存謂etc.tar
tar -xzf etc.rar #解壓 etc.rar文件
1.5 命令行使用技巧
1. 善於使用tab鍵
2. 善於使用上下鍵
3. 查看名兩行歷史
4. 清屏
ctrl+l
clear
5. 查找常用命令存儲位置
which find #查詢find命令的存儲位置
1.6 幫助
1. man
man ls #查ls命令手冊
2. info
info ls #查看ls命令信息
3.help
ls --help #查看ls幫助