Linux 常用命令大全【收藏】
這一次收集的是比較基礎的 Linux 命令,其實 Linux 命令未必每個都要記住,只要在用到時能查閱到需要的命令的用法。
系統資訊
arch 顯示機器的處理器架構(1)
uname -m 顯示機器的處理器架構(2)
uname -r 顯示正在使用的核心版本
dmidecode -q 顯示硬體系統部件 – (SMBIOS / DMI)
hdparm -i /dev/hda 羅列一個磁碟的架構特性
hdparm -tT /dev/sda 在磁碟上執行測試性讀取操作
cat /proc/cpuinfo 顯示CPU info的資訊
cat /proc/interrupts 顯示中斷
cat /proc/meminfo 校驗記憶體使用
cat /proc/swaps 顯示哪些swap被使用
cat /proc/version 顯示核心的版本
cat /proc/net/dev 顯示網路介面卡及統計
cat /proc/mounts 顯示已載入的檔案系統
lspci -tv 羅列 PCI 裝置
lsusb -tv 顯示 USB 裝置
date 顯示系統日期
cal 2007 顯示2007年的日曆表
date 041217002007.00 設定日期和時間 – 月日時分年.秒
clock -w 將時間修改儲存到 BIOS
關機 (系統的關機、重啟以及登出 )
shutdown -h now 關閉系統(1)
init 0 關閉系統(2)
telinit 0 關閉系統(3)
shutdown -h hours:minutes & 按預定時間關閉系統
shutdown -c 取消按預定時間關閉系統
shutdown -r now 重啟(1)
reboot 重啟(2)
logout 登出
檔案和目錄
cd /home 進入 ‘/ home’ 目錄’
cd .. 返回上一級目錄
cd ../.. 返回上兩級目錄
cd 進入個人的主目錄
cd ~user1 進入個人的主目錄
cd – 返回上次所在的目錄
pwd 顯示工作路徑
ls 檢視目錄中的檔案
ls -F 檢視目錄中的檔案
ls -l 顯示檔案和目錄的詳細資料
ls -a 顯示隱藏檔案
ls *[0-9]* 顯示包含數字的檔名和目錄名
tree 顯示檔案和目錄由根目錄開始的樹形結構(1)
lstree 顯示檔案和目錄由根目錄開始的樹形結構(2)
mkdir dir1 建立一個叫做 ‘dir1′ 的目錄’
mkdir dir1 dir2 同時建立兩個目錄
mkdir -p /tmp/dir1/dir2 建立一個目錄樹
rm -f file1 刪除一個叫做 ‘file1′ 的檔案’
rmdir dir1 刪除一個叫做 ‘dir1′ 的目錄’
rm -rf dir1 刪除一個叫做 ‘dir1′ 的目錄並同時刪除其內容
rm -rf dir1 dir2 同時刪除兩個目錄及它們的內容
mv dir1 new_dir 重新命名/移動 一個目錄
cp file1 file2 複製一個檔案
cp dir/* . 複製一個目錄下的所有檔案到當前工作目錄
cp -a /tmp/dir1 . 複製一個目錄到當前工作目錄
cp -a dir1 dir2 複製一個目錄
ln -s file1 lnk1 建立一個指向檔案或目錄的軟連結
ln file1 lnk1 建立一個指向檔案或目錄的物理連結
touch -t 0712250000 file1 修改一個檔案或目錄的時間戳 – (YYMMDDhhmm)
file file1 outputs the mime type of the file as text
iconv -l 列出已知的編碼
iconv -f fromEncoding -t toEncoding inputFile > outputFile creates a new from the given input file by assuming it is encoded in fromEncoding and converting it to toEncoding.
find . -maxdepth 1 -name *.jpg -print -exec convert “{}” -resize 80×60 “thumbs/{}” ; batch resize files in the current directory and send them to a thumbnails directory (requires convert from Imagemagick)