自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

對 Linux 中級用戶非常有用的 20 個命令

系統(tǒng) Linux
上周,我們?yōu)樾率譁?zhǔn)備的20個命令,這篇文章是繼對初級Linux用戶非常有用的20個命令的一個延伸。主要為Linux的中高級用戶打造的,你可以學(xué)會如何進行自定義搜索,如何使用Linux的強勢功能等。

也許你已經(jīng)發(fā)現(xiàn)***篇文章非常的有用,這篇文章是繼對初級Linux用戶非常有用的20個命令 的一個延伸。 ***篇文章的目的是為新手準(zhǔn)備的而這篇文章則是為了Linux的中高級用戶。在這里你將學(xué)會如何進行自定義搜索,知道正在進行的進程和停掉進程,如何使用Linux的強勢功能和如何在系統(tǒng)內(nèi)編譯C,C++和JAVA程序。

21. 命令: Find

搜索指定目錄下的文件,從開始于父目錄,然后搜索子目錄。

  1. root@tecmint:~# find -name *.sh 
  2. ./Desktop/load.sh 
  3. ./Desktop/test.sh 
  4. ./Desktop/shutdown.sh 
  5. ./Binary/firefox/run-mozilla.sh 
  6. ./Downloads/kdewebdev-3.5.8/quanta/scripts/externalpreview.sh 
  7. ./Downloads/kdewebdev-3.5.8/admin/doxygen.sh 
  8. ./Downloads/kdewebdev-3.5.8/admin/cvs.sh 
  9. ./Downloads/kdewebdev-3.5.8/admin/ltmain.sh 
  10. ./Downloads/wheezy-nv-install.sh 

注意: `-name‘選項是搜索大小寫敏感??梢允褂胉-iname‘選項,這樣在搜索中可以忽略大小寫。(*是通配符,可以搜索所有的文件;‘.sh‘你可以使用文件名或者文件名的一部分來制定輸出結(jié)果)

  1. root@tecmint:~# find -iname *.SH ( find -iname *.Sh /  find -iname *.sH) 
  2. ./Desktop/load.sh 
  3. ./Desktop/test.sh 
  4. ./Desktop/shutdown.sh 
  5. ./Binary/firefox/run-mozilla.sh 
  6. ./Downloads/kdewebdev-3.5.8/quanta/scripts/externalpreview.sh 
  7. ./Downloads/kdewebdev-3.5.8/admin/doxygen.sh 
  8. ./Downloads/kdewebdev-3.5.8/admin/cvs.sh 
  9. ./Downloads/kdewebdev-3.5.8/admin/ltmain.sh 
  10. ./Downloads/wheezy-nv-install.sh 
  11. root@tecmint:~# find -name *.tar.gz 
  12. /var/www/modules/update/tests/aaa_update_test.tar.gz 
  13. ./var/cache/flashplugin-nonfree/install_flash_player_11_linux.i386.tar.gz 
  14. ./home/server/Downloads/drupal-7.22.tar.gz 
  15. ./home/server/Downloads/smtp-7.x-1.0.tar.gz 
  16. ./home/server/Downloads/noreqnewpass-7.x-1.2.tar.gz 
  17. ./usr/share/gettext/archive.git.tar.gz 
  18. ./usr/share/doc/apg/php.tar.gz 
  19. ./usr/share/doc/festival/examples/speech_pm_1.0.tar.gz 
  20. ./usr/share/doc/argyll/examples/spyder2.tar.gz 
  21. ./usr/share/usb_modeswitch/configPack.tar.gz 

注意:以上命令查找根目錄下和所有文件夾以及加載的設(shè)備的子目錄下的所有包含‘tar.gz'的文件。

’find'命令的更詳細信息請參考35 Find Command Examples in Linux #p#

22. 命令: grep

‘grep‘命令搜索指定文件中包含給定字符串或者單詞的行。舉例搜索‘/etc/passwd‘文件中的‘tecmint'

  1. root@tecmint:~# grep tecmint /etc/passwd 
  2. tecmint:x:1000:1000:Tecmint,,,:/home/tecmint:/bin/bash 

使用’-i'選項將忽略大小寫。

  1. root@tecmint:~# grep -i TECMINT /etc/passwd 
  2. tecmint:x:1000:1000:Tecmint,,,:/home/tecmint:/bin/bash 

使用’-r'選項遞歸搜索所有自目錄下包含字符串 “127.0.0.1“.的行。

  1. root@tecmint:~# grep -r "127.0.0.1" /etc/ 
  2. /etc/vlc/lua/http/.hosts:127.0.0.1 
  3. /etc/speech-dispatcher/modules/ivona.conf:#IvonaServerHost "127.0.0.1" 
  4. /etc/mysql/my.cnf:bind-address      = 127.0.0.1 
  5. /etc/apache2/mods-available/status.conf:    Allow from 127.0.0.1 ::1 
  6. /etc/apache2/mods-available/ldap.conf:    Allow from 127.0.0.1 ::1 
  7. /etc/apache2/mods-available/info.conf:    Allow from 127.0.0.1 ::1 
  8. /etc/apache2/mods-available/proxy_balancer.conf:#    Allow from 127.0.0.1 ::1 
  9. /etc/security/access.conf:#+ : root : 127.0.0.1 
  10. /etc/dhcp/dhclient.conf:#prepend domain-name-servers 127.0.0.1; 
  11. /etc/dhcp/dhclient.conf:#  option domain-name-servers 127.0.0.1; 
  12. /etc/init/network-interface.conf:   ifconfig lo 127.0.0.1 up || true 
  13. /etc/java-6-openjdk/net.properties:# localhost & 127.0.0.1). 
  14. /etc/java-6-openjdk/net.properties:# http.nonProxyHosts=localhost|127.0.0.1 
  15. /etc/java-6-openjdk/net.properties:# localhost & 127.0.0.1). 
  16. /etc/java-6-openjdk/net.properties:# ftp.nonProxyHosts=localhost|127.0.0.1 
  17. /etc/hosts:127.0.0.1    localhost 

注意:您還可以使用以下選項:

  • -w 搜索單詞 (egrep -w ‘word1|word2‘ /path/to/file).
  • -c 用于統(tǒng)計滿足要求的行 (i.e., total number of times the pattern matched) (grep -c ‘word‘ /path/to/file).
  • –color 彩色輸出 (grep –color server /etc/passwd).

23. 命令: man

‘man‘是系統(tǒng)幫助頁。Man提供命令所有選項及用法的在線文檔。幾乎所有的命令都有它們的幫助頁,例如:

  1. root@tecmint:~# man man 
  2. MAN(1)                                                               Manual pager utils                                                              MAN(1) 
  3. NAME 
  4. man - an interface to the on-line reference manuals 
  5. SYNOPSIS 
  6. man  [-C  file]  [-d]  [-D]  [--warnings[=warnings]]  [-R  encoding]  [-L  locale]  [-m  system[,...]]  [-M  path]  [-S list] [-e extension] [-i|-I] 
  7. [--regex|--wildcard] [--names-only] [-a] [-u] [--no-subpages] [-P pager] [-r prompt] [-7] [-E encoding] [--no-hyphenation] [--no-justification]  [-p 
  8. string] [-t] [-T[device]] [-H[browser]] [-X[dpi]] [-Z] [[section] page ...] ... 
  9. man -k [apropos options] regexp ... 
  10. man -K [-w|-W] [-S list] [-i|-I] [--regex] [section] term ... 
  11. man -f [whatis options] page ... 
  12. man -l [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L locale] [-P pager] [-r prompt] [-7] [-E encoding] [-p string] [-t] [-T[device]] 
  13. [-H[browser]] [-X[dpi]] [-Z] file ... 
  14. man -w|-W [-C file] [-d] [-D] page ... 
  15. man -c [-C file] [-d] [-D] page ... 
  16. man [-hV] 

上面是man命令的系統(tǒng)幫助頁,類似的有cat和ls的幫助頁。

注意:系統(tǒng)幫助頁是為了命令的使用和學(xué)習(xí)而設(shè)計的。#p#

24. 命令: ps

ps命令給出正在運行的某個進程的狀態(tài),每個進程有特定的id成為PID。

  1. root@tecmint:~# ps 
  2. PID TTY          TIME CMD 
  3. 4170 pts/1    00:00:00 bash 
  4. 9628 pts/1    00:00:00 ps 

使用‘-A‘選項可以列出所有的進程及其PID。

  1. root@tecmint:~# ps -A 
  2. PID TTY          TIME CMD 
  3. 1 ?        00:00:01 init 
  4. 2 ?        00:00:00 kthreadd 
  5. 3 ?        00:00:01 ksoftirqd/0 
  6. 5 ?        00:00:00 kworker/0:0H 
  7. 7 ?        00:00:00 kworker/u:0H 
  8. 8 ?        00:00:00 migration/0 
  9. 9 ?        00:00:00 rcu_bh 
  10. .... 

注意:當(dāng)你要知道有哪些進程在運行或者需要知道想殺死的進程PID時ps命令很管用。你可以把它與‘grep‘合用來查詢指定的輸出結(jié)果,例如:

  1. root@tecmint:~# ps -A | grep -i ssh 
  2. 1500 ?        00:09:58 sshd 
  3. 4317 ?        00:00:00 sshd 

ps命令與grep命令用管道線分割可以得到我們想要的結(jié)果。

25. 命令: kill

也許你從命令的名字已經(jīng)猜出是做什么的了,kill是用來殺死已經(jīng)無關(guān)緊要或者沒有響應(yīng)的進程.它是一個非常有用的命令,而不是非常非常有用.你可能很熟悉Windows下要殺死進程可能需要頻繁重啟機器因為一個在運行的進程大部分情況下不能夠殺死,即使殺死了進程也需要重新啟動操作系統(tǒng)才能生效.但在linux環(huán)境下,事情不是這樣的.你可以殺死一個進程并且重啟它而不是重啟整個操作系統(tǒng).

殺死一個進程需要知道進程的PID.

假設(shè)你想殺死已經(jīng)沒有響應(yīng)的‘apache2'進程,運行如下命令:

  1. root@tecmint:~# ps -A | grep -i apache2 
  2. 1285 ?        00:00:00 apache2 

搜索‘apache2'進程,找到PID并殺掉它.例如:在本例中‘apache2'進程的PID是1285..

  1. root@tecmint:~# kill 1285 (to kill the process apache2) 

注意:每次你重新運行一個進程或者啟動系統(tǒng),每個進程都會生成一個新的PID.你可以使用ps命令獲得當(dāng)前運行進程的PID.

另一個殺死進程的方法是:

  1. root@tecmint:~# pkill apache2 

注意:kill需要PID作為參數(shù),pkill可以選擇應(yīng)用的方式,比如指定進程的所有者等。

26. 命令: whereis

whereis的作用是用來定位命令的二進制文件\資源\或者幫助頁.舉例來說,獲得ls和kill命令的二進制文件/資源以及幫助頁:

  1. root@tecmint:~# whereis ls 
  2. ls: /bin/ls /usr/share/man/man1/ls.1.gz 
  3. root@tecmint:~# whereis kill 
  4. kill: /bin/kill /usr/share/man/man2/kill.2.gz /usr/share/man/man1/kill.1.gz 

注意:當(dāng)需要知道二進制文件保存位置時有用.#p#

27. 命令: service

‘service‘命令控制服務(wù)的啟動、停止和重啟,它讓你能夠不重啟整個系統(tǒng)就可以讓配置生效以開啟、停止或者重啟某個服務(wù)。

在Ubuntu上啟動apache2 server:

  1. root@tecmint:~# service apache2 start 
  2. * Starting web server apache2                                                                                                                               
  3.  apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName 
  4. httpd (pid 1285) already running    [ OK ] 

重啟apache2 server:

  1. root@tecmint:~# service apache2 restart 
  2. * Restarting web server apache2                                                                                                                               
  3. apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName 
  4. ... waiting .apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName  [ OK ] 

停止apache2 server:

  1. root@tecmint:~# service apache2 stop 
  2. * Stopping web server apache2                                                                                                                                 
  3. apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName 
  4. ... waiting                                                                [ OK ] 

注意:要想使用service命令,進程的腳本必須放在‘/etc/init.d‘,并且路徑必須在指定的位置。

如果要運行“service apache2 start”實際上實在執(zhí)行“service /etc/init.d/apache2 start”.

28. 命令: alias

alias是一個系統(tǒng)自建的shell命令,允許你為名字比較長的或者經(jīng)常使用的命令指定別名。

我經(jīng)常用‘ls -l‘命令,它有五個字符(包括空格)。于是我為它創(chuàng)建了一個別名‘l'。

  1. root@tecmint:~# alias l='ls -l' 

試試它是否能用:

  1. root@tecmint:~# l 
  2. total 36 
  3. drwxr-xr-x 3 tecmint tecmint 4096 May 10 11:14 Binary 
  4. drwxr-xr-x 3 tecmint tecmint 4096 May 21 11:21 Desktop 
  5. drwxr-xr-x 2 tecmint tecmint 4096 May 21 15:23 Documents 
  6. drwxr-xr-x 8 tecmint tecmint 4096 May 20 14:56 Downloads 
  7. drwxr-xr-x 2 tecmint tecmint 4096 May  7 16:58 Music 
  8. drwxr-xr-x 2 tecmint tecmint 4096 May 20 16:17 Pictures 
  9. drwxr-xr-x 2 tecmint tecmint 4096 May  7 16:58 Public 
  10. drwxr-xr-x 2 tecmint tecmint 4096 May  7 16:58 Templates 
  11. drwxr-xr-x 2 tecmint tecmint 4096 May  7 16:58 Videos 

去掉’l'別名,要使用unalias命令:

  1. root@tecmint:~# unalias l 

再試試:

  1. root@tecmint:~# l 
  2. bash: l: command not found 

開個玩笑,把一個重要命令的別名指定為另一個重要命令:

  1. alias cd='ls -l' (set alias of ls -l to cd) 
  2. alias su='pwd' (set alias of pwd to su) 
  3. .... 
  4. (You can create your own) 
  5. .... 

想想多么有趣,現(xiàn)在如果你的朋友敲入‘cd'命令,當(dāng)他看到的是目錄文件列表而不是改變目錄;當(dāng)他試圖用’su‘命令時,他會進入當(dāng)前目錄。你可以隨后去掉別名,向他解釋以上情況。#p#

29.命令: df

報告系統(tǒng)的磁盤使用情況。在跟蹤磁盤使用情況方面對于普通用戶和系統(tǒng)管理員都很有用。 ‘df‘ 通過檢查目錄大小工作,但這一數(shù)值僅當(dāng)文件關(guān)閉時才得到更新。

  1. root@tecmint:~# df 
  2. Filesystem     1K-blocks    Used Available Use% Mounted on 
  3. /dev/sda1       47929224 7811908  37675948  18% / 
  4. none                   4       0         4   0% /sys/fs/cgroup 
  5. udev             1005916       4   1005912   1% /dev 
  6. tmpfs             202824     816    202008   1% /run 
  7. none                5120       0      5120   0% /run/lock 
  8. none             1014120     628   1013492   1% /run/shm 
  9. none              102400      44    102356   1% /run/user 
  10. /dev/sda5         184307   79852     94727  46% /boot 
  11. /dev/sda7       95989516   61104  91045676   1% /data 
  12. /dev/sda8       91953192   57032  87218528   1% /personal 

‘df’命令的更多例子請參閱 12 df Command Examples in Linux.

30. 命令: du

估計文件的空間占用。 逐層統(tǒng)計文件(例如以遞歸方式)并輸出摘要。

  1. root@tecmint:~# du 
  2. 8       ./Daily Pics/wp-polls/images/default_gradient 
  3. 8       ./Daily Pics/wp-polls/images/default 
  4. 32      ./Daily Pics/wp-polls/images 
  5. 8       ./Daily Pics/wp-polls/tinymce/plugins/polls/langs 
  6. 8       ./Daily Pics/wp-polls/tinymce/plugins/polls/img 
  7. 28      ./Daily Pics/wp-polls/tinymce/plugins/polls 
  8. 32      ./Daily Pics/wp-polls/tinymce/plugins 
  9. 36      ./Daily Pics/wp-polls/tinymce 
  10. 580     ./Daily Pics/wp-polls 
  11. 1456    ./Daily Pics 
  12. 36      ./Plugins/wordpress-author-box 
  13. 16180   ./Plugins 
  14. 12      ./May Articles 2013/Xtreme Download Manager 
  15. 4632    ./May Articles 2013/XCache 

注意: ‘df‘ 只顯示文件系統(tǒng)的使用統(tǒng)計,但‘du‘統(tǒng)計目錄內(nèi)容。‘du‘命令的更詳細信息請參閱10 du (Disk Usage) Commands.

31. 命令: rm

'rm' 標(biāo)準(zhǔn)移除命令。 rm 可以用來刪除文件和目錄。

刪除目錄:

  1. root@tecmint:~# rm PassportApplicationForm_Main_English_V1.0 
  2. rm: cannot remove `PassportApplicationForm_Main_English_V1.0': Is a directory 

