There are several ways to create a file in Linux using the terminal.
Create an empty file:
Using redirection operators:
1 2 3 4 |
## Using redirection operators > myfile #or >> myfile |
Using touch command:
1 2 |
## Using touch touch myfile |
Using echo command:
1 2 |
## Using echo echo -n > file |
Create a file with some content:
Using echo command:
1 2 |
## Using echo echo "hello world" > myfile |
Using cat command:
1 2 3 4 |
## Using cat cat < hello world EOF |
Using output from another command:
1 2 |
## Using output of another command ps -aux > myfile |
Using terminal editor like vim:
1 2 |
## Uisng editor like vim vi myfile ## type i (insert mode) write some content and escape colon w (save) |