We use the linux system daily through terminal commands, and often need to create files.
So what method (command) do you use to create files?
Let ’s share with you what commands I often use to create files in different scenarios
When I write a blog, I need to create some files for example files.
At this time, I use the linux touch command create an empty file.
➜ touch example.file
When we need to write a shell script, we need to open the file directly and write the script.
At this time, I will use the linux vim/vi command “Create file”.
➜ vim script.sh
# Enter the script code and save and exit.
Similar to scenario 2, when you need to rewrite existing code or optimize, you can use the linux cp command “Create file”.
Then, edit with vim command.
➜ cp ../vim/script.sh .
Redirect “>” or “>>”.
Creating files in this way is more used in text processing, such as filtering file contents, merging files, and so on.
1.After sorting the first column of the test.log file, create and write a new file.
2.Use echo, cat, head and other print commands to create a new file with redirection symbols and write the print.
➜ echo "hello, world" > test.log
The “>>“ symbol is an additional file content symbol, of course, it can also be used to create a new file.
➜ echo "hello, world" >> appendFile.log
3.Some display commands, such as linux date command
➜ date +'%Y-%m-%d-%H-%M-%S' > date.log
appendFile.log date.log test.log
➜ cat date.log
Linux common commands tutorial and use examples
Sed command tutorials in linux/unix with examples and use cases
Awk command tutorials in linux/unix with examples and use cases