Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

linux shell ½Å±¾ÈëÃÅ


1. Linux ½Å±¾±àд»ù´¡
1.1 Óï·¨»ù±¾½éÉÜ
1.1.1 ¿ªÍ·
³ÌÐò±ØÐëÒÔÏÂÃæµÄÐпªÊ¼£¨±ØÐë·½ÔÚÎļþµÄµÚÒ»ÐУ©£º
#!/bin/sh
·ûºÅ#!ÓÃÀ´¸æËßϵͳËüºóÃæµÄ²ÎÊýÊÇÓÃÀ´Ö´ÐиÃÎļþµÄ³ÌÐò¡£ÔÚÕâ¸öÀý×ÓÖÐÎÒÃÇʹÓÃ/bin/shÀ´Ö´ÐгÌÐò¡£
µ±±à¼­ºÃ½Å±¾Ê±£¬Èç¹ûÒªÖ´Ðиýű¾£¬»¹±ØÐëʹÆä¿ÉÖ´ÐС£
Ҫʹ½Å±¾¿ÉÖ´ÐУº
±àÒë chmod +x filename ÕâÑù²ÅÄÜÓÃ./filename À´ÔËÐÐ
1.1.2 ×¢ÊÍ
ÔÚ½øÐÐshell±à³Ìʱ£¬ÒÔ#¿ªÍ·µÄ¾ä×Ó±íʾעÊÍ£¬Ö±µ½ÕâÒ»ÐеĽáÊø¡£ÎÒÃÇÕæ³ÏµØ½¨ÒéÄúÔÚ³ÌÐòÖÐʹÓÃ×¢ÊÍ¡£
Èç¹ûÄúʹÓÃÁË×¢ÊÍ£¬ÄÇô¼´Ê¹Ï൱³¤µÄʱ¼äÄÚûÓÐʹÓøýű¾£¬ÄúÒ²ÄÜÔں̵ܶÄʱ¼äÄÚÃ÷°×¸Ã½Å±¾µÄ×÷ÓÃ
¼°¹¤×÷Ô­Àí¡£
1.1.3 ±äÁ¿
ÔÚÆäËû±à³ÌÓïÑÔÖÐÄú±ØÐëʹÓñäÁ¿¡£ÔÚshell±à³ÌÖУ¬ËùÓеıäÁ¿¶¼ÓÉ×Ö·û´®×é³É£¬²¢ÇÒÄú²»ÐèÒª¶Ô±äÁ¿
½øÐÐÉùÃ÷¡£Òª¸³Öµ¸øÒ»¸ö±äÁ¿£¬Äú¿ÉÒÔÕâÑùд£º
#!/bin/sh
#¶Ô±äÁ¿¸³Öµ£º
a="hello world"
# ÏÖÔÚ´òÓ¡±äÁ¿aµÄÄÚÈÝ£º
echo "A is:"
echo $a
ÓÐʱºò±äÁ¿ÃûºÜÈÝÒ×ÓëÆäËûÎÄ×Ö»ìÏý£¬±ÈÈ磺
num=2
echo "this is the $numnd"
Õâ²¢²»»á´òÓ¡³ö"this is the 2nd"£¬¶ø½ö½ö´òÓ¡"this is the "£¬ÒòΪshell»áÈ¥ËÑË÷±äÁ¿numndµÄÖµ£¬
µ«ÊÇÕâ¸ö±äÁ¿Ê±Ã»ÓÐÖµµÄ¡£¿ÉÒÔʹÓû¨À¨ºÅÀ´¸æËßshellÎÒÃÇÒª´òÓ¡µÄÊÇnum±äÁ¿£º
num=2
echo "this is the ${num}nd"
Õ⽫´òÓ¡£º this is the 2nd
1.1.4 »·¾³±äÁ¿
ÓÉexport¹Ø¼ü×Ö´¦Àí¹ýµÄ±äÁ¿½Ð×ö»·¾³±äÁ¿¡£ÎÒÃDz»¶Ô»·¾³±äÁ¿½øÐÐÌÖÂÛ£¬ÒòΪͨ³£Çé¿öϽö½öÔڵǼ
½Å±¾ÖÐʹÓû·¾³±äÁ¿¡£
1.1.5 ShellÃüÁîºÍÁ÷³Ì¿ØÖÆ
ÔÚshell½Å±¾ÖпÉÒÔʹÓÃÈýÀàÃüÁ
1)Unix ÃüÁî:
ËäÈ»ÔÚshell½Å±¾ÖпÉÒÔʹÓÃÈÎÒâµÄunixÃüÁµ«ÊÇ»¹ÊÇÓÉһЩÏà¶Ô¸ü³£ÓõÄÃüÁî¡£ÕâЩÃüÁîͨ³£ÊÇÓÃÀ´
½øÐÐÎļþºÍÎÄ×Ö²Ù×÷µÄ¡£
³£ÓÃÃüÁîÓï·¨¼°¹¦ÄÜ
echo "some text": ½«ÎÄ×ÖÄÚÈÝ´òÓ¡ÔÚÆÁÄ»ÉÏ
ls: ÎļþÁбí
wc –l filewc -w filewc -c file: ¼ÆËãÎļþÐÐÊý¼ÆËãÎļþÖеĵ¥´ÊÊý¼ÆËãÎļþÖеÄ×Ö·ûÊý
cp sourcefile destfile: Îļþ¿½±´
mv oldname newname : ÖØÃüÃûÎļþ»òÒƶ¯Îļþ
rm file: ɾ³ýÎļþ
grep 'pattern' file: ÔÚÎļþÄÚËÑË÷×Ö·û´®±ÈÈ磺grep 'searchstring' file.txt
cut -b colnum file: Ö¸¶¨ÓûÏÔʾµÄÎļþÄÚÈÝ·¶Î§£¬²¢½«ËüÃÇÊä³öµ½±ê×¼Êä³öÉ豸±ÈÈ磺Êä³ö
ÿÐеÚ5¸öµ½µÚ9¸ö×Ö·ûcut -b5-9 file.txtǧÍò²»ÒªºÍcatÃüÁî»ìÏý£¬
ÕâÊÇÁ½¸öÍêÈ«²»Í¬µÄÃüÁî
cat file.txt: Êä³öÎļþÄÚÈݵ½±ê×¼Êä³öÉ豸£¨ÆÁ