'rm' 不能直接刪除目錄,需要加上相應(yīng)的'-rf'參數(shù)才可以。

  1. root@tecmint:~# rm -rf PassportApplicationForm_Main_English_V1.0 

警告: "rm -rf" 命令是一個破壞性的命令,假如你不小心刪除一個錯誤的目錄。一旦你使用'rm -rf' 刪除一個目錄,在目錄中所有的文件包括目錄本身會被***的刪除,所以使用這個命令要非常小心。#p#

32. 命令: echo

echo  的功能正如其名,就是基于標(biāo)準(zhǔn)輸出打印一段文本。它和shell無關(guān),shell也不讀取通過echo命令打印出的內(nèi)容。然而在一種交互式腳本中,echo通過終端將信息傳遞給用戶。它是在腳本語言,交互式腳本語言中經(jīng)常用到的命令。

  1. root@tecmint:~# echo "Tecmint.com is a very good website" 
  2. Tecmint.com is a very good website 

創(chuàng)建一小段交互式腳本

1. 在桌面上新建一個文件,命名為 ‘interactive_shell.sh‘  (記住必須帶 ‘.sh‘擴展名)。

2. 復(fù)制粘貼如下腳本代碼,確保和下面的一致。

  1. #!/bin/bash 
  2. echo "Please enter your name:" 
  3. read name 
  4. echo "Welcome to Linux $name" 

