Linux Tips – File Create in Linux Command Line
This linux tutorial provides five different ways to create a file on the terminal using five different commands. They are
- Using cat command
- Using echo command
- Using printf command
- Using lolcat command
- Using tee command
1. Create file using cat command
- Cat command is used to create a file with help of output redirection operator named > on the linux terminal
- This will take only one argument which is the name of the file.
Syntax
cat > filename
Example
2. Create file using echo command
- Like cat command, echo command is also used to create a file with help of output redirection operator named > on the linux terminal
- This command will take message as argument and stored them into the given file with help of output redirection operator >
Syntax
echo message > filename
Example
NOTE
- Here option -e enables the special character \n. If you don’t mention -e then the newline will not be shown.
3. Create file using printf command
- Like echo command, printf command is also used to create a file with help of output redirection operator named > on the linux terminal
- This command will take message as argument and stored them into the given file with help of output redirection operator >
Syntax
echo message > filename
Example
4. Create file using lolcat command
- Like cat command, lolcat command is used to create a text file
- Like cat command this command will be used to create a file with help of output redirection operator >
- This command will take only one argument which is the filename
Syntax
lolcat > filename
Example
5. Create file using tee command
- Like cat, echo, printf commands, this command will create a text file on the linux terminal.
- Whatever typed using tee command will be stored in file as well as displayed in the terminal
- This command will take only one argument which is the name of the file name
Syntax
tee filename
Example