## Get Ubuntu Version Infophp
lsb_release -a
html
## Get Linux kernal infolinux
uname -ac++
## Get Computer name程序員
echo $HOSTNAME web
## Define Environment Variableshell
### Defining Variables Globally ubuntu
Most Linux distributions tell you to change or add environment variable definitions in /etc/profile
or other locations. Be sure to maintain and manage the environment variables and pay attention to the numerous files that can contain environment variables. In principle, any shell script can be used for initializing environmental variables, but following traditional UNIX conventions, these statements should be only be present in some particular files. The following files should be used for defining global environment variables on your system: /etc/profile
, /etc/bash.bashrc
and /etc/environment
.centos
### Defining Variables Locally 安全
You do not always want to define an environment variable globally. For instance, you might want to add /home/my_user/bin
to the PATH variable but do not want all other users on your system to have that in their PATH
too. The following files should be used for local environment variables on your system: ~/.bashrc
, ~/.profile
, ~/.bash_login
and ~/.bash_logout
.
To add a directory to PATH
for local usage, put following in ~/.bashrc
:
PATH="${PATH}:/home/my_user/bin"
To update the variable, re-login or source the file: $ source ~/.bashrc
.
### Session Specific Variables
Sometimes even stricter definitions are required. One might want to temporarily run executables from a specific directory created without having to type the absolute path to each one, or editing ~/.bashrc
for the short time needed to run them.
In this case, you can define the PATH
variable in your current session, combined with the export
command. As long as you do not log out, the PATH
variable will be using the temporary settings. To add a session-specific directory to PATH
, issue:
$ export PATH="${PATH}:/home/my_user/tmp/usr/bin"
## Print all environment variables
printenv
## 關機命令 shutdown
好像ubuntu的終端中默認的是當前用戶的命令,只是普通用戶,所以在終端器中可使用sudo -sh 轉換到管理員root用戶下執行命令。
1)shutdown --help
能夠查看shutdown命令如何使用,固然也可使用man shutdown命令。
2) shutdown -h now 如今當即關機
3)shutdown -r now 如今當即重啓
4)shutdown -r +3 三分鐘後重啓
5)shutdown -h +3 "The System will shutdown after 3 minutes" 提示使用者將在三分鐘後關機
6)shutdown -r 20:23 在20:23時將重啓計算機
7)shutdown -r 20:23 & 能夠將在
## How to start GUI application
Add a "&" to the end of commandline
$ emacs &
$ p4v &
You can also "ctrl + z" to suspend current running process.
## 搜索文件
1.whereis 文件名
快速模糊查找.
2.find / -name 文件名
準確,但速度慢,消耗資源大
#find / -name php.ini
3.locate 文件名
強力推薦,最快,最好. To use locate in Mac, run "sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist"
Install locate:
ubuntu:sudo apt-get install locate;
centos:yum -y install mlocate;
第一次使用locate的時候,會有一個"mlocate.db:No such file or directoly"的錯誤,須要update db。
[root@ip-10-199-99-196 src]# locate .emacs
locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory
[root@ip-10-199-99-196 src]# updatedb
[root@ip-10-199-99-196 src]# locate .emacs
/etc/rpm/macros.emacs
/etc/skel/.emacs
/root/.emacs.d
/root/.emacs.d/auto-save-list
/root/.emacs.d/auto-save-list/.saves-11160-ip-10-199-99-196.ec2.internal~
/root/.emacs.d/auto-save-list/.saves-5002-ip-10-199-99-196.ec2.internal~
/root/.emacs.d/auto-save-list/.saves-5181-ip-10-199-99-196.ec2.internal~
/root/.emacs.d/auto-save-list/.saves-5215-ip-10-199-99-196.ec2.internal~
/usr/bin/etags.emacs
/usr/share/man/man1/etags.emacs.1.gz
## 查看磁盤剩餘空間和文件夾大小
df -hl 查看磁盤剩餘空間
df -h 查看每一個根路徑的分區大小
du -sh [目錄名] 返回該目錄的大小
du -sm [文件夾] 返回該文件夾總M數
Example:
[root@ip-12-345-678-910 users]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 7.9G 3.0G 4.9G 39% /
tmpfs 831M 0 831M 0% /dev/shm
Help:
df --help
du --help
## 用ps查看進程
ps命令能夠用來查看當前的進程。
ps a 顯示現行終端機下的全部程序,包括其餘用戶的程序。
ps -A 顯示全部程序。
ps c 列出程序時,顯示每一個程序真正的指令名稱,而不包含路徑,參數或常駐服務的標示。
ps -e 此參數的效果和指定"A"參數相同。
ps e 列出程序時,顯示每一個程序所使用的環境變量。
ps f 用ASCII字符顯示樹狀結構,表達程序間的相互關係。
ps -H 顯示樹狀結構,表示程序間的相互關係。
ps -N 顯示全部的程序,除了執行ps指令終端機下的程序以外。
ps s 採用程序信號的格式顯示程序情況。
ps S 列出程序時,包括已中斷的子程序資料。
ps -t<終端機編號> 指定終端機編號,並列出屬於該終端機的程序的情況。
ps u 以用戶爲主的格式來顯示程序情況。
ps x 顯示全部程序,不以終端機來區分。
常有人用ps aux | grep program_filter_word來利用grep過濾process。
## 用top來查看進程
top命令用來動態顯示系統當前的進程情況,與ps的主要區別也正在於這動態二字.
Options:
-b:使用批處理模式。
-c:顯示程序並顯示程序的完整相關信息,如名稱、路徑等。
-i:忽略閒置或已經凍結的程序。
-d<delay>:以秒爲單位,設定監控程序執行情況的時間間隔。
-n<iterations>:設定監控信息的更新次數。
-p<進程號>:指定進程。
-s:安全模式。
-u<somebody>:指定用戶名。
-v:顯示版本信息。
-h:顯示幫助信息。

