Skip to content
Advertisement

Creating file and writing to it in one single command [closed]

right now, I’m doing the following operation, which takes me two iterations of typing into my ubuntu terminal.

$ touch someFile
$ ls > SomeFile

Using ls here is just an example of some program that outputs some text.

It seems a bit tedious that I need to first create the file, and then write to it, is there any way I can do this in one go, something along these lines (which does not work):

$ ls > touch ff

Thanks a lot for any tips

Advertisement

Answer

You do not have to create the file first before writing to it.

Just simply:

$ ls
$ echo "asdf" > myFile 
$ ls
myFile
$ cat myFile
asdf

Here is a reference that explains this in more detail

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement