Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux 伺服器

Linux 必會命令精選:涵蓋你 95% 日常操作

以下整理的是實際工作中有在用到的 Linux 指令,也可以視為新手必知必會的清單,大致涵蓋了日常會用到的九成五以上。

一、MySQL 常用操作

登入登出:mysql -uroot -p123456;從檔案匯入:mysql <./HostCache.sql -uroot -p123456;show databases;、use HostCache;、show tables;、desc HostCache;、exit;

資料操作:alter table voucherwinner modify cpuid varchar(36);、alter table installerreport add skypeid varchar(32);、update operator set agentid='00000124' where username='00000124';、select * from HostCache order by TimeStamp;、delete from HostCache where ISPType = 4;

匯出匯入:mysqldump -h172.24.172.47 -uskypeuser -ptomskype47 skypeuser voucherwinner > voucherwinner 會把建表與插入語句以腳本形式存成檔案;要帶條件可用 --w "time >= '...' and time <= '...'";匯入則是 mysql -uroot -p skypeuser <voucherwinner;

權限分配:grant all on *.* to username@IP identified by 'password';。預設最大連線數為 100,存放在 my.ini 這類設定檔中,找到對應值修改即可。

二、日常操作

tail -f 2005-10-28.log 即時追蹤仍被寫入的日誌;ps -A 列出行程;ps -ef | grep natserver 查特定行程;killall -9 p2pserver、kill -9 6499 結束行程;df 看磁碟使用率。

定時任務用 crontab -e 編輯、crontab -l 檢視。例如每天 9:16 執行一次:16 9 * * * echo "hello" > /root/hello.txt

時間設定:date、date -s 'Sat Apr 21 09:55:11 CST 2007'。遠端登入:ssh 61.135.234.140、exit。

三、環境變數

locale 檢視在地化設定、export LANG=zh_CN 設定、uname -a 看系統與 CPU、top 看資源佔用、env 列出所有變數。全域設定檔是 /etc/profile,個人設定則可寫入 ~/.bashrc,例如 export LD_LIBRARY_PATH=/data/TOMSKYPEIVR/cpprad/lib。

四、C/C++ 編譯與除錯

make 編譯、chmod a+x tcastchanroot 給執行權、./runnewtcast.sh & 背景執行、nohup ./tcastchanroot > runlog 不掛起執行。

gdb:gdb ./reportserver 啟動、b main 設斷點、b 100 於第 100 行設斷點、d 刪除、s 單步進入、n 下一行、c 續行至下一斷點、where 看呼叫堆疊。搭配 ulimit -c unlimited 產生 core 檔後,用 gdb tcastchanroot core.6200 事後分析。

五、文字處理

grep MyKeyword statistics.log | wc 計數;awk '{print $3}' | sort -u | wc 統計不重複欄位值;cat a.txt > b.txt 覆寫、>> 追加;find -name Main.cpp 搜檔名。

vi 基本操作:i 進入插入模式、ESC 回命令模式、yy 複製一行、p 貼上、dd 刪除一行、/xx 搜尋、n 下一個、:wq 存檔離開;全域置換::g/installerreport/s/installerreport/installerreport20070503/g

六、檔案系統

touch 建空檔、mkdir 建目錄、mv 移動或改名(Linux 沒有 rename 指令)、cp -a 連整個目錄一起複製、rm -rf 強制刪除、split -l 10000 依行數切檔。

ln -s 源檔 目標檔 建立軟連結,多個目錄共用同一份檔案時不必重複佔用磁碟;不加 -s 則是硬連結。用 ls -l 可看到連結指向的路徑。

下載用 wget;跨機傳檔用 scp *.so web@211.99.190.120:/data/...

七、壓縮解壓

tar zxvf x.tar.gz(gz)、tar jxvf x.tar.bz2(bz2)、tar zcvf KingSoftUnion.tar.gz KingSoftUnion/ 打包;zip 用 unzip,rar 用 unrar x。

八、背景執行

在指令後加 & 可讓 shell 立刻釋放出來,但父進程仍是這個 shell,登出後會被一起結束,離開前請用 jobs 確認。若要跨登出存活,用 nohup tar -cf /dev/tape /home &,nohup 必須與 & 搭配使用。能自行處理 SIGHUP 的程式(如 wget)則不需要 nohup。

九、通用安裝三步驟

找到並下載原始碼包,解壓,然後 ./configure --prefix=/data/TOMSKYPEIVR/bin、make、make install。

Copyright © Linux教程網 All Rights Reserved