当前位置: 技术问答>java相关
怎样用JAVA程序把一个linux文件改变为其它用户的?
来源: 互联网 发布时间:2015-01-04
本文导语: | Try to execute linux commands such as "chown", "chggrp" and so on. Note: Make sure your program is running with root's identity. | 1.通过JAVA的Runtime类执行shell 程序 2.编辑shell,例如 # shell begin chown myAccount $1...
|
Try to execute linux commands such as "chown", "chggrp" and so on.
Note: Make sure your program is running with root's identity.
Note: Make sure your program is running with root's identity.
|
1.通过JAVA的Runtime类执行shell 程序
2.编辑shell,例如
# shell begin
chown myAccount $1
chgrp myAccount $1
# shell end
其中$1就是命令行参数,这里应该是文件名。
如果要改变一个目录下所有文件的权限可以加上参数 -R
chown -R myAccount $1
chgrp -R myAccount $1
3.编辑以后用chmod +x shell_file_name 加上可执行权限
2.编辑shell,例如
# shell begin
chown myAccount $1
chgrp myAccount $1
# shell end
其中$1就是命令行参数,这里应该是文件名。
如果要改变一个目录下所有文件的权限可以加上参数 -R
chown -R myAccount $1
chgrp -R myAccount $1
3.编辑以后用chmod +x shell_file_name 加上可执行权限