Common Commands in Linux and the vi/vim Editor
Common Commands in Linux
Most Raspberry Pi systems are based on Linux, and Linux is mostly operated by entering commands at the command line.
- View the system version:
cat /proc/version
- View the motherboard version:
cat /proc/cpuinfo
- Check the SD memory card's remaining space:
df -h
- Check the IP address:
ifconfig
- Compress: tar -zcvf filename.tar.gz dirname
- Decompress: tar -zxvf filename.tar.gz
- The apt (Advanced Package Tool) is commonly used on Linux systems to install software
sudo apt-get install xxx #Install the software. sudo apt-get update Update #the software list. sudo apt-get upgrade Update #the installed software. sudo apt-get remove xxx #Removes the software.
For example: Run the following two commands to install sl,cmatrix:
sudo apt-get install sl sudo apt-get install cmatrix
Run the following commands after installing:
sl cmatrix
"sudo" is to add user privileges, adding "sudo" in front of the command line is to run this command as "root" user. You can run "sudo su" to switch directly to the "root" user to operate. I personally like to log in as the normal user." $" is the normal user and "#" is the super user.
pi@raspberrypi ~ $ sudo su root@raspberrypi:/home/pi# su pi pi@raspberrypi ~ $
vi/vim Editor
Common editing tools in Linux are nano, vi/vim (vim is an advanced version of vi), and so on. Beginners are recommended to use the nano editor, easy to use. I personally prefer to use the vi/vim editor, if you want to use the vi editor first have to reinstall the vi editor because the raspberry pi that comes with an editor is not good.
First, delete the default vi editor:
sudo apt-get remove vim-common
And then reinstall vim:
sudo apt-get install vim
For ease of use, you must also add the following three sentences to the end of the /etc/vim/vimrc file:
set nu #Display line numbers syntax on #syntax highlighting set tabstop=4 #tab back four frames
As shown below:
vi has 3 modes: insert mode, command mode, and last line mode.
- Insert mode: you can type characters in this mode, pressing ESC will return to command mode.
- Command mode: you can move the cursor, delete characters, etc.
- Last line mode: you can save the file, exit vi, set vi, find, and other functions (low line mode can also be seen as in command mode).
Open file, save, close file (used in vi command mode):
vi filename //open filename file :w //Save the file :q //exit the editor, if the file has been modified use the following command :q! //exit the editor without saving :wq //exit the editor and save the file
Insert text or line (vi command mode to use, after the execution of the following command will enter the insertion mode, press the ESC key to exit the insertion mode).
a //add text to the right of the current cursor position i //Add text to the left of the current cursor position A //Add text at the end of the current line I //Add text at the beginning of the current line (non-blank character at the beginning of the line) O // add a new line above the current line o // in the current line below the new line R // replace (overwrite) the current cursor position and a number of text behind J //Merge the line where the cursor is and the next line (still in command mode)
Delete, and restore characters or lines (used in vi command mode)
x //delete the current character nx //delete the n characters from the start of the cursor dd //Delete the current line ndd //Delete n lines including the current line down u //undo the previous operation U //undo all operations on the current line
Paste (used in vi command mode)
yy //copy the current line to the buffer nyy //Copy the current line n lines down to the buffer yw //Copy the characters from the beginning of the cursor to the end of the word nyw //copy n words from the cursor y^ //copy from the cursor to the beginning of the line y$ //copy from the cursor to the end of the line p //paste the contents of the clipboard after the cursor p //Paste the contents of the clipboard before the cursor
Set the line number (used in vi command mode)
:set nu //Display line number :set nonu //Undisplay line number
Newcomers to vi may not be used to it, but they will slowly get used to it after being abused more. By the way, remind me that the Linux system is case-sensitive.