
public class Linux {
public static void main(String[] args) throws IOException {
//将根目录下的文件列出并将结果写入 /tmp/list.out
Process p = Runtime.getRuntime().exec("ls -al /")
InputStream in = p.getInputStream()
OutputStream out = new FileOutputStream("/tmp/list.out")
byte[] b = new byte[1024]
int r
while((r=in.read(b))>-1)
out.write(b,0,r)
out.flush()
out.close()
}
}
通过 ps --help a 查询ps的参数:
使用 ps axhw -o cmd 只输出Linux ps查询结果的CMD列,比如获取Jenkins容器进程中的CMD:
参考: https://stackoverflow.com/questions/65115463/how-to-print-only-cmd-from-ps-command-using-perl
命令:相关显示命令有sed,tail,cat.awk,head等,可以常看Linux命令大全,man命令或者help命令查看相关用法。我们只介绍其中的一部分。一、sed命令
#sed --help;查看具体使用规则:
#sed -n 'xp' filename;显示文件X行命令:
#sed -n 'x,yp' filename;显示文件X行到Y行的内容:
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)