Javaµ÷ÓÃLinuxÃüÁîÐÐÈô¸ÉʵÀý
Executing a CommandSee also e90 Reading Output from a Command.
try {
// Execute a command without arguments
String command = "ls";
Process child = Runtime.getRuntime().exec(command);
// Execute a command with an argument
command = "ls /tmp";
child = Runtime.getRuntime().exec(command);
} catch (IOException e) {
}
If an argument contain spaces, it is necessary to use the overload that requires the command and its arguments to be supplied in an array:
try {
// Execute a command with an argument that contains a space
String[] commands = new String[]{"grep", "hello world", "/tmp/f.txt"};
commands = new String[]{"grep", "hello world", "c:\\Documents and Settings\\f.txt"};
Process child = Runtime.getRuntime().exec(commands);
} catch (IOException e) {
}
e90. Reading Output from a Commandtry {
// Execute command
String command = "ls";
Process child = Runtime.getRuntime().exec(command);
// Get the input stream and read from it
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
process((char)c);
}
in.close();
} catch (IOException e) {
}
e91. Sending Input to a Commandtry {
// Execute command
String command = "cat";
Process child = Runtime.getRuntime().exec(command);
// Get output stream to write from it
OutputStream out = child.getOutputStream();
out.write("some text".getBytes());
out.close();
} catch (IOException e) {
}
Ïà¹ØÎĵµ£º
LinuxÅäÖÃjava¿ª·¢Æ½Ì¨
Ò»¡¢°²×°jdk
1.ÏÂÔØ°²×°jdk
£¨1£©¡¢Ê×ÏÈ£¬ÔÚhttp://java.sun.com
ÕÒµ½ÒªÏÂÔصÄjdk£¬ÏÂÔØ×Ô¼ºÐèÒªµÄjdk°æ±¾¡£ÎÒÕâÀïʹÓõÄÊÇjdk6£¬µÃµ½µÄÊÇÒ»¸öÃûΪjdk-6u6-linux-i586-rpm.binµÄÎļþ¡£´ËÎļþµ±Ç°Îª²»¿ÉÔËÐеÄshell script¡£
£¨2£©¡¢¸ü¸ÄȨÏÞ£¬ÌáÈ¡jdk°²×°Îļþ£º
´ò¿ªÖÕ¶ËÔËÐ ......
ÔÎĵØÖ·
À¶É«±íʾĿ¼£»
ÂÌÉ«±íʾ¿ÉÖ´ÐÐÎļþ£»
ºìÉ«±íʾѹËõÎļþ£»
dzÀ¶É«±íʾÁ´½ÓÎļþ£»
»ÒÉ«±íʾÆäËüÎļþ£»
ºìÉ«ÉÁ˸±íʾÁ´½ÓµÄÎļþÓÐÎÊÌâÁË£»
»ÆÉ«ÊÇÉ豸Îļþ£¬°üÀ¨block, char, fifo¡£
ÓÃdircolors
-p¿´µ½È±Ê¡µÄÑÕÉ«ÉèÖ㬰üÀ¨¸÷ÖÖÑÕÉ«ºÍ“´ÖÌ唣¬Ï»®Ïߣ¬ÉÁ˸µÈ¶¨Òå¡£ ......
1 ¡¢°²×°Ç°µÄ×¼±¸
1.1 ¼ì²éÓ²¼þ
ÎïÀíÄڴ棺 # grep MemTotal /proc/meminfo
½»»»¿Õ¼ä£º # grep SwapTotal /proc/meminfo
½»»»¿Õ¼äµÄ´óСÊǸù¾ÝÎïÀíÄÚ´æµÄ´óСÀ´ÉèÖõģ¬ÎïÀíÄÚ´æÉÙÓÚ 2G µÄÔò½»»»¿Õ¼äÉèΪÎïÀíÄÚ´æµÄÁ½±¶£¬ÎïÀíÄÚ´æ´óÓÚ 2G µÄÔò½»»»¿Õ¼äºÍÎïÀíÄÚ´æ´óСһÑù¡£Èç¹û²»·ûºÏÉÏÊö¹æ¶¨£¬ÄÇô¾ÍÐèÒªÖØÐÂÉèÖý ......
×÷Òµ¹ÜÀí
1.½«“µ±Ç°”×÷Òµ·Åµ½ºǫ́“ÔÝÍ£”£ºctrl+z
2.¹Û²ìµ±Ç°ºǫ́×÷ҵ״̬£ºjobs
²ÎÊý£º
-l ³ýÁËÁгö×÷ÒµºÅÖ®ÍâͬʱÁгöPID
-r£ºÁгö½öÔÚºǫ́ÔËÐУ¨run£©µÄ×÷Òµ
-s£º½öÁгöÔÝÍ£µÄ×÷Òµ
3.½«ºǫ́×÷ÒµÄõ½Ç°Ì¨´¦Àí£ºfg
fg %jobnumber (%¿ÉÓпÉÎÞ)
4.ÈÃ×÷ÒµÔÚºǫ́ÔËÐУºbg
ctrl ......
ps -ef|grep tomcat ²é¿´ÕýÔÚÆô¶¯µÄÏß³Ì
cd .. ÍË»ØÉÏÒ»¼«
ls Áгöµ±Ç°Ä¿Â¼µÄÎļþ
kill -9 [Ï̺߳Å] ¹Ø±ÕÏß³Ì
su - root µÇ½Õ˺Å
ÔĶÁ(0)| ÆÀÂÛ(14)| ·ÖÏí(0) ½ÏÐÂһƪ:ת£º´øËÑË÷·ÖÒ³µÄgird ½Ï¾Éһƪ:·è×Ó ÆÀÂÛ| ÔÞ
ÖÜ˧ 2010-01-26 18:23
su - root µÇ½Õ˺Å
ÖÜ˧ 2010-01-26 19:53
......