接下來,設(shè)置執(zhí)行權(quán)限并運行腳本。

  1. root@tecmint:~# chmod 777 interactive_shell.sh 
  2. root@tecmint:~# ./interactive_shell.sh 
  3. Please enter your name: 
  4. Ravi Saive 
  5. Welcome to Linux Ravi Saive 

注意: ‘#!/bin/bash‘ 告訴shell這是一個腳本,并且在腳本首行寫上這句話是個好習(xí)慣。. ‘read‘ 讀取給定的輸出.

33. 命令: passwd

這是一個很重要的命令,在終端中用來改變自己密碼很有用。顯然的,因為安全的原因,你需要知道當(dāng)前的密碼。

  1. root@tecmint:~# passwd 
  2. Changing password for tecmint. 
  3. (current) UNIX password: ******** 
  4. Enter new UNIX password: ******** 
  5. Retype new UNIX password: ******** 

Password unchanged   [這里表示密碼未改變,例如:新密碼=舊密碼]

  1. Enter new UNIX password: ##### 
  2. Retype new UNIX password:##### 

34. 命令: lpr

這個命令用來在命令行上將指定的文件在指定的打印機上打印。

  1. root@tecmint:~# lpr -P deskjet-4620-series 1-final.pdf 

注意: "lpq"命令讓你查看打印機的狀態(tài)(是開啟狀態(tài)還是關(guān)閉狀態(tài))和等待打印中的工作(文件)的狀態(tài)。

35. 命令: cmp

比較兩個任意類型的文件并將結(jié)果輸出至標(biāo)準(zhǔn)輸出。如果兩個文件相同, ‘cmp‘默認(rèn)返回0;如果不同,將顯示不同的字節(jié)數(shù)和***處不同的位置。

以下面兩個文件為例:

  1. file1.txt 
  2. root@tecmint:~# cat file1.txt 
  3. Hi My name is Tecmint 
  4. file2.txt 
  5. root@tecmint:~# cat file2.txt 
  6. Hi My name is tecmint [dot] com 

比較一下這兩個文件,看看命令的輸出。

  1. root@tecmint:~# cmp file1.txt file2.txt 
  2. file1.txt file2.txt differ: byte 15, line 1 

36. 命令: wget

Wget是用于非交互式(例如后臺)下載文件的免費工具.支持HTTP, HTTPS, FTP協(xié)議和 HTTP 代理。

使用wget下載ffmpeg

  1. view sourceprint? 
  2. root@tecmint:~# wget http://downloads.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2 
  3. --2013-05-22 18:54:52--  http://downloads.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2 
  4. Resolving downloads.sourceforge.net (downloads.sourceforge.net)... 216.34.181.59 
  5. Connecting to downloads.sourceforge.net (downloads.sourceforge.net)|216.34.181.59|:80... connected. 
  6. HTTP request sent, awaiting response... 302 Found 
  7. Location: http://kaz.dl.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2 [following] 
  8. --2013-05-22 18:54:54--  http://kaz.dl.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2 
  9. Resolving kaz.dl.sourceforge.net (kaz.dl.sourceforge.net)... 92.46.53.163 
  10. Connecting to kaz.dl.sourceforge.net (kaz.dl.sourceforge.net)|92.46.53.163|:80... connected. 
  11. HTTP request sent, awaiting response... 200 OK 
  12. Length: 275557 (269K) [application/octet-stream] 
  13. Saving to: ‘ffmpeg-php-0.6.0.tbz2’ 
  14. 100%[===========================================================================>] 2,75,557    67.8KB/s   in 4.0s 
  15.  
  16. 2013-05-22 18:55:00 (67.8 KB/s) - ‘ffmpeg-php-0.6.0.tbz2’ saved [275557/275557] 

#p#

37 命令: mount

mount 是一個很重要的命令,用來掛載不能自動掛載的文件系統(tǒng)。你需要root權(quán)限掛載設(shè)備。

在插入你的文件系統(tǒng)后,首先運行"lsblk"命令,識別出你的設(shè)備,然后把分配的設(shè)備名記下來。

  1. root@tecmint:~# lsblk 
  2. NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT 
  3. sda      8:0    0 931.5G  0 disk 
  4. ├─sda1   8:1    0 923.6G  0 part / 
  5. ├─sda2   8:2    0     1K  0 part 
  6. └─sda5   8:5    0   7.9G  0 part [SWAP] 
  7. sr0     11:0    1  1024M  0 rom 
  8. sdb      8:16   1   3.7G  0 disk 
  9. └─sdb1   8:17   1   3.7G  0 part 

從這個輸出上來看,很明顯我插入的是4GB的U盤,因而“sdb1”就是要掛載上來的文件系統(tǒng)。以root用戶操作,然后切換到/dev目錄,它是所有文件系統(tǒng)掛載的地方。

  1. root@tecmint:~# su 

Password:

  1. root@tecmint:~# cd /dev 

創(chuàng)建一個任何名字的目錄,但是***和引用相關(guān)。

  1. root@tecmint:~# mkdir usb 

現(xiàn)在將“sdb1”文件系統(tǒng)掛載到“usb”目錄.

  1. root@tecmint:~# mount /dev/sdb1 /dev/usb 

現(xiàn)在你就可以從終端進入到/dev/usb或者通過X窗口系統(tǒng)從掛載目錄訪問文件。

是時候讓程序猿見識見識Linux環(huán)境是多么豐富了!

38. 命令: gcc

gcc 是Linux環(huán)境下C語言的內(nèi)建編譯器。下面是一個簡單的C程序,在桌面上保存為Hello.c (記住必須要有‘.c‘擴展名)。

  1. #include <stdio.h> 
  2. int main() 
  3. printf("Hello world\n"); 
  4. return 0; 

編譯:

  1. root@tecmint:~# gcc Hello.c 

運行:

  1. root@tecmint:~# ./a.out 
  2. Hello world 

注意: 編譯C程序時,輸出會自動保存到一個名為“a.out”的新文件,因此每次編譯C程序 “a.out”都會被修改。 因此編譯期間***定義輸出文件名.,這樣就不會有覆蓋輸出文件的風(fēng)險了。

用這種方法編譯:

  1. root@tecmint:~# gcc -o Hello Hello.c 

這里‘-o‘將輸出寫到‘Hello‘文件而不是 ‘a.out‘。再運行一次。

  1. root@tecmint:~# ./Hello 
  2. Hello world 

39. 命令: g++

g++是C++的內(nèi)建編譯器。下面是一個簡單的C++程序,在桌面上保存為Add.cpp (記住必須要有‘.cpp‘擴展名)。

  1. #include <iostream> 
  2. using namespace std; 
  3. int main() 
  4. int a; 
  5. int b; 
  6. cout<<"Enter first number:\n"; 
  7. cin >> a; 
  8. cout <<"Enter the second number:\n"; 
  9. cin>> b; 
  10. cin.ignore(); 
  11. int result = a + b; 
  12. cout<<"Result is"<<"  "<<result<<endl
  13. cin.get(); 
  14. return 0; 

編譯:

  1. root@tecmint:~# g++ Add.cpp 

運行:

  1. root@tecmint:~# ./a.out 
  2. Enter first number: 
  3. ... 
  4. ... 

注意:編譯C++程序時,輸出會自動保存到一個名為“a.out”的新文件,因此每次編譯C++程序 “a.out”都會被修改。 因此編譯期間***定義輸出文件名.,這樣就不會有覆蓋輸出文件的風(fēng)險了。

用這種方法編譯:

  1. root@tecmint:~# g++ -o Add Add.cpp 

運行:

  1. view sourceprint? 
  2. root@tecmint:~# ./Add 
  3. Enter first number: 
  4. ... 
  5. ... 

40. 命令: java

Java 是世界上使用最廣泛的編程語言之一. 它也被認(rèn)為是高效, 安全和可靠的編程語言. 現(xiàn)在大多數(shù)基于網(wǎng)絡(luò)的服務(wù)都使用Java實現(xiàn).

拷貝以下代碼到一個文件就可以創(chuàng)建一個簡單的Java程序. 不妨把文件命名為tecmint.java (記住: '.java'擴展名是必需的).

  1. class tecmint { 
  2. public static void main(String[] arguments) { 
  3. System.out.println("Tecmint "); 

用javac編譯tecmint.java:

  1. root@tecmint:~# javac tecmint.java 

運行:

  1. root@tecmint:~# java tecmint 

注意: 幾乎所有的Linux發(fā)行版都帶有g(shù)cc編譯器, 大多數(shù)發(fā)行版都內(nèi)建了g++ 和 java 編譯器, 有些也可能沒有. 你可以用apt 或 yum 安裝需要的包.

請留下您寶貴的意見和想看到的文章類型. 稍后, 我會打來一個很有趣主題, 關(guān)于Linux的一些鮮為人知的知識.

 

責(zé)任編輯:黃丹 來源: oschina
相關(guān)推薦

2018-08-03 10:02:05

Linux命令

2013-08-13 10:46:51

LinuxLinux命令

2009-03-24 14:23:59

PHP類庫PHP開發(fā)PHP

2017-08-02 13:32:18

編程Java程序片段

2013-06-14 14:57:09

Java基礎(chǔ)代碼

2021-10-21 22:03:00

PythonNumpy函數(shù)

2020-06-15 10:29:10

JavaScript開發(fā) 技巧

2009-05-18 16:58:56

Java代碼片段

2020-10-29 10:00:55

Python函數(shù)文件

2023-02-19 15:22:22

React技巧

2011-07-07 17:16:43

PHP

2023-06-13 15:15:02

JavaScript前端編程語言

2022-09-02 23:08:04

JavaScript技巧開發(fā)

2013-11-05 10:03:22

Eclipse功能

2021-03-09 09:14:27

ES2019JavaScript開發(fā)

2009-02-09 11:20:06

Windows7Windows

2022-06-27 19:01:04

Python應(yīng)用程序數(shù)據(jù)

2013-08-21 10:31:22

HTML5工具

2017-11-16 08:15:26

程序員Java程序

2011-04-06 14:08:14

jQuery
點贊
收藏

51CTO技術(shù)棧公眾號