在命令行中:

1、su user -c "shell命令"。-c 后面跟shell命令

如su root -c "cd ~; touch 1.txt"

2、su user -s /bin/bash xxx.sh。-s 后面跟一个shell脚本

如 su root -s /bin/bash ./test.sh

test.sh内容如下:

#! /bin/bash

cd ~;

touch 1.txt;

mkdir tmp;

3、su user << EOF

xxx

xxx

EOF

 

在shell脚本中执行:

1、

 

2、

 

3、

 

相关文章:

  • 2021-06-05
  • 2021-07-19
  • 2021-12-10
  • 2021-06-13
  • 2022-12-23
  • 2022-01-15
  • 2021-10-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2021-08-29
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案