Ïà¹ØÎĵµ£º

linuxµÄÎļþºÍĿ¼

chmod £»ÐÞ¸ÄĿ¼ȨÏÞ
eg£ºchmod o-t /tmp
touch:´´½¨ÐÂÎļþ
rm -rf:ɾ³ýÎļþ
set gid ¶ÔĿ¼µÄ×÷ÓÃ
1£ºÄ¬ÈÏÇé¿öÏ£¬Óû§½¨Á¢µÄÎļþÊôÓÚÓû§µ±Ç°ËùÔÚµÄ×é
2£ºÄ¿Â¼ÉÏÉèÖÃÁËsetgid£¬±íʾÔÚ´ËĿ¼ÖУ¬ÈκÎÈ˽¨Á¢µÄÎļþ£¬¶¼»áÊôÓÚĿ¼ËùÊôµÄ×é¡£
rm -rf test  //ɾ³ý֮ǰµÄtestĿ¼
mkdir test // ÔÚµ±Ç°Ä¿Â¼´´½¨Ò ......

linux signalº¯Êý

CÓïÑÔÖеijéÏóº¯Êý¶¨ÒåÒ²¾ÍÊÇʹÓÃÁ˺¯ÊýÖ¸Õ룬ÕâÀïÓÃsignalº¯Êý½âÊÍһϳéÏóº¯Êý¶¨ÒåµÄº¬ÒåºÍ¹æÔò¡£
signalº¯Êý¶¨ÒåΪ£º
void (   * signal (int signum , void (*handler)(int)  )   )(int);
 
¿ÉÒÔÕâÑù¶¨Òå
typedef  void(* handler) (int)
handler signal(int signum,handler) ......

ǶÈëʽLinuxµÄͼÏñ²É¼¯ÓëÏÔʾ

1 ϵͳƽ̨µÄÓ²¼þ½á¹¹
±¾ÎÄʹÓõÄϵͳƽ̨Ӳ¼þ¹¦ÄÜ¿òͼÈçͼ1Ëùʾ£¬¸Ãƽ̨²ÉÓÃSamsung¹«Ë¾µÄ´¦ÀíÆ÷S3C2410¡£¸Ã´¦ÀíÆ÷ÄÚ²¿¼¯³ÉÁËARM¹«Ë¾ARM920T´¦ ÀíÆ÷ºËµÄ32b΢¿ØÖÆÆ÷£¬×ÊÔ´·á¸»£¬´ø¶ÀÁ¢µÄ16kBµÄÖ¸ÁîCacheºÍ16kBÊý¾ÝCache£¬LCD¿ØÖÆÆ÷¡¢RAM¿ØÖÆÆ÷£¬NANDÉÁ´æ¿ØÖÆÆ÷£¬3· UART¡¢4·DMA¡¢4·´øPWMµÄTimer¡¢²¢ÐÐI/O¿Ú¡¢8·10λA ......

±àÒëÒ»¸ölinuxÄÚºËÄ£¿é

¿´Ô´´úÂë¡£
#include <linux/kernel.h>
#include <linux/module.h>
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif
int init_module()
{
printk("Hello, I'm kernel\n");
return 0;
}
void cleanup_module()
{
printk("I'm kernel, bye\n");
} ......

linux²¶»ñKILLÃüÁîµÄÐźÅ

linuxÖÐÒ»¹²ÓÐ32ÖÖÐźţ¬ÔÚ/usr/include/bits/signum.h Í·ÎļþÖпÉÒÔ¿´µ½
#define    SIGHUP        1    /* Hangup (POSIX).  */
#define    SIGINT        2    /* Interrupt (ANSI).& ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