## 用pstree來顯示進程樹
pstree命令列出當前的進程,以及它們的樹狀結構。
## kill來殺死進程
kill [ -s signal | -p ] [ -a ] pid ...
kill -l [ signal ]
參數
-s:指定發送的信號。
-p:模擬發送信號。
-l:指定信號的名稱列表。
pid:要停止進程的ID號。
Signal:表示信號。
信號量9殺死Zombie Process並清理內存
kill -9 pid
free
## 查看可執行程序和動態連接庫因此來的動態連接庫
在Windows下,咱們可使用Dependency Walker來查看依賴,在Linux下,咱們能夠簡單使用ldd來達到一樣的目的.
[root@ip-12-345-678-910 users]# ldd ./test
linux-vdso.so.1 => (0x00007fff491ff000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f9b10b84000)
libm.so.6 => /lib64/libm.so.6 (0x00007f9b10900000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f9b106eb000)
libc.so.6 => /lib64/libc.so.6 (0x00007f9b1035c000)
/lib64/ld-linux-x86-64.so.2 (0x00007f9b10e8b000)
可是,咱們要注意可能存在安全問題:
ldd工具可能比你想象的更容易被攻擊。程序員和系統管理員常常使用ldd工具在Linux和UNIX操做系統內列出可執行文件所依賴的共享庫。可是一位黑客用事例證實,在一個可執行文件中運行ldd,可能會致使其執行任意代碼。一位用戶指出,這個問題很早被發現了,「Program Library HOWTO」就警告:不要在本身不信任的程序內運行ldd,ldd是經過設置特殊的環境變量工做和運行程序的,一個可疑的程序可能會迫使ldd用戶執行任意的代碼,而不是列出共享庫。
固然,除了ldd,咱們也可使用elflibviewer或binscan:
binscan: http://sourceforge.net/projects/binscan/

elflibviewer:http://www.purinchu.net/software/elflibviewer.php

## 顯示動態連接庫的導出的符號
這個功能在Windows下的Dependency walker也有,在Linux下,它是nm。
[root@ip-12-345-678-910 users]# nm ./test
0000000000600ad8 d _DYNAMIC
0000000000600cc0 d _GLOBAL_OFFSET_TABLE_
0000000000400863 t _GLOBAL__sub_I_main
...
0000000000400968 R _IO_stdin_used
00000000004007c0 t frame_dummy
00000000004007e4 T main
## 壓縮與解壓
———————————————
.tar/.tar.gz/tar.bz
必須的參數:(3個參數不能共存)
-c :建立壓縮文件c表明create。
-x :解壓縮文件
-t :查看壓縮包裏面的文件!
輔助參數:
-z :用 gzip 壓縮/解壓縮
-j :用 bzip2 壓縮/解壓縮
-v :顯示壓縮/解壓縮的進度條
-f :使用檔名(注意:f後面不要接參數,也就是說-zxfv是不對的,要寫成-zxvf)
實例:
解壓一個文件:tar -zxvf abc.tar.bz2
(解壓縮abc.tar.bz2)
建立壓縮文件:tar -zcvf abc.tar.bz2 one.mp3 two.mp3
(把one.mp3和two.mp3壓縮成abc.tar.bz2)
———————————————
———————————————
.7z
安裝:Redhat、Fedora、Centos安裝命令:yum install p7zip
安裝:Debian、Ubuntu安裝命令:apt-get install p7zip
解壓實例:
7z x filename.7z
———————————————
———————————————
.zip
zip參數列表:
-a 將文件轉成ASCII模式
-F 嘗試修復損壞的壓縮文件
-h 顯示幫助界面
-m 將文件壓縮以後,刪除源文件
-n 特定字符串 不壓縮具備特定字尾字符串的文件
-o 將壓縮文件內的全部文件的最新變更時間設爲壓縮時候的時間
-q 安靜模式,在壓縮的時候不顯示指令的執行過程
-r 將指定的目錄下的全部子目錄以及文件一塊兒處理
-S 包含系統文件和隱含文件(S是大寫)
-t 日期 把壓縮文件的最後修改日期設爲指定的日期,日期格式爲mmddyyyy
unzip參數列表:
-l 列出壓縮文件所包含的內容
-v 顯示詳細的執行過程
解壓:unzip FileName.zip
壓縮:zip -r FileName.zip DirName
———————————————
## Find all file descripters
列出打開FileDescripter數目: ls -l | wc -l
http://www.cyberciti.biz/tips/linux-procfs-file-descriptors.html