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
More Posts related to Linux,
- Terminal display next month Calendar
- How to change bash terminal prompt string and color
- How to exit from nano command
- How to Display content of a file in Terminal Screen?
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- 3 Commands to stop Nginx Server
- How to check file permissions for your file using Linux/Unix/macOS Terminal Command
- Create Hidden File or Directory using Shell Command
- bash: cls: command not found
- How to install python pip on Ubuntu using apt command
- The Date Command and its usage [Linux - Unix - macOS]
- SCP Copy all files from directory to Local Folder
- Create and write file in single Linux/macOS command
- Install OpenSSL on Linux/Ubuntu
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- Check SSH/OpenSSH version Command
- Execute .bin and .run file Ubuntu Linux
- What does apt-get update command does?
- How to ls command to output one entry per line [macOS/Linux/Bash]
- 3 ways to clear screen on Linux Terminal
- How to backup a file in Linux/Unix
- How to quit or exit SFTP Prompt on Terminal
- How to use SCP Command to Copy Directory
- zsh hello world example
- How to remove/delete a directory in Linux/macOs
More Posts: