[已解决]如何向root所属文件夹写入文件
- xyy_xx
- 帖子: 344
- 注册时间: 2008-09-17 13:37
- 系统: arch|centos
[已解决]如何向root所属文件夹写入文件
如题
正在写一个bash脚本。需要想/etc下写入一个配置文件。
尝试过cp mv
sudo cp,sudo mv
以及在tmp下生成文件再把owner和group换成root后弄到etc 下也不行
求解
正在写一个bash脚本。需要想/etc下写入一个配置文件。
尝试过cp mv
sudo cp,sudo mv
以及在tmp下生成文件再把owner和group换成root后弄到etc 下也不行
求解
上次由 xyy_xx 在 2012-04-30 0:56,总共编辑 2 次。
拥有书籍并不表示拥有知识;拥有知识并不表示拥有技能;拥有技能并不表示拥有文化;拥有文化并不表示拥有智慧
渣浪:@CodewalkerDotMe
推特:@codewalkertse
博客:http://codewalker.me/
渣浪:@CodewalkerDotMe
推特:@codewalkertse
博客:http://codewalker.me/
-
- 帖子: 5
- 注册时间: 2010-06-15 2:26
Re: 如何向root所属文件夹写入文件

- xyy_xx
- 帖子: 344
- 注册时间: 2008-09-17 13:37
- 系统: arch|centos
Re: 如何向root所属文件夹写入文件
不好意思是etc这个目录,手拙敲快了。hanla 写了:我也是小菜,不过我觉得应该是挂载/ 是以ro方式挂载的吧.remount 成rw,试一下.
谢谢各位了
上次由 xyy_xx 在 2012-04-30 0:43,总共编辑 1 次。
拥有书籍并不表示拥有知识;拥有知识并不表示拥有技能;拥有技能并不表示拥有文化;拥有文化并不表示拥有智慧
渣浪:@CodewalkerDotMe
推特:@codewalkertse
博客:http://codewalker.me/
渣浪:@CodewalkerDotMe
推特:@codewalkertse
博客:http://codewalker.me/
- lilydjwg
- 论坛版主
- 帖子: 4258
- 注册时间: 2009-04-11 23:46
- 系统: Arch Linux
- 联系:
Re: 如何向root所属文件夹写入文件
贴上脚本先。
- YeLee
- 论坛版主
- 帖子: 26406
- 注册时间: 2008-08-13 8:48
- 系统: Fundu i64
- 来自: 东海硇州,一双管钥。
- 联系:
Re: 如何向root所属文件夹写入文件
No such file or directory



◎当我站在道德的高度上俯视别人的时候,发现自己是多么渺小。
♥执着但不偏激,反对而不排斥,坚决捍卫矛盾体的存在方式。
★★★天气预报★★★
fcitx-yatable一个可以使用的码表输入法
[教程]几个实例攻克软件编译难关
Gentoo Development Guide
字体相关
♥执着但不偏激,反对而不排斥,坚决捍卫矛盾体的存在方式。
★★★天气预报★★★
fcitx-yatable一个可以使用的码表输入法
[教程]几个实例攻克软件编译难关
Gentoo Development Guide
字体相关
- xyy_xx
- 帖子: 344
- 注册时间: 2008-09-17 13:37
- 系统: arch|centos
Re: 如何向root所属文件夹写入文件
lilydjwg 写了:贴上脚本先。
代码: 全选
_net_config_file='/tmp/wireless-cfg';
read -p "Your ESSID ==>"cw
if [ -f $_net_config_file ];then
sudo echo '' > $_net_config_file;
else
sudo touch $_net_config_file;
fi
sudo echo "ESSID='$cw'" >> $_net_config_file;
read -p "Please type your wireless_password==> " wireless_password
sudo echo "KEY='$wireless_password'" >> $_net_config_file;
sudo echo "INTERFACE='wlan0'" >> $_net_config_file;
sudo echo "IP='dhcp'" >> $_net_config_file;
sudo echo "SECURITY='wpa'">> $_net_config_file;
cat $_net_config_file;#测试输出一下内容
sudo mv $_net_config_file /ect/network.d/wireless.cfg;
拥有书籍并不表示拥有知识;拥有知识并不表示拥有技能;拥有技能并不表示拥有文化;拥有文化并不表示拥有智慧
渣浪:@CodewalkerDotMe
推特:@codewalkertse
博客:http://codewalker.me/
渣浪:@CodewalkerDotMe
推特:@codewalkertse
博客:http://codewalker.me/
- xyy_xx
- 帖子: 344
- 注册时间: 2008-09-17 13:37
- 系统: arch|centos
Re: 如何向root所属文件夹写入文件
因为移动不过去 也复制不过去不知道为何会这样。很简单的一个问题,不知道卡在哪了短路所以上来问问YeLee 写了:No such file or directory![]()
![]()
你懂的。

拥有书籍并不表示拥有知识;拥有知识并不表示拥有技能;拥有技能并不表示拥有文化;拥有文化并不表示拥有智慧
渣浪:@CodewalkerDotMe
推特:@codewalkertse
博客:http://codewalker.me/
渣浪:@CodewalkerDotMe
推特:@codewalkertse
博客:http://codewalker.me/
- lilydjwg
- 论坛版主
- 帖子: 4258
- 注册时间: 2009-04-11 23:46
- 系统: Arch Linux
- 联系:
Re: 如何向root所属文件夹写入文件
1. 末尾不需要分号;xyy_xx 写了:lilydjwg 写了:贴上脚本先。代码: 全选
_net_config_file='/tmp/wireless-cfg'; read -p "Your ESSID ==>"cw if [ -f $_net_config_file ];then sudo echo '' > $_net_config_file; else sudo touch $_net_config_file; fi sudo echo "ESSID='$cw'" >> $_net_config_file; read -p "Please type your wireless_password==> " wireless_password sudo echo "KEY='$wireless_password'" >> $_net_config_file; sudo echo "INTERFACE='wlan0'" >> $_net_config_file; sudo echo "IP='dhcp'" >> $_net_config_file; sudo echo "SECURITY='wpa'">> $_net_config_file; cat $_net_config_file;#测试输出一下内容 sudo mv $_net_config_file /ect/network.d/wireless.cfg;
2. sudo 不是这么用的。sudo 用 root 权限执行了 echo 语句。但是,重定向是 shell 管的,而 shell 是普通用户权限。你可以用 sudo sh -c "echo xxx > yyy"。
另,为什么不不在脚本里使用 sudo,而让用户使用 sudo your_script 呢?
- xyy_xx
- 帖子: 344
- 注册时间: 2008-09-17 13:37
- 系统: arch|centos
Re: 如何向root所属文件夹写入文件
1写php习惯用;了lilydjwg 写了:1. 末尾不需要分号;xyy_xx 写了:lilydjwg 写了:贴上脚本先。代码: 全选
_net_config_file='/tmp/wireless-cfg'; read -p "Your ESSID ==>"cw if [ -f $_net_config_file ];then sudo echo '' > $_net_config_file; else sudo touch $_net_config_file; fi sudo echo "ESSID='$cw'" >> $_net_config_file; read -p "Please type your wireless_password==> " wireless_password sudo echo "KEY='$wireless_password'" >> $_net_config_file; sudo echo "INTERFACE='wlan0'" >> $_net_config_file; sudo echo "IP='dhcp'" >> $_net_config_file; sudo echo "SECURITY='wpa'">> $_net_config_file; cat $_net_config_file;#测试输出一下内容 sudo mv $_net_config_file /ect/network.d/wireless.cfg;
2. sudo 不是这么用的。sudo 用 root 权限执行了 echo 语句。但是,重定向是 shell 管的,而 shell 是普通用户权限。你可以用 sudo sh -c "echo xxx > yyy"。
另,为什么不不在脚本里使用 sudo,而让用户使用 sudo your_script 呢?
2脚本里面可以
代码: 全选
sudo sh -c "echo xxx > yyy"
拥有书籍并不表示拥有知识;拥有知识并不表示拥有技能;拥有技能并不表示拥有文化;拥有文化并不表示拥有智慧
渣浪:@CodewalkerDotMe
推特:@codewalkertse
博客:http://codewalker.me/
渣浪:@CodewalkerDotMe
推特:@codewalkertse
博客:http://codewalker.me/
- lilydjwg
- 论坛版主
- 帖子: 4258
- 注册时间: 2009-04-11 23:46
- 系统: Arch Linux
- 联系:
Re: 如何向root所属文件夹写入文件
设计问题?xyy_xx 写了: 3因为这个脚本里面还有其他的function是普通用户执行的不需要用到sudo
- xyy_xx
- 帖子: 344
- 注册时间: 2008-09-17 13:37
- 系统: arch|centos
Re: 如何向root所属文件夹写入文件
嗯对,脚本有点儿乱,记录的是一些常用方法。通过参数来调用不同的方法。稍候空了还是分成不同的文件算了。lilydjwg 写了:设计问题?xyy_xx 写了: 3因为这个脚本里面还有其他的function是普通用户执行的不需要用到sudo
还是感谢你,写这么久脚本居然被路径给困这么久 晕死
拥有书籍并不表示拥有知识;拥有知识并不表示拥有技能;拥有技能并不表示拥有文化;拥有文化并不表示拥有智慧
渣浪:@CodewalkerDotMe
推特:@codewalkertse
博客:http://codewalker.me/
渣浪:@CodewalkerDotMe
推特:@codewalkertse
博客:http://codewalker.me/