linux

ls889 13年前發布 | 3K 次閱讀 ER
時記錄的一些比較常用且重要的linux命令,特貢獻給大家共享。
轉載請注明出處:http://hi.baidu.com/luxiaoyi/creat/blog/
1 : service vsftpd start
2 : ps -ax
3 : ps -Af|grep java
4 : ftp 10.61.0.157 -> entering passive mode
    ftp> ls -> no route to host
    deal with this case : under 'ftp>' marks, you put 'passive' , then it will
    display like this : Passive mode off.
    then input 'ls', that's ok!
5 : how to copy files from remote sites?
    resolvent : scp vs@10.61.0.217:/opt/HPCG-1107/GOSRTestlib/conf/* ./conf/
        and scp ./conf/ vs@10.61.0.217:/opt/HPCG-1107/GOSRTestlib/conf/*
6 : how to caculate total files num under a dir or total dirs ?
    resolvent :
    file:
    find /path -type f|wc -l
    dir:
    find /path -type d|wc -l
    or there is a good method to count. find -maxdepth 1|wc -l
    '-maxdepth 1' indicates find current dir.
    'wc -l' indicates count lines.
7 : how to add a new user into linux?
    ************Create new user*************************
    adduser penghan
    #Changing password for user penghan
    passwd penghan
   
    New password: //input password
    Retype new password: //input again
    # Updated successfully //Over
8 : what is mount?
    將 /dev/hda1 掛在 /mnt 之下。
    #mount /dev/hda1 /mnt
    將 /dev/hda1 用唯讀模式掛在 /mnt 之下。
    #mount -o ro /dev/hda1 /mnt
    將 /tmp/image.iso 這個光碟的 image 檔使用 loop 模式掛在 /mnt/cdrom之下。用這種方法可以將一般網絡上可以找到的 Linux 光     碟ISO 檔在不燒錄成光碟的情況下檢視其內容。
    #mount -o loop /tmp/image.iso /mnt/cdrom
    相關命令umount
9 : how to mount your windows filesystem into linux?
    把Win下的硬盤分區Mount進Linux去就行了(如果你的分區格式是Fat32,則)
    C盤 #mkdir /mnt/c
         #mount -t vfat /dev/hda1 /mnt/c
    D盤 #mkdir /mnt/d
        #mount -t vfat /dev/hda4 /mnt/d
    E盤 #mkdir /mnt/e
        #mount -t vfat /dev/hda5 /mnt/e
    if your hard disk's file system is ntfs format, you must install another module, but it's also only support read only mode.
10 : when you tar file success in one computer, but failed in another one, and you are sure they are the same file. In this case, it may be the disk free space is not enough. So you can input 'df -h' command to check it.
11 : chmod ugo+w xxx --to add write priviledge for user,group and owner
    or chmod ugo+x xxx --to add execute priviledge for the three roles.
12 : when you write a file in windows, you must run 'dos2unix xxx' to modify some differences when you take it to linux system. For example, the difference of 'enter'.
13 : In redhat enterprise4, its mysql server service is called 'mysqld', so you must input 'service mysqld start', then the mysql service is start.
14 : If you want to change a file's owner and group, you can input like this 'chown vs.ftp xxx' xxx: filename vs: owner name ftp : group name
15 : 要修改所有用戶的PATH值,您可以以root身份編輯/etc/profile文件,修改其中包含“PATH=”的一行。只有在用戶重新注冊后,PATH的新值才會生效。如果只是要修改某一個用戶的PATH值,就應該編輯該用戶主目錄中的.bash-profile文件。
16 : export LANG=en_US : this command can modify your computer's language.
17 : if you want to check a dir' size , you can put 'du -h' to check this.
18 : date -s "2007-12-8"
19 : mysql 查看當前系統參數變量 show variables like 'character\_set\_%'; In linux system, you can modify mysql conf by modifying /etc/my.cnf.
20 : sometimes, your system has installed a software already, but you want to make your installation valid, you can do like this: export PATH='your software's path':$PATH .
    REMEMBER : your software's bin path must be at the head of PATH.
21 : diff xxxfile xxxfile :this command can find differences between two files.
22 : NAT——網絡地址轉換,是通過將專用網絡地址(如企業內部網Intranet)轉換為公用地址(如互聯網Internet),從而對外隱藏了內部管理的 IP 地址。這樣,通過在內部使用非注冊的 IP 地址,并將它們轉換為一小部分外部注冊的 IP 地址,從而減少了IP 地址注冊的費用以及節省了目前越來越缺乏的地址空間(即IPV4)。同時,這也隱藏了內部網絡結構,從而降低了內部網絡受到攻擊的風險。
23 : 列出幾個關掉Linux防火墻的方法(when i install gos, i found that if my iptables is on, my computer can't connect with other machinces.)
    service iptables stop
    service iptables start
    redhat-config-securitylevel
    永久關閉防火墻
    service iptables sto
    chkconfig iptables off
24 : As to every user in linux, if you want to modify your enviroment always when your system is on, you can implement this by this way :
    $ cd ~ (go to home dir)
    $vi .bashrc
    at the end of bashrc file, you can add export everything you like.
    for example: export LANG=en_US or you can export PATH=...:$PATH
25 : top : this command is similar to taskmanager.
26 : alias : this command is used to see which commands in your computer has other alias. e.g vi maybe is vim.
27 : find ${dir} -name make.inc :this command can find {dir}'s all make.inc files recursivly. you can take param like -maxdepth 1 to limit recursivly.
    e.g find . -maxdepth 1 -name find | wc -l   : it will output 1.
    this command is similar with grep command.
   
    eg: find . -name *.log
   
    grep find -f * (the first 'find' is the string you want to find. -f is to indicate which file you want to search.)
28 : 在Linux下查看內存我們一般用命令: free 也可以用top
    如何看額定值(RHEL4.0):
    #cat /proc/meminfo
29 : nohup 這個命令很重要 當你在控制臺上運行一個程序時,你可能希望關機,但是程序接著在服務器上運行,那么這個時候就應該用
“nohup yourcommand” 來運行你的程序,這樣的話就算你關閉了控制臺程序也還在跑。
30 : screen : this command is very important. please see an article in my blog, the url is http://hi.baidu.com/luxiaoyi/blog/item/a58d9645ee216e25cffca3b2.html
31 : 用.o編譯.so簡單方法: gcc -o abc.so -shared a.o b.o c.o
    詳細介紹 :
    $gcc -c hello.c -o hello.o
    1.連接成靜態庫
    連接成靜態庫使用ar命令,其實ar是archive的意思
    $ar cqs libhello.a hello.o
    2.連接成動態庫
    生成動態庫用gcc來完成,由于可能存在多個版本,因此通常指定版本號:
    $gcc -shared -Wl,-soname,libhello.so.1 -o libhello.so.1.0 hello.o
    另外再建立兩個符號連接:
    $ln -s libhello.so.1.0 libhello.so.1
    $ln -s libhello.so.1 libhello.so
    這樣一個libhello的動態連接庫就生成了。最重要的是傳gcc -shared 參數使其生成是動態庫而不是普通執行程序.
    -Wl 表示后面的參數也就是-soname,libhello.so.1直接傳給連接器ld進行處理。實際上,每一個庫都有一個soname,當連接器發現它正在查找的程序庫中有這樣一個名稱,連接器便會將soname嵌入連結中的二進制文件內,而不是它正在運行的實際文件名,在程序執行期間,程序會查找擁有soname名字的文件,而不是庫的文件名,換句話說,soname是庫的區分標志。
    這樣做的目的主要是允許系統中多個版本的庫文件共存,習慣上在命名庫文件的時候通常與soname相同
    libxxxx.so.major.minor
    其中,xxxx是庫的名字,major是主版本號,minor 是次版本號
    JNI在linux下編譯so文件:
    ------------------------------
    GCC 編譯命令
    ------------------------------
    gcc   -fPIC -shared JniTest.c -o libJniTest.so -I/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/include -I/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/include/linux
    說明:-fPIC -shared 生成動態鏈接文件;-I目錄指向java的目錄,不然會找不到jni.h.
   
    一個新問題:在vc里面,jni自動生成的頭文件中的方法JNIEXPORT void JNICALL Java_testdll_testSo_outOfArray(JNIEnv *, jclass)不需要把參數具體寫上變量,
    但是在linux中,需要寫上具體的變量JNIEXPORT void JNICALL Java_testdll_testSo_outOfArray(JNIEnv * jEnv, jclass jClass) 例如這里的jEnv和jClass。
    還有一個新問題:在linux下動態鏈接庫一定要取名叫lib+你在win下的dll的名字,比如win下叫testso.dll,那么在linux下一定要
    叫libtestso.so 你的代碼里面還是寫System.loadlibrary("testso");
32 : vi /etc/services 可以配置所有的服務和端口。
     netstat -nap|grep 8000 察看所有活動的端口 用root身份就可以看見是哪個進程占了你要的端口,然后kill掉他就可以了。
33 : 如何使ssh登陸別的站點不用輸入密碼?
    首先,例如我想用本地的lxy賬戶登陸遠程節點A的lxy1賬戶,那么首先進入本地/home/lxy目錄,在這個目錄下有一個隱藏目錄.ssh,進入這個目錄,利用ssh-keygen命令來生成本用戶的公私鑰對,可以利用-t參數來指定生成方法:一般用rsa方法。此時,會要求你輸入key的密碼,直接回車就可以。如果你輸的話,就一定要輸入4位以上的密碼,而且,以后你用ssh的時候就要輸入這個密碼。所以,建議不輸入。
    然后會在.ssh目錄下生成兩個文件,例如id_rsa和id_rsa.pub,利用vi拷貝id_rsa.pub中的內容到遠程節點A的lxy1賬戶目錄下的.ssh目錄里面的authorized_keys文件里。這樣,以后你在本地以lxy用戶身份利用ssh命令用節點A的lxy1賬號登陸A節點,就不用再輸入密碼了。而且,執行:ssh lxy1@A ls 就能直接返回遠程節點A的/home/lxy1/目錄結構,不用輸入密碼。
34 : cat /proc/cpuinfo 可以查看cpu信息
35 : /etc/sysconfig/network-scripts/ifcfg-eth0 可以修改ip等網絡信息。
36 : /sbin/service xxx restart == /etc/init.d/xxx restart   
 
名稱 : crontab
使用權限 : 所有使用者
使用方式 :
    crontab  filecrontab [ -u user ] [ -u user ] { -l | -r | -e }
說明 :
    crontab 是用來讓使用者在固定時間或固定間隔執行程式之用,換句話說,也就是類似使用者的時程表。-u user 是指設定指定 user 的時程表,這個前提是你必須要有其權限(比如說是 root)才能夠指定他人的時程表。如果不使用 -u user 的話,就是表示設定自己的時程表。
參數 :
    -e : 執行文字編輯器來設定時程表,內定的文字編輯器是 VI,如果你想用別的文字編輯器,則請先設定 VISUAL 環境變數來指定使用那個文字編輯器(比如說 setenv VISUAL joe)
    -r : 刪除目前的時程表
    -l : 列出目前的時程表

  f1 f2 f3 f4 f5 program
    其中 f1 是表示分鐘,f2 表示小時,f3 表示一個月份中的第幾日,f4 表示月份,f5 表示一個星期中的第幾天。program 表示要執行的程式。
    當 f1 為 * 時表示每分鐘都要執行 program,f2 為 * 時表示每小時都要執行程式,其余類推
    當 f1 為 a-b 時表示從第 a 分鐘到第 b 分鐘這段時間內要執行,f2 為 a-b 時表示從第 a 到第 b 小時都要執行,其余類推
    當 f1 為 */n 時表示每 n 分鐘個時間間隔執行一次,f2 為 */n 表示每 n 小時個時間間隔執行一次,其余類推
    當 f1 為 a, b, c,... 時表示第 a, b, c,... 分鐘要執行,f2 為 a, b, c,... 時表示第 a, b, c...個小時要執行,其余類推
    使用者也可以將所有的設定先存放在檔案 file 中,用 crontab file 的方式來設定時程表。
     可以是 1-30/5 表示:第1-30分鐘,每5分鐘執行一次
 
 

查看端口服務程序:
nmap -sT -O xxx.xxx.xxx.xxx
 本文由用戶 ls889 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!