Welcome to ROSMASTER R2 repository
02. Linux Basics
02. Linux Basics
2.1 Introduction to the Linux System
Linux is an open-source operating system whose kernel was first released by Linus Bennedict Tovaz on October 5, 1991. It inherits Unix's network-centered design idea and is a multi-user network operating system with stable performance.
In March 1994, Linux 1.0 was released with 170,000 lines of code, which was released under a completely free and free agreement, and then officially adopted the GPL.
In January 1995, Bob Young founded RedHat (Little Red Hat), with GNU, Linux as the core, integrating more than 400 open-source program modules, and came up with a branded Linux, i.e., RedHat Linux, which is called Linux distribution, and sold in the market.
In June 1996, the Linux 2.0 kernel was released, which can support multiple processors.
- Main features of Linux
Free and open source; fully compatible with the POSIX 1.0 standard; multi-user, multi-tasking; has a good interface; supports multiple platforms.
- Linux Main Versions
Currently there are about 300 Linux distributions, almost all of which can be run as server systems.Linux distributions rarely copy each other, and the popular Linux server distributions are mainly the following:
Red Hat Enterprise Linux (Red Hat Enterprise Linux): this is the first Linux distribution for the commercial market. It is available in server versions and supports numerous processor architectures.
Debian: Debian runs extremely stable, which makes it ideal for servers.
CentOS: CentOS is an enterprise Linux distribution that has been rebuilt using the free source code from Red Hat Enterprise Linux. This rebuild completely removes the registered trademarks as well as a very minor change in the Binary package.
Ubuntu: Ubuntu is a derivative of Debian, focusing on its use in this market, and is common on servers, cloud computing, and even some mobile devices running Ubuntu Linux.
2.2. Overview of Ubuntu
Ubuntu is a Linux operating system with a focus on desktop applications.Ubuntu is based on the Debian distribution and the Gnome desktop environment, and as of version 11.04, the Ubuntu distribution dropped the Gnome desktop environment in favor of Unity. As of Ubuntu 18.04 LTS, the Ubuntu distribution has reverted to using the GNOME3 desktop environment. Debian-based Ubuntu is on almost every Linux-related list, and Canonical's Ubuntu trumps every other Linux server distribution -- from easy installation and excellent hardware discovery to world-class commercial support. Ubuntu sets a rigorous standard that is hard to match.
2.3 The Ubuntu File System
Unlike Windows, Ubuntu does not have a disk drive, there is only a root directory [/], and all files are located under it.
xxxxxxxxxx├── bin # bin是Binary的缩写。存放系统中最常用的可执行文件(二进制)。 # bin is an abbreviation for Binary. Holds the most commonly used executable (binary) files on the system.├── boot # 这里存放的是linux内核和系统启动文件,包括Grub、lilo启动器程序。 # This is where the linux kernel and system boot files are stored, including the Grub and lilo bootloader programs.├── dev # dev是Device(设备)的缩写。该目录存放的是Linux的外部设备,如硬盘、分区、键盘、鼠标、usb等。 # dev is an abbreviation for Device. This directory holds Linux external devices, such as hard disks, partitions, keyboards, mice, usb, and so on.├── etc # 这个目录用来存放所有的系统管理所需要的配置文件和子目录,如passwd、hostname等。 # This directory is used to store all the configuration files and subdirectories needed for system administration, such as passwd, hostname, and so on.├── home # 用户的主目录,在Linux中,每个用户都有一个自己的目录,一般该目录名是以用户的账号命名的。# The user's home directory. In Linux, each user has a directory of his or her own, which is usually named after the user's account.│ └── yahboom # 用户 # Users│ ├── Desktop # 桌面 # Desktop│ ├── Documents # 文档 # Document│ ├── Downloads # 下载 # Download│ ├── Music # 音乐 # Music│ ├── Pictures # 图片 # Pictures│ ├── Public # 共享 # Shared│ ├── Templates # 模板 # Templates│ ├── Videos # 视频 # Video│ ...│ ... ├── lost+found # 这个目录一般情况下是空的,当系统非法关机后,这里就存放了一些零散文件。# This directory is normally empty, and when the system is shut down illegally, bits and pieces of files are stored here.├── lib # 存放共享的库文件,包含许多被/bin和/sbin中程序使用的库文件。 # Stores shared library files, containing many libraries used by programs in /bin and /sbin.├── media # ubuntu系统自动挂载的光驱、usb设备,存放临时读入的文件。 # Optical drive, usb device automatically mounted by ubuntu system to store temporary read-in files.├── mnt # 作为被挂载的文件系统得挂载点。 # Mount point for the mounted file system.├── opt # 作为可选文件和程序的存放目录,主要被第三方开发者用来简易安装和卸载他们的软件。# As a directory for optional files and programs, it is mainly used by third-party developers for easy installation and uninstallation of their software.├── proc # 这个目录是一个虚拟的目录,它是系统内存的映射,这里存放所有标志为文件的进程,比较cpuinfo存放cpu当前工作状态的数据。 # This directory is a virtual directory which is a map of the system memory, where all processes marked as files are stored. compare cpuinfo stores data about the current operating status of the cpu.├── root # 该目录为系统管理员,也称作超级权限者的用户主目录。# This directory is the user home directory for system administrators, also known as super-privileged individuals.├── sbin # s就是Super User的意思,这里存放的是系统管理员使用的系统管理程序,如系统管理、目录查询等关键命令文件。# s means Super User, where system administration programs used by system administrators are stored, such as system administration, directory lookup and other key command files.├── srv # 存放系统所提供的服务数据。# Store data on the services provided by the system.├── sys # 系统设备和文件层次结构,并向用户程序提供详细的内核数据信息。 # System device and file hierarchies and provides detailed kernel data information to user programs.├── usr # 存放与系统用户有关的文件和目录。 # Stores files and directories related to system users.│ ├── bin # 用户和管理员的标准命令 # Standard commands for users and administrators│ ├── games # 存放着XteamLinux自带的小游戏# Stores the games that come with XteamLinux.│ ├── include # 用来存放Linux下开发和编译应用程序所需要的头文件,c或者c++# Used to store the header files, c or c++, needed to develop and compile applications under Linux.│ ├── lib # 应用程序和程序包的连接库 # Connection libraries for applications and packages│ ├── local # 系统管理员安装的应用程序目录# Directory of applications installed by the system administrator│ ├── sbin # 存放root超级用户使用的管理程序 # Admin program for the root superuser│ └── src # Linux开放的源代码 # Linux open source code│ └── share # 存放共享数据 # Store shared data│ ...├── var # 长度可变的文件,尤其是些记录数据,如日志文件和打印机文件。 # Files of variable length, especially logged data such as log files and printer files.│ ├── backups│ ├── cache # 应用程序缓存目录# Application cache directory│ ├── crash # 系统错误信息 # System error messages│ ├── log # 日志文件 # Log files│ ├── mail # 电子邮件 # E-mail│ └── tmp # 临时文件目录# Directory of temporary documents│ ...├── tmp # 这个目录是用来存放一些临时文件的,所有用户对此目录都有读写权限。# This directory is used to store temporary files, and all users have read and write access to this directory.... 2.4 Common Commands
2.4.1 Add
New file
xxxxxxxxxxtouch test.txt
New Folder
xxxxxxxxxxmkdir test # 创建一个文件 # Create a filemkdir -p test/src # 创建test文件夹,并在test文件夹中创建src文件夹# Create the test folder and create the src folder in the test foldermake a copy of
xxxxxxxxxxsudo cp test.txt test_copy.txt # 复制一个文件# Copy a file2.4.2 Delete
| -i | in an interactive manner |
|---|---|
| -f | Forced deletion, ignoring non-existing files without prompting |
| -r | Delete the contents of a directory recursively |
xxxxxxxxxxsudo rm test.txt # 删除文件 | 空文件夹# Delete Files | Empty Folderssudo rm -r test # 删除文件夹及文件夹里的内容 # Delete folders and their contents2.4.3. Change
- mv move, rename
xxxxxxxxxxsudo mv test test_new # 将test文件夹修改为test_new # Change test folder to test_newsudo mv test.txt test_new.txt # 将test.txt文件修改为test_new.txt # Change the file test.txt to test_new.txt- chmod modifies file permissions
Permission settings
| symbolic | meaning |
|---|---|
| + | increase authority |
| - | revoke authority |
| = | Setting permissions |
rwx
| letter authority | meaning |
|---|---|
| r | read means readable permissions, for a directory, if there is no r permission, then it means that you can't view the contents of this directory through ls. |
| w | write denotes writable permissions, for a directory, if there is no w permission, then it means that no new files can be created in the directory. |
| x | excute denotes executable permissions, for a directory without x permissions, it means that the directory cannot be accessed by cd. |
xxxxxxxxxxsudo chmod +rwx test.txt
Add shortcuts to all permissions
xxxxxxxxxxsudo chmod 777 test.txt
- Modify password
Setting the root password
xxxxxxxxxxsudo passwd root
Set user name and password
xxxxxxxxxxsudo passwd 用户名
2.4.4. Check
- Check the system version
xxxxxxxxxxlsb_release -a # 发行版本号# Release version numberuname -a # 内核版本及系统位数# Kernel version and system bitscat /proc/version # 内核版本及gcc版本 # Kernel version and gcc version- Viewing Hardware Information
xcurl cip.cc 或者 ifconfig # 查看IP地址# View IP addresscat /proc/cpuinfo or lscpu # cpu信息# cpu informationsudo dmidecode -t memory # 内存信息 # Memory informationdf -h # 查看所有挂载的文件系统空间情况 # View space on all mounted file systemswhich python3 # 查看命令位置 # View command locationv4l2-ctl --list-formats-ext # 查看相机设备参数# View camera device parametersnproc # 查看内核数 # View kernel count- View file information
xxxxxxxxxxla # 显示指定目录下所有子目录与文件,包括隐藏文件 # Display all subdirectories and files in the specified directory, including hidden files.ll # 以列表方式显示文件的详细信息 # Display file details in a list ls -h # 配合以人性化的方式显示文件大小 # Work with displaying file sizes in a user-friendly waycat test.txt # 查看文件内容 # View the contents of the filetree # 查看文件目录(需要安装tree) # View file directories (requires tree to be installed)The tree installation command
xxxxxxxxxxsudo apt install tree
- Find a file
xxxxxxxxxxfind ./ -name test.sh # 查找当前目录下所有名为test.sh的文件or目录# Find all files or directories named test.sh in the current directoryfind ./ -name '*.sh' # 查找当前目录下所有后缀为.sh的文件or目录# Find all files or directories in the current directory with the extension .shfind ./ -name "[A-Z]*" # 查找当前目录下所有以大写字母开头的文件or目录# Find all files or directories in the current directory that begin with an uppercase letter2.4.5. Other
- The tar command
The format of tar is as follows: tar [parameter] Packaging filename file
xxxxxxxxxx-c # 生成档案文件,创建打包文件# Generate archive files, create packaged files-v # 列出归档解档的详细过程,显示进度# List the details of the archive unarchiving process, showing progress-f # 指定档案文件名称,f后面一定是.tar文件,所以必须放选项最后# Specify the name of the archive file, f must be followed by a .tar file, so it must be placed at the end of the options.-t # 列出档案中包含的文件# List the files contained in the archive-x # 解开档案文件 # Unlock the archive filepack
xxxxxxxxxxtar -cvf xxx.tar * # 当前目录所有文件# All files in current directorytar -cvf xxx.tar *.txt # 以.txt结尾的文件 # Files ending in .txt tar -cvf xxx.tar my-file my-dir # 打包指定目录或文件# Pack the specified directory or fileunpack
xxxxxxxxxxtar -xvf xxx.tar # 解包到当前目录 # Unpack to current directorytar -xvf xxx.tar -C my-dir # 解包到指定目录(需要先创建my-dir目录) # Unpack to a specified directory (you need to create the my-dir directory first)- zip, unzip commands
Zip file: zip [-r] target file (no extension) source file
xxxxxxxxxxzip bak * # 当前目录所有文件,也可以指定文件 # All files in the current directory, or you can specify a filezip -r bak * # 当前目录所有文件&目录递归 # All files in the current directory & directory recursionUnzip files: unzip -d Unzip directory files Compressed files
xxxxxxxxxxunzip -d ./target_dir bak.zip # 解压到指定目录# Unzip to a specified directoryunzip bak.zip # 解压到当前目录# Unzip to the current directory- The ln command
Soft links: Soft links do not take up disk space, and they become invalid when the source file is deleted. Commonly used, can be created for files or folders
xxxxxxxxxxln -s Source file Link fileHard links: Hard links can only link normal files, not directories. Even if the source file is deleted, the linked file still exists
xxxxxxxxxxln Source file Link file- scp remote copy
xxxxxxxxxxscp jetson@192.168.16.66:/home/jetson/xxx.tar.gz /home/yahboom/ # 从远程复制文件到本地 # Copy files from remote to localscp /home/yahboom/xxx.png jetson@192.168.16.66:/home/jetson/ # 从本地复制文件到远程 # Copy files from local to remotescp -r jetson@192.168.16.66:/home/jetson/test /home/yahboom/ # 从远程复制目录到本地 -r # Copy directory from remote to local -rscp -r /home/yahboom/test jetson@192.168.16.66:/home/jetson/ # 从本地复制目录到远程 -r # Copy directory from local to remote -r- wget file download
Search a random image address in Baidu as an example.
xxxxxxxxxxwget "https://img0.baidu.com/it/u=3911542037,2006161295&fm=224&fmt=auto&gp=0.jpg" # 下载普通文件(百度链接要加双引号) # Download common files (Baidu links should be in double quotes)wget -O yahboom.jpg "https://img0.baidu.com/it/u=3911542037,2006161295&fm=224&fmt=auto&gp=0.jpg" # 以指定文件名保存文件 # Save the file with the specified filename- other
xxxxxxxxxxnautilus . # 打开当前文件 # Open the current filecd ~ # 切换到当前用户的主目录(/home/用户目录)# Switch to the current user's home directory (/home/user directory)cd . # 切换到当前目录 # Switch to the current directorycd - # 可进入上次所在的目录 # Go to the last directory you were incd / # 切换到系统根目录/ # Switch to the system root directory /pwd # 显示当前路径# Display the current pathecho "HelloWorld" # 向控制台输出HelloWorld信息 # Output HelloWorld messages to the consolewhich # 查看命令位置# View command location2.5 Editor
2.5.1 vim
vim is the upgraded version of vi, the most common difference is that it can display some special information of system files in various colors.
- Installation commands
xxxxxxxxxxsudo apt install vim
- Three main models
Command Mode (Edit Mode): Default mode, move cursor, cut/paste text (interface performance: the lower left corner displays the file name or is empty) Insert Mode (Input Mode): Modify text (interface performance: the lower left corner shows -INSERT-) Insert Mode, press ESC to return to Command Mode. Last line mode (extended mode): save, exit, etc. (interface performance: the lower left corner displays -VISUAL-) under the last line mode, press the ESC key twice consecutively to return to the last line mode.
- Mode switching
Command Mode to Edit Mode
xxxxxxxxxxi # 插入方式进入编辑模式# Insertion into edit modea # 追加方式进入编辑模式# Add-on to edit modeo # 当前行下一行开始位置开始编辑# Start editing at the beginning of the next line below the current lineO # 当前行上一行开始位置开始编辑# Start editing at the beginning of the line above the current lineCommand mode switches to last line mode
xxxxxxxxxx: # 输入冒号【:】# Enter a colon [:]End-of-line mode to command mode: Press [esc].
Edit mode switch to command mode: press [esc]
Esc build: exit to current mode
Esc build Esc build: always return to command mode

- terminal phase
xxxxxxxxxxw # 保存 # Saveq # 退出 # Exitq! # 强制退出# Force exitx # 保存并退出# Save and exitset nu # 显示行号# Display line numberset # nonu 隐藏行号# nonu Hide line numbers0,$d # vim 删除文件全部内容: # vim deletes the entire contents of a file. /string # 从光标处开始向后寻找字符串string;按n定位下一个,shfit+n定位上一个。 # Find the string string backwards from the cursor; press n to locate the next one, shfit+n to locate the previous one.g/string # 检索string。使光标停止在第一个检索到的 string 串的行首。# Retrieves the string. stops the cursor at the beginning of the first retrieved string.- command mode
xxxxxxxxxxyy # 复制 # Copyp # 粘贴# Paste3yy # 复制3行 # Copy 3 lines2p # 粘贴2遍# Paste 2 timesdd # 剪切# Cut3dd # 剪切3行# Cut 3 rowsu # 撤销 # WithdrawnCtrl + r # 反撤销# Anti-revocationdd # 删除当前行 # Delete the current linedG # 删除当前行到文件末尾# Delete the current line to the end of the filedH # 删除当前行到文件开头 # Delete the current line to the beginning of the filegg # 跳到当前文档首行# Jump to the first line of the current documentG # 跳到当前文档末行# Jump to the last line of the current document^ # 跳到当前行首 # Jump to the beginning of the current line$ # 跳到当前行尾 # Jump to the end of the current lineh # 左移一个字符# Shift one character to the leftj # 下移一行 # Move down a linek # 上移一行 # Move up one linel # 右移一个字符# Shift one character to the rightPageDown(or Ctrl+F) # 下翻一屏 # Scroll down one screenPageUp(or Ctrl+B) # 上翻一屏# Flip up a screen2.5.2 nano
nano is a text editor for Unix and Unix-like systems that is a copy of Pico.
- Installation
xxxxxxxxxxsudo apt install nano
New/open file
xxxxxxxxxxnano Path + filenameExample: nano test_nano.txt
control command
xxxxxxxxxxCtrl+v # 下一页# Next pageCtrl+y # 上一页# Previous pageCtrl+w # 搜索单词或短语# Search for words or phrasesCtrl+x # 关闭当前文本,退出nano,返回shell# Close the current text, exit nano, return to shellCtrl+\ # 搜索替换# Search replacementsCtrl+k # 剪切文本行# Cut lines of textCtrl+u # 粘贴文本行 # Paste lines of textCtrl+c # 显示光标在文本中的位置 # Display the position of the cursor in the text2.5.3 gedit
gedit is not much different from Notepad in Windows.
In the editor, we can click the "Open" button to browse the list of recently opened files and open the file; click the "Save" button to save the file you are currently editing; click the menu bar on the right side to do more operations and so on. The shortcut keys are the same as in windows:
xxxxxxxxxxCtrl + s 保存文件 Save fileCtrl + Shift + s 另存为 save asCtrl + f 搜索文本内容 Search text contentThe gedit editor must be started in a situation where it can display the interface, not ssh, jupyter, putty and other remote start without interface.
2.6 Ubuntu software operation commands
xxxxxxxxxxsudo apt-get update # 更新源 # Update the sourcesudo apt-get install package # 安装包 # Installation packagessudo apt-get remove package # 删除包# Delete packagessudo apt-cache search package # 搜索软件包 # Search for packagessudo apt-cache show package # 获取包的相关信息,如说明、大小、版本等# Get information about the package, such as description, size, version, etc.sudo apt-get install package --reinstall # 重新安装包# Reinstall the packagesudo apt-get -f install # 修复安装# Repair installationsudo apt-get remove package --purge # 删除包,包括配置文件等# Delete packages, including configuration files, etc.sudo apt-get build-dep package # 安装相关的编译环境# Install the relevant compilation environmentsudo apt-get upgrade # 更新已安装的包 # Update installed packagessudo apt-get dist-upgrade # 升级系统 # Upgrade the systemsudo apt-cache depends package # 了解使用该包依赖那些包# Understand which packages are dependent on the use of this packagesudo apt-cache rdepends package # 查看该包被哪些包依赖 # See which packages this package depends onsudo apt-get source package # 下载该包的源代码# Download the source code for the packagesudo apt-get clean && sudo apt-get autoclean # 清理无用的包# Clean up useless packagessudo apt-get check # 检查是否有损坏的依赖 # Check for corrupted dependency packages