learning content from Mo python:linux TutorialNano
nano
is a text editing tool for Linux. We can use it to do the most basic terminal-end text editing, even write code ~ below we used to touch
create a Python script. We can nano
edit the text or script.
Then use nano
this file to execute t.py
.
$ nano t.py
He's going to be a text editor, and you can play some scripts in it, like me.
Then press "Ctrl + X" to save and exit. If you are prompted to save, you can click on the "Y" key and then enter and your file will be saved.
Then if you enter this in terminal, you can see that terminal executed your Python file.
$ python t.pyThis is a Python script!
Cat
cat
(catenate) can be used to display the contents of a file, or to write the contents of a file into other files. Let us illustrate.
1 Viewing the contents of a file
$ cat t.pyprint("This is a Python script!")
2 >
putting the contents of a file in another file
$ cat t.py > t1.py$ cat t1.pyprint("This is a Python script!")
3 >
Package The contents of multiple files together into another file
For example, here we put the content in the t.py
t1.py
same time t2.py
, if t2.py
it is displayed, it has two lines "Print ...".
$ cat t.py t1.py > t2.py$ cat t2.pyprint("This is a Python script!")print("This is a Python script!")
4 >>
Adding content to the end of a file
I created a t3
file that says "This is T3". Let's add this to the t2.py
bar. The end of the content that will be >>
added is t3
used t2.py
.
$ cat t3 >> t2.py$ cat t2.pyprint("This is a Python script!")print("This is a Python script!")This is t3.
Linux Learning notes: Nano and Cat