If you want to create a fine and write to it in a single command you can do it in various ways, one of the way is to use the echo command and use > redirect the text to a file, but doing so the file will be created and echoed text will be written to the file.
Example:
bash $ echo "This will be written to the file" > myFile.txt
bash $ cat myFile.txt
This will be written to the file

You can in this way also redirect the output of a command to a file.
Example:bash-3.2$ cd /
bash-3.2$ ls > /Users/code2care/Desktop/myFile.txt
bash-3.2$ cat /Users/code2care/Desktop/myFile.txt
Applications
Library
System
Users
Volumes
bin
cores
dev
etc
home
opt
private
sbin
tmp
usr
var
Comments:
- Thanks!
03 Jul 2022 17:07:05 GMT
- Further comments disabled!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!