ѧϰlinux programming(1)
¡¾1. linux applications ÓÐÁ½ÖÖÐÎʽ¡¿
i£©¿ÉÖ´ÐеÄÎļþ£º ¿ÉÓɼÆËã»úÖ±½ÓÔËÐУ¬Ï൱ÓÚwindowsµÄ.exeÎļþ
ii£©Script: collections of instructions for another program. Ï൱ÓÚwindowsµÄ.bat .cmdÎļþ
¡¾2. PATH¡¿
ÔÚLinuxÖУ¬µ±ÊäÈë³ÌÐòÃû£¨ÈçFirefox£©Ê±£¬ÏµÍ³»áÔÚÃûΪPATHµÄShell±äÁ¿Ëù¸ø¶¨µÄһϵÁÐĿ¼ÖÐÑ°ÕÒÊÇ·ñÓÐͬÃûµÄÎļþ¡£
²é¿´PATHµÄÖµ£¬ÔÚLinux£º $PATH »òÕß echo $PATH
windows£º PATH
Linux¿ÉÖ´ÐÐÎļþλÖÃ˵Ã÷£º
/bin: binaries, programs used in booting the system
/usr/bin: user binaries, standard programs available to users
/usr/local/bin: local binaries, programs specific to an installation
µ±ÒÔadministatorÉí·Ý½øÈëʱ£¬¿ÉÄÜ»áʹÓÃϵͳ¹ÜÀí³ÌÐòËùÔÚµÄPATHĿ¼£¬Èç: /sbin »ò /usr/sbin
Linux£¬like unix, ÔÚPATH±äÁ¿µÄentriesÖ®¼äÓÃcolon(:)·Ö¸ô£¬¶øwindowsºÍms-dosÓÃsemicolon (;) ·Ö¸ô¡£
Linux£ºÊ¹ÓÃforward slash (/) À´·Ö¸ôĿ¼
eg: /usr/bin/
windows: ʹÓÃbackward slash (\)À´·Ö¸ô
eg: c:\Documents and settings\user>
¡¾3. C compiler¡¿
ÔÚPOSIX-compliant system (POSIX: Portable Operating System Interface), C compiler is called c89.
in linux, c89, cc, gcc refer to the system c compiler.
¡¾4. first c program in linux¡¿
1) hello.c file content
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello World!\n");
}
2) compile
$gcc -o hello hello.c
gcc²ÎÊý˵Ã÷£º
-o <file>£ºÊä³öµ½file,Èôδָ¶¨-o£¬ÔòdefaultÊä³öµ½a.out
Èç¹ûÒª²é¿´ÖмäÉú³ÉÎļþ£¬¿ÉÓÃgcc²ÎÊý -save-temps
$gcc -save-temps -o hello hello.c
$ls
hello hello.c hello.i hello.o hello.s
//ÒÔÉÏÉú³ÉµÄ4¸öÎļþ˵Ã÷¼û¡¾5.±àÒëϵͳ¡¿
3) execute
$./hello
˵Ã÷£º
ÈôÖ±½ÓÓÃhello£¬¼´Ö´ÐÐ
$hello
Ôòϵͳ»áÔÚShell±äÁ¿PATHËùÁгöµÄĿ¼ÖÐsearch£¬ÈôÇ¡ºÃÓÐÒ»¸öÃûΪ
helloµÄÎļþ£¬ÔòÖ´ÐÐÖ®¡£
./£º ´ú±íµ±Ç°Ä¿Â¼¡£
¡¾5.±àÒëϵÍ
Ïà¹ØÎĵµ£º
ÎÒÃǾ³£»áÅöµ½ÕâÑùµÄÎÊÌ⣬Óà telnet/ssh µÇ¼ÁËÔ¶³ÌµÄ Linux ·þÎñÆ÷£¬ÔËÐÐÁËһЩºÄʱ½Ï³¤µÄÈÎÎñ£¬ ½á¹ûÈ´ÓÉÓÚÍøÂçµÄ²»Îȶ¨µ¼ÖÂÈÎÎñÖÐ;ʧ°Ü¡£ÈçºÎÈÃÃüÁîÌá½»ºó²»Êܱ¾µØ¹Ø±ÕÖն˴°¿Ú/ÍøÂç¶Ï¿ªÁ¬½ÓµÄ¸ÉÈÅÄØ£¿ÏÂÃæ¾ÙÁËһЩÀý×Ó£¬ Äú¿ÉÒÔÕë¶Ô²»Í¬µÄ³¡¾°Ñ¡Ôñ²»Í¬µÄ·½Ê½À´´¦ÀíÕâ¸öÎÊÌâ¡£
nohup/setsid/&
³¡¾°£º
Èç¹ûÖ» ......
ÔÚLinuxÀïÃæÒ»ÇнÔÎļþ£¬´ÓÎļþѧÆðÀ´£¬×î³£¼ûµÄÃüÁî¾ÍÊDz鿴ÎļþºÍËÑË÷Îļþ¡£
ÏÂÃæ¼òµ¥µÄ×ܽáÏÂÕ⼸¸öÃüÁ
²é¿´Îļþ(cat,tac,more,less,head,tail,od)
cat:
cat [file]
²é¿´ÎļþµÄÄÚÈÝ¡£È«³ÌʽconcatenateµÄÒâ˼£¬½«ÎļþÄÚÈÝÁ¬ÐøÊä³öµ½ÆÁÄ»ÉÏ¡£µÚÒ»Ðе½×îºóÒ»ÐÐÏÔʾ¡£
tac:
tac [file]
ºÍcat¸ÕºÃÏà·´ ÊÇ´Ó ......
Linux²é¿´Ó²¼þÐÅÏ¢ÃüÁî
1.²é¿´CPUÐÅÏ¢
cat /proc/cpuinfo
2.²é¿´ÄÚ´æÐÅÏ¢
cat /proc/meminfo
free
vmstat
3.²é¿´Ó²ÅÌÐÅÏ¢
fdisk -l
df -lh
4.²é¿´Äں˰汾ÐÅÏ¢
cat /proc/version
uname -r
lsb_release -a
5.²é¿´ÎļþÕ¼Óÿռä
du
6.²é¿´ÏµÍ³ÐÅÏ¢
dmesg
7.²é¿´¶Ë¿ÚÐÅÏ¢
netstat
8.²é¿´32λ»¹ÊÇ64λ
ge ......
LinuxϵͳÆô¶¯¹ý³Ì
±¾ÎÄÒÔRedHat9.0ºÍi386ƽ̨ΪÀý£¬ÆÊÎöÁË´ÓÓû§´ò¿ªµçÔ´Ö±µ½ÆÁÄ»³öÏÖÃüÁîÐÐÌáʾ·ûµÄÕû¸öLinuxÆô¶¯¹ý³Ì¡£²¢ÇÒ½éÉÜÁËÆô¶¯ÖÐÉæ¼°µ½µÄ¸÷ÖÖÎļþ¡£
µ±Óû§´ò¿ªPCµÄµçÔ´£¬BIOS¿ª»ú×Լ죬°´BIOSÖÐÉèÖõÄÆô¶¯É豸(ͨ³£ÊÇÓ²ÅÌ)Æô¶¯£¬½Ó×ÅÆô¶¯É豸ÉÏ°²×°µÄÒýµ¼³ÌÐòlilo»ògrub¿ªÊ¼Òýµ¼ Linux£¬LinuxÊ×ÏȽøÐÐÄں˵ÄÒý ......
add user£º
[root@localhost ~]# useradd test
[root@localhost ~]# passwd test
add user to a group:
e.g. add nexus to admin
useradd -g admin nexus
default role£º
[root@localhost ~]# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=no
de ......