简体   繁体   中英

How to edit and move a file from one directory to another in one line in Linux?

Happy new year. I have a question. I want to modify and move a file in /etc/ansible directory to my home directory in one shot.

With sed command i removed the # and empty lines. Now I want to move ansible.cfg to my home directory in the same command.

~$ sudo sed -i.date +%F '/^\\s*#/d;/^$/d' /etc/ansible/ansible.cfg

Can you use a file descriptor redirection?

~$ sudo sed -i.date +%F '/^\\s*#/d;/^$/d' /etc/ansible/ansible.cfg > /path/to/destination

This won't remove or change the original file, however.

你可以这样尝试。

sudo sed -i.$(date +%F) '/^\s*#/d;/^$/d;w filename-in-your-home' /etc/ansible/ansible.cfg

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM