簡體   English   中英

在Linux中,如何在一行中編輯文件並將文件從一個目錄移動到另一目錄?

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

新年快樂。 我有個問題。 我想一次將/etc/ansible目錄中的文件修改並移動到我的主目錄中。

使用sed命令,我刪除了#和空行。 現在,我想使用同一命令將ansible.cfg移至我的主目錄。

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

您可以使用文件描述符重定向嗎?

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

但是,這不會刪除或更改原始文件。

你可以這樣嘗試。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM