Linux ½Å±¾±àд»ù´¡(Èý)
3) Á÷³Ì¿ØÖÆ
1.if
"if" ±í´ïʽ Èç¹ûÌõ¼þΪÕæÔòÖ´ÐÐthenºóÃæµÄ²¿·Ö£º
if ....; then
....
elif ....; then
....
else
....
fi
´ó¶àÊýÇé¿öÏ£¬¿ÉÒÔʹÓòâÊÔÃüÁîÀ´¶ÔÌõ¼þ½øÐвâÊÔ¡£±ÈÈç¿ÉÒԱȽÏ×Ö·û´®¡¢ÅжÏÎļþÊÇ·ñ´æÔÚ¼°ÊÇ·ñ¿É¶ÁµÈµÈ…
ͨ³£ÓÃ" [ ] "À´±íʾÌõ¼þ²âÊÔ¡£×¢ÒâÕâÀïµÄ¿Õ¸ñºÜÖØÒª¡£ÒªÈ·±£·½À¨ºÅµÄ¿Õ¸ñ¡£
[ -f "somefile" ] £ºÅжÏÊÇ·ñÊÇÒ»¸öÎļþ
[ -x "/bin/ls" ] £ºÅжÏ/bin/lsÊÇ·ñ´æÔÚ²¢ÓпÉÖ´ÐÐȨÏÞ
[ -n "$var" ] £ºÅжÏ$var±äÁ¿ÊÇ·ñÓÐÖµ
[ "$a" = "$b" ] £ºÅжÏ$aºÍ$bÊÇ·ñÏàµÈ
Ö´ÐÐman test¿ÉÒԲ鿴ËùÓвâÊÔ±í´ïʽ¿ÉÒԱȽϺÍÅжϵÄÀàÐÍ¡£
Ö±½ÓÖ´ÐÐÒÔϽű¾£º
#!/bin/sh
if [ "$SHELL" = "/bin/bash" ]; then
echo "your login shell is the bash (bourne again shell)"
else
echo "your login shell is not bash but $SHELL"
fi
±äÁ¿$SHELL°üº¬Á˵ǼshellµÄÃû³Æ£¬ÎÒÃǺÍ/bin/bash½øÐÐÁ˱Ƚϡ£
¿ì½Ý²Ù×÷·û
ÊìϤCÓïÑÔµÄÅóÓÑ¿ÉÄÜ»áºÜϲ»¶ÏÂÃæµÄ±í´ïʽ£º
[ -f "/etc/shadow" ] && echo "This computer uses shadow passwors"
ÕâÀï && ¾ÍÊÇÒ»¸ö¿ì½Ý²Ù×÷·û£¬Èç¹û×ó±ßµÄ±í´ïʽΪÕæÔòÖ´ÐÐÓұߵÄÓï¾ä¡£ÄúÒ²¿ÉÒÔÈÏΪÊÇÂß¼ÔËËãÖеÄÓë²Ù×÷¡£ÉÏÀýÖбíʾÈç¹û/etc/shadowÎļþ´æÔÚÔò´òÓ¡” This computer uses shadow passwors”¡£Í¬Ñù»ò²Ù×÷(||)ÔÚshell±à³ÌÖÐÒ²ÊÇ¿ÉÓõġ£ÕâÀïÓиöÀý×Ó£º
#!/bin/sh
mailfolder=/var/spool/mail/james
[ -r "$mailfolder" ]' '{ echo "Can not read $mailfolder" ; exit 1; }
echo "$mailfolder has mail from:"
grep "^from " $mailfolder
¸Ã½Å±¾Ê×ÏÈÅжÏmailfolderÊÇ·ñ¿É¶Á¡£Èç¹û¿É¶ÁÔò´òÓ¡¸ÃÎļþÖеÄ"from" Ò»ÐС£Èç¹û²»¿É¶ÁÔò»ò²Ù×÷ÉúЧ£¬´òÓ¡´íÎóÐÅÏ¢ºó½Å±¾Í˳ö¡£ÕâÀïÓиöÎÊÌ⣬ÄǾÍÊÇÎÒÃDZØÐëÓÐÁ½¸öÃüÁ
-´òÓ¡´íÎóÐÅÏ¢
-Í˳ö³ÌÐò
ÎÒÃÇʹÓû¨À¨ºÅÒÔÄäÃûº¯ÊýµÄÐÎʽ½«Á½¸öÃüÁî·Åµ½Ò»Æð×÷Ϊһ¸öÃüÁîʹÓá£Ò»°ãº¯Êý½«ÔÚÏÂÎÄÌá¼°¡£²»ÓÃÓëºÍ»ò²Ù×÷·û£¬ÎÒÃÇÒ²¿ÉÒÔÓÃif±í´ïʽ×÷ÈκÎÊÂÇ飬µ«ÊÇʹÓÃÓë»ò²Ù×÷·û»á¸ü±ãÀûºÜ¶à¡£
2.case
case :±í´ïʽ¿ÉÒÔÓÃÀ´Æ¥ÅäÒ»¸ö¸ø¶¨µÄ×Ö·û´®£¬¶ø²»ÊÇÊý×Ö¡£
case ... in
...) do something here ;;
esac
ÈÃÎÒÃÇ¿´Ò»¸öÀý×Ó¡£fileÃüÁî¿ÉÒÔ±æ±ð³öÒ»¸ö¸ø¶¨ÎļþµÄÎļþÀàÐÍ£¬±ÈÈ磺
file lf.gz
Õ⽫·µ»Ø£º
lf.gz: gzip compressed data, deflated, original filename,
last modified:
Ïà¹ØÎĵµ£º
Service Discovery Protocol(SDP)ÌṩһÖÖÄÜÁ¦£¬ÈÃÓ¦ÓóÌÐòÓз½·¨·¢ÏÖÄÄÖÖ·þÎñ¿ÉÓÃÒÔ¼°ÕâÖÖ·þÎñµÄÌØÐÔ¡£
·þÎñ·¢ÏÖÐÒé(SDP»òBluetooth SDP)ÔÚÀ¶ÑÀÐÒéÕ»ÖжÔÀ¶ÑÀ»·¾³ÖеÄÓ¦ÓóÌÐòÓÐÌØÊâµÄº¬Ò⣬·¢ÏÖÄĸö·þÎñÊÇ¿ÉÓõĺÍÈ·¶¨ÕâЩ¿ÉÓ÷þÎñµÄÌØÕ÷¡£SDP¶¨ÒåÁËbluetooth client·¢ÏÖ¿ÉÓÃbluetooth server·þÎñºÍËüÃǵÄÌØÕ÷µÄ·½·¨¡£ ......
VSFTPDµÄÉèÖÃÑ¡Ïî
¡¡¡¡VSFTPDµÄÅäÖÃÎļþ/etc/vsftpd/vsftpd.confÊǸöÎı¾Îļþ¡£ÒÔ“#”×Ö·û¿ªÊ¼µÄÐÐÊÇ×¢ÊÍÐС£Ã¿¸öÑ¡ÏîÉèÖÃΪһÐУ¬¸ñʽΪ“option=value”£¬×¢Òâ“=”ºÅÁ½±ß²»ÄÜÁô¿Õ°×·û¡£³ýÁËÕâ¸öÖ÷ÅäÖÃÎļþÍ⣬»¹¿ÉÒÔ¸øÌض¨Óû§É趨¸öÈËÅäÖÃÎļþ£¬¾ßÌå½éÉܼûºó¡£
¡¡¡¡VSFTPD°üÖÐËù´øµ ......
Linux 2.6 ×Ö·ûÉ豸Çý¶¯³ÌÐò
¡ð¡¢ËµÃ÷
±Ê¼ÇÊÊÓÃÓÚLinuxµÄ2.6.10ÒÔºóµÄÄںˡ£
±Ê¼ÇÒÔLinux
Device
Driver3ÌṩµÄscull³ÌÐò(scullĿ¼ÖеÄmain.cºÍscull.h)Ϊ¼Ç¼Ö÷Ïߣ¬²¢ÒÔ¸ÃÇý¶¯³ÌÐòÖеĸ÷ÖÖϵͳµ÷Óúͺ¯Êýµ÷ÓÃÁ÷³ÌΪ¼Ç
¼˳Ðò¡£±ÈÈ磬module_init( )ºÍmodule_exit(
)ΪÏà¶ÔÓ¦µÄÒ»¶Ôϵͳµ÷Óã¬Ò»°ãÊé¼®Öж¼»á·ÅÔÚÒ ......
1.1 Óï·¨»ù±¾½éÉÜ
1.1.1 ¿ªÍ·
³ÌÐò±ØÐëÒÔÏÂÃæµÄÐпªÊ¼£¨±ØÐë·½ÔÚÎļþµÄµÚÒ»ÐУ©£º
#!/bin/sh
·ûºÅ#!ÓÃÀ´¸æËßϵͳËüºóÃæµÄ²ÎÊýÊÇÓÃÀ´Ö´ÐиÃÎļþµÄ³ÌÐò¡£ÔÚÕâ¸öÀý×ÓÖÐÎÒÃÇʹÓÃ/bin/shÀ´Ö´ÐгÌÐò¡£
µ±±à¼ºÃ½Å±¾Ê±£¬Èç¹ûÒªÖ´Ðиýű¾£¬»¹±ØÐëʹÆä¿ÉÖ´ÐС£
Ҫʹ½Å±¾¿ÉÖ´ÐУº
±àÒë chmod +x filename ÕâÑù²ÅÄÜÓÃ./filena ......
1.1.5 ShellÃüÁîºÍÁ÷³Ì¿ØÖÆ
ÔÚshell½Å±¾ÖпÉÒÔʹÓÃÈýÀàÃüÁ
1)Unix ÃüÁî:
ËäÈ»ÔÚshell½Å±¾ÖпÉÒÔʹÓÃÈÎÒâµÄunixÃüÁµ«ÊÇ»¹ÊÇÓÉһЩÏà¶Ô¸ü³£ÓõÄÃüÁî¡£ÕâЩÃüÁîͨ³£ÊÇÓÃÀ´½øÐÐÎļþºÍÎÄ×Ö²Ù×÷µÄ¡£
³£ÓÃÃüÁîÓï·¨¼°¹¦ÄÜ
echo "some text": ½«ÎÄ×ÖÄÚÈÝ´òÓ¡ÔÚÆÁÄ»ÉÏ
ls: ÎļþÁбí
wc –l filewc -w filewc -c fi ......