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命令
http://jythoner.javaeye.com/blog/290976
关键字: linux
1.查看系统内核
#uname -a
2.查看cpu信息
#cat /proc/cpuinfo
3.查看内存使用情况
#free -m
4.查看硬盘剩余空间
#df -h
5.查看目录占用空间
#du -hs 目录名
6.查看当前有哪些进程
#ps -A
7.查看当前进程的实 ......
许多刚接触Linux的网络管理员发现,他们很难由指向点击式的安全配置界面转换到另一种基于编辑复杂而难以捉摸的文本文件的界面。本文列出七条管理员能够也应该可以做到的步骤,从而帮助他们建立更加安全的Linux服务器,并显著降低他们所面临的风险。
请任何大型机构的网络管理员对Linux和网络操作系统(如Windows NT或No ......
磁盘与目录的容量
在文字接口底下查看目前的磁盘最大容许容量、已经使用掉的容量、 目前所在目录的已使
用容量
指令 df [-ahikHTm] [目录或文件名]
-a :列出所有的文件系统,包括系统特有的 /proc 等文件系统;
-k :以 KBytes 的容量显示各文件系统;
-m :以 MBytes 的容量显示各文件系统;
......
1、Apache
在如下页面下载apache的for Linux 的源码包
http://www.apache.org/dist/httpd/;
存至/home/xx目录,xx是自建文件夹,我建了一个wj的文件夹。
命令列表:
cd /home/wj
tar -zxvf httpd-2.0.54.tar.gz
mv httpd-2.0.54 apache
cd apache
./configure --prefix=/u ......
#pacman -S openssh #安装openssh
安装完成后在/etc/rc.conf的最底部DAEMONS后添加sshd让系统启动时自动启动openssh
DAEMONS=(syslog-ng network netfs crond sshd)
也可手动启动openssl,执行
#/etc/inin.d/sshd start
默认情况下其它电脑是不能通过ssh来访问archlinux的,需要修改两个文件来实现:
/etc/h ......