Friday, May 3, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1498  / 2 Years ago, thu, december 23, 2021, 2:22:56

Is it possible to edit an existing text file using only one line of command and Nano. For instance if I have a text file called "new.txt" and I want to write "HELLO WORLD" in it. Can I do like this:



nano new.txt "something that will make it to write in that file "HELLO WORLD"


That is, can I write in a file using Nano without explicitly opening it in Nano. Yet only add something after the command nano (like -w for write) and the file name in the terminal.


More From » command-line

 Answers
1

Just use >> in your shell. This is a way of output redirection that will append to a file. In order to create the output, use the simple echo. E.g.



echo "Hello world." >> /path/to/file.txt


Alternatively, to create a new file (or to overwrite an existing one), use a single >, e.g.:



echo "Hello world." > /path/to/new/file.txt


One can use any command that create output to redirect it to a file like this. echo is just an example that outputs the argument(s) to stdout.


[#27440] Friday, December 24, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sator

Total Points: 258
Total Questions: 119
Total Answers: 101

Location: Sweden
Member since Fri, Apr 16, 2021
3 Years ago
;