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) {
}
相关文档:
今天遇到要导出数据库中表的数据。下面这个就可以搞定。。
#导出指定的表 #导出命令 -u用户名 -p密码 -h主机IP地址 数据库名 表名1 表名2 > 导出文件.sql
mysqldump -uroot -proot -h192.168.0.88 ok_db oktable1 oktable2 > ok_db.sql
另外在更改mysql密码时候,网上有些命令不对:
我用如下:set password=pas ......
今天安装了db2,忙了好一阵子,上网找资料等,终于装好了,下面就把我的步骤跟大家分享一下。
第一步:检查程序包及其版本
compat-libstdc++-7.3-2.96.118.i386.rpm
在linux的安装盘上,找到后使用rpm -i compat-libstdc++-7.3-2.96.118.i386.rpm 安装即可
第 ......
原文地址
蓝色表示目录;
绿色表示可执行文件;
红色表示压缩文件;
浅蓝色表示链接文件;
灰色表示其它文件;
红色闪烁表示链接的文件有问题了;
黄色是设备文件,包括block, char, fifo。
用dircolors
-p看到缺省的颜色设置,包括各种颜色和“粗体”,下划线,闪烁等定义。 ......
磁盘与目录的容量
在文字接口底下查看目前的磁盘最大容许容量、已经使用掉的容量、 目前所在目录的已使
用容量
指令 df [-ahikHTm] [目录或文件名]
-a :列出所有的文件系统,包括系统特有的 /proc 等文件系统;
-k :以 KBytes 的容量显示各文件系统;
-m :以 MBytes 的容量显示各文件系统;
......
安装OpenSSH
Ubuntu缺省没有安装SSH Server,使用以下命令安装:
sudo apt-get install openssh-server openssh-client
不过Ubuntu缺省已经安装了ssh client。
配置完成后重起:
sudo /etc/init.d/ssh restart
windows 客户端用putty连接命令shell模式 ......