To create an empty file:
Touch Akeke.log
Use Echo to create a new file and simply edit a file:
#echo "I am Wuyike" >wuyike.txt
Then use Cat view: #cat wuyike.txt
The difference between > and >>:
> is to empty and add new content, i.e. redirect
>> is to append a new content after the file content, that is, append redirect
Append content to a file with Cat: (Pros: Multiple lines of content can be added)
[email protected] ~]# cat >>wuyike.txt<<eof
> I am Beautiful
> EOF
View results:
[email protected] ~]# cat Wuyike.txt
I am Wuyike
I am Beautiful
Using cat to redirect files:(Pros: Multiple lines of content can be added)
[[Email protected] ~] #cat >wuyike.txt<<eof
> I am a Student
> EOF
View results:
[email protected] ~]# cat Wuyike.txt
I am a Student
You can also add multiple lines of content to a file using echo:
[Email protected] ~]# echo "Wuyike
> Wuyikeke ">>wuyike.txt
View results:
[email protected] ~]# cat Wuyike.txt
I am a Student
Wuyike
Wuyikeke
Correct output redirection: Code 1, using > or >>.
Error output redirection: Code 2, using 2> or 2>>. Make the error message in the file.
[Email protected] ~]# Ech wuyike 2>test.txt
[email protected] ~]# cat Test.txt
-bash:ech:command not found
Or:
[Email protected] ~]# echo 111 1>wuyike.txt 2>wuyike1.txt
[email protected] ~]# cat Wuyike.txt
111
[email protected] ~]# cat Wuyike1.txt
[Email protected] ~]#
[Email protected] ~]# Ech 111 1>wuyike.txt 2>wuyike1.txt
[email protected] ~]# cat Wuyike.txt
[email protected] ~]# cat Wuyike1.txt
-bash:ech:command not found
This article from "11805879" blog, declined reprint!
The use of cat and Echo in Linux