Welcome to RDK X3 Robot repository
2. Linux Basics
2. Linux Basics
2. Linux Basics2.1 Introduction to Linux2.2. Ubuntu Overview2.3. Ubuntu Filesystem2.4. Common commands2.4.1. Add2.4.2 Delete2.4.3. Change2.4.4 Search2.4.5 Others2.5. Editor2.5.1、vim2.5.2、nano2.5.3、gedit2.6、Ubuntu software operation commands
2.1 Introduction to Linux
Linux is an open source operating system whose kernel was first released by Linus Benedikt Torvalds on October 5, 1991. It inherits Unix's network-centered design idea and is a stable multi-user network operating system.
In March 1994, Linux 1.0 was released with 170,000 lines of code and was released under a completely free and free license, followed by the official adoption of the GPL.
In January 1995, Bob Young founded RedHat (Little Red Riding Hood), with GNU and Linux as the core, integrated more than 400 open-source program modules, and made a branded Linux, RedHat Linux, called Linux distribution, sold in the market.
In June 1996, the Linux 2.0 kernel was released to support multiple processors.
- Main features of Linux
Free and open source; Fully compliant with POSIX 1.0 standards; Multi-user, multi-task; Have a good interface; Multiple platforms are supported.
- Linux major version
There are currently about 300 Linux distributions, almost all of which can run as server systems. Linux distributions rarely copy each other, and the main popular Linux server distributions are 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 a wide range of processor architectures.
Debian: Debian runs extremely stable, which makes it ideal for servers.
CentOS: CentOS is an enterprise Linux distribution that is rebuilt using free source code from Red Hat Enterprise Linux. The refactoring completely removed the registered trademark and a very minor change in the Binary package.
Ubuntu: Ubuntu is a derivative of Debian that focuses on its application in this market and is common on servers, cloud computing, and even some mobile devices running Ubuntu Linux.
2.2. Ubuntu Overview
Ubuntu is a Linux operating system for desktop applications. Ubuntu is based on the Debian distribution and Gnome desktop environment, and as of 11.04, the Ubuntu distribution dropped the Gnome desktop environment in favor of Unity. Since Ubuntu 18.04 LTS, Ubuntu distributions have returned to using the GNOME3 desktop environment. On almost every Linux-related list, Debian-based Ubuntu has a place. Canonical's Ubuntu trumps all other Linux server distributions - from easy installation, excellent hardware discovery, to world-class commercial support, Ubuntu sets exacting standards that are hard to match
2.3. Ubuntu Filesystem
Unlike Windows, Ubuntu does not have the concept of a drive letter, only a root directory [/], where all files are located
xxxxxxxxxx├── bin # bin是Binary的缩写。存放系统中最常用的可执行文件(二进制)。 # bin is short for Binary. Store the most commonly used executable files (binary) in the system.├── boot # 这里存放的是linux内核和系统启动文件,包括Grub、lilo启动器程序。 # Here are the linux kernel and system boot files, including Grub, lilo launcher programs.├── dev # dev是Device(设备)的缩写。该目录存放的是Linux的外部设备,如硬盘、分区、键盘、鼠标、usb等。 # dev is short for Device. This directory stores Linux external devices, such as hard disks, partitions, keyboards, mice, and usb devices.├── etc # 这个目录用来存放所有的系统管理所需要的配置文件和子目录,如passwd、hostname等。 # This directory is used to store all the configuration files and subdirectories required by the system administration, such as passwd, hostname, etc.├── home # 用户的主目录,在Linux中,每个用户都有一个自己的目录,一般该目录名是以用户的账号命名的。 # The user's home directory. In Linux, each user has its own directory, usually named after the user's account.│ └── yahboom # 用户 # User│ ├── Desktop # 桌面 # Desktop│ ├── Documents # 文档 # Document│ ├── Downloads # 下载 # Download│ ├── Music # 音乐 # Music│ ├── Pictures # 图片 # Pictures│ ├── Public # 共享 # Share│ ├── Templates # 模板 # Template│ ├── Videos # 视频 # Template│ ...│ ... ├── lost+found # 这个目录一般情况下是空的,当系统非法关机后,这里就存放了一些零散文件。 # This directory is usually empty, when the system is illegally shut down, there are some scattered files stored here.├── lib # 存放共享的库文件,包含许多被/bin和/sbin中程序使用的库文件。 # Store shared library files, including many library files used by /bin and /sbin programs.├── media # ubuntu系统自动挂载的光驱、usb设备,存放临时读入的文件。 # The CD-ROM drive and usb device automatically mounted by the ubuntu system to store temporarily read files.├── mnt # 作为被挂载的文件系统得挂载点。 # As the mount point of the mounted file system.├── opt # 作为可选文件和程序的存放目录,主要被第三方开发者用来简易安装和卸载他们的软件。 # Serves as a directory for optional files and programs, mainly used by third-party developers to easily install and uninstall their software.├── proc # 这个目录是一个虚拟的目录,它是系统内存的映射,这里存放所有标志为文件的进程,比较cpuinfo存放cpu当前工作状态的数据。 # This directory is a virtual directory, which is a map of the system memory, where all the processes marked as files are stored, and compare cpuinfo to the current working status of the cpu.├── root # 该目录为系统管理员,也称作超级权限者的用户主目录。 # This directory is the home directory of the system administrator, also known as the super user.├── sbin # s就是Super User的意思,这里存放的是系统管理员使用的系统管理程序,如系统管理、目录查询等关键命令文件。 # s is the meaning of Super User, where the system administrator uses the system management program, such as system management, directory query and other key command files.├── srv # 存放系统所提供的服务数据。 # Store the service data provided by the system.├── sys # 系统设备和文件层次结构,并向用户程序提供详细的内核数据信息。 # System device and file hierarchy, and provide detailed kernel data information to user programs.├── usr # 存放与系统用户有关的文件和目录。 # Store files and directories related to system users.│ ├── bin # 用户和管理员的标准命令 # Standard commands for users and administrators│ ├── games # 存放着XteamLinux自带的小游戏 # Store XteamLinux's own mini games│ ├── include # 用来存放Linux下开发和编译应用程序所需要的头文件,c或者c++ # Used to store the header files needed to develop and compile applications under Linux, c or C ++│ ├── lib # 应用程序和程序包的连接库 # Connection libraries for applications and packages│ ├── local # 系统管理员安装的应用程序目录 # Application directory installed by the system administrator│ ├── sbin # 存放root超级用户使用的管理程序 # Store the hypervisor used by the root super user│ └── src # Linux开放的源代码 # Linux open source code│ └── share # 存放共享数据 # Store shared data│ ...├── var # 长度可变的文件,尤其是些记录数据,如日志文件和打印机文件。 # Files of variable length, especially recorded data such as log files and printer files.│ ├── backups│ ├── cache # 应用程序缓存目录 # Application cache directory│ ├── crash # 系统错误信息 # System error message│ ├── log # 日志文件 # Log file│ ├── mail # 电子邮件 # Email│ └── tmp # 临时文件目录 # Temporary file directory│ ...├── tmp # 这个目录是用来存放一些临时文件的,所有用户对此目录都有读写权限。 # This directory is used to store some temporary files, and all users have read and write permission to this directory.... 2.4. Common commands
2.4.1. Add
The new file
xxxxxxxxxxtouch test.txt
Creating a new folder
xxxxxxxxxxmkdir test # 创建一个文件 # Create a new filemkdir -p test/src # 创建test文件夹,并在test文件夹中创建src文件夹 # Create the test folder and create the src folder within the test folder复制
xxxxxxxxxxsudo cp test.txt test_copy.txt # 复制一个文件 # Copy a file 2.4.2 Delete
| -i | Execute in an interactive manner |
|---|---|
| -f | Delete files forcibly and ignore files that do not exist without prompting |
| -r | Recursively deletes the contents of the directory |
xxxxxxxxxxsudo rm test.txt # 删除文件 | 空文件夹 # Delete files | empty foldersudo rm -r test # 删除文件夹及文件夹里的内容 # Delete the folder and its contents2.4.3. Change
- mv Move, repeat name
xxxxxxxxxxsudo mv test test_new # 将test文件夹修改为test_newsudo mv test.txt test_new.txt # 将test.txt文件修改为test_new.txt- chmod modifies the file permission
Permission setting
| Symbol | Meaning |
|---|---|
| + | Add permission |
| - | Revoke permission |
| = | Set permission |
rwx
| Alphabetic permission | Meaning |
|---|---|
| r | read means can read permission, for a directory, if there is no r permission, then it means that the contents of the directory cannot be viewed through ls. |
| w | write indicates the writable permission. For a directory, if there is no w permission, it means that no new files can be created in the directory. |
| x | excute indicates executable permissions. For a directory, if there is no x permission, it means that the directory cannot be accessed through cd. |
xxxxxxxxxxsudo chmod +rwx test.txt
Add shortcuts for all permissions
xxxxxxxxxxsudo chmod 777 test.txt
- Change the password
Set the root password
xxxxxxxxxxsudo passwd root
Set the user name and password
xxxxxxxxxxsudo passwd 用户名
2.4.4 Search
- Viewing the system version
xxxxxxxxxxlsb_release -a # 发行版本号 # Release version numberuname -a # 内核版本及系统位数 # Kernel version and system numbercat /proc/version # 内核版本及gcc版本 # Kernel version and gcc version- Check the hardware information
xxxxxxxxxxcurl cip.cc 或者 ifconfig # 查看IP地址 # Check the IP addresscat /proc/cpuinfo or lscpu # cpu信息 # cpu informationsudo dmidecode -t memory # 内存信息 # Memory informationdf -h # 查看所有挂载的文件系统空间情况 # View all mounted file system spacewhich python3 # 查看命令位置 # View command locationv4l2-ctl --list-formats-ext # 查看相机设备参数 # View camera device parametersnproc # 查看内核数 # Check the number of cores- 查看文件信息
xxxxxxxxxxla # 显示指定目录下所有子目录与文件,包括隐藏文件 # Displays all subdirectories and files in the specified directory, including hidden filesll # 以列表方式显示文件的详细信息 # Displays file details in a listls -h # 配合以人性化的方式显示文件大小 # Cooperate to display file size in a user-friendly waycat test.txt # 查看文件内容 # View file contentstree # 查看文件目录(需要安装tree) # View the file directory (requires tree installation)tree安装命令
xxxxxxxxxxsudo apt install tree
- Find 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 with the suffix.sh in the current directoryfind ./ -name "[A-Z]*" # 查找当前目录下所有以大写字母开头的文件or目录 # Find all files or directories in the current directory that start with a capital letter2.4.5 Others
- tar command
tar Format: tar [parameter] Package file name file
xxxxxxxxxx-c # 生成档案文件,创建打包文件 # Generate archive file, create package file-v # 列出归档解档的详细过程,显示进度 # Lists the detailed process of archive decompression, showing the progress-f # 指定档案文件名称,f后面一定是.tar文件,所以必须放选项最后 # Specifies the name of the file, f must be followed by the.tar file, so you must put the option last-t # 列出档案中包含的文件 # Lists the files contained in the file-x # 解开档案文件 # Unpack the archive filePack
xxxxxxxxxxtar -cvf xxx.tar * # 当前目录所有文件 # All files in the current directorytar -cvf xxx.tar *.txt # 以.txt结尾的文件 # Files ending in.txttar -cvf xxx.tar my-file my-dir # 打包指定目录或文件 # Package the specified directory or fileUnpack
xxxxxxxxxxtar -xvf xxx.tar # 解包到当前目录 # Unpack to current directorytar -xvf xxx.tar -C my-dir # 解包到指定目录(需要先创建my-dir目录) # Unpack to specified directory (need to create my-dir directory first)- zip and unzip commands
zip file: zip [-r] target file (without extension) source file
xxxxxxxxxxzip bak * # 当前目录所有文件,也可以指定文件 # All files in the current directory, you can also specify fileszip -r bak * # 当前目录所有文件&目录递归 # All files in current directory & directories recursivelyUnzip file: unzip -d unzip the directory file to compress the file
xxxxxxxxxxunzip -d ./target_dir bak.zip # 解压到指定目录 # Unzip to the specified directoryunzip bak.zip # 解压到当前目录 # Unzip to the current directory- ln commands
Soft link: The soft link does not occupy disk space and becomes invalid when the source file is deleted. Commonly used, you can create files or folders
xxxxxxxxxxln -s 源文件 链接文件 #source file link fileHard link: Hard links can only link common 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 # From the remote replication directory to the 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 picture address in Baidu, as an example.
xxxxxxxxxxwget "https://img0.baidu.com/it/u=3911542037,2006161295&fm=224&fmt=auto&gp=0.jpg" # 下载普通文件(百度链接要加双引号) # Download ordinary files (Baidu link to add 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 file name- Other
xxxxxxxxxxnautilus . # 打开当前文件 # Open the current filecd ~ # 切换到当前用户的主目录(/home/用户目录) # Switch to the current user's home directory (/home/user directory)cd . # 切换到当前目录 # Switch to the current directorycd - # 可进入上次所在的目录 # Can go to the last directorycd / # 切换到系统根目录/ # Switch to system root /pwd # 显示当前路径 # Display the current pathecho "HelloWorld" # 向控制台输出HelloWorld信息 # Output HelloWorld message to consolewhich # 查看命令位置 # View command location2.5. Editor
2.5.1、vim
vim is an upgraded version of vi, and the most common difference is the ability to display some special information about system files in a variety of colors.
- Installation command
xxxxxxxxxxsudo apt install vim
- Three main modes
Command mode (Edit mode) : Default mode, move cursor, cut Paste text (interface performance: file name displayed in the lower left corner or empty) INSERT mode (Input mode) : Modify the text (- Insert - is displayed in the lower left corner). In the insert mode, press ESC to return to the command mode Last line mode (extended mode) : Save, exit, etc. (Interface performance: lower-left corner display - VISUAL -) Press the ESC button twice in the last line mode to return to the last line mode
- Mode switching
The command mode is changed to edit mode
xxxxxxxxxxi # 插入方式进入编辑模式 # Insert mode Enter edit modea # 追加方式进入编辑模式 # Append mode Enter edit modeo # 当前行下一行开始位置开始编辑 # Start editing at the start of the line below the current lineO # 当前行上一行开始位置开始编辑 # Start editing at the start of the current lineSwitch the command mode to the last line mode
xxxxxxxxxx: # 输入冒号【:】 # Enter colon [:]Switch to command mode: press [esc]
To switch to command mode: press [esc]
Esc Build: Exit to the current mode
Esc Build Esc Build: Always returns to command mode

- Last line pattern
xxxxxxxxxxw # 保存 # Saveq # 退出 # Exitq! # 强制退出 # Forced exitx # 保存并退出 # Save and exitset nu # 显示行号 # Show the line numberset # nonu 隐藏行号 # nonu hides the line number0,$d # vim 删除文件全部内容: # vim Delete the entire contents of the file:/string # 从光标处开始向后寻找字符串string;按n定位下一个,shfit+n定位上一个。 # Start at the cursor and look backwards for the string string; Press n to locate the next one, and shfit+n to locate the previous one.g/string # 检索string。使光标停止在第一个检索到的 string 串的行首。 # Retrieve string. Makes the cursor stop at the beginning of the first retrieved string line.- Command mode
xxxxxxxxxxyy # 复制 # Copyp # 粘贴 # paste3yy # 复制3行 # Copy 3 lines2p # 粘贴2遍 # twicedd # 剪切 # shear3dd # 剪切3行 # Cut 3 rowsu # 撤销 # undoCtrl + r # 反撤销 # undodd # 删除当前行 # Deletes the current rowdG # 删除当前行到文件末尾 # Deletes the current line to the end of the filedH # 删除当前行到文件开头 # Deletes the current line to the beginning of the filegg # 跳到当前文档首行 # Skip to the first line of the current documentG # 跳到当前文档末行 # Skip to the last line of the current document^ # 跳到当前行首 # Skip to the beginning of the current line$ # 跳到当前行尾 # jumps to the end of the current lineh # 左移一个字符 # Move one character leftj # 下移一行 # Move down one linek # 上移一行 # Move up one linel # 右移一个字符 # Move one character to the rightPageDown(或Ctrl+F) # 下翻一屏 # Scroll down one screenPageUp(或Ctrl+B) # 上翻一屏 # Scroll up one screen2.5.2、nano
nano is a text editor in Unix and Unix-like systems that is a copy of Pico.
- Install
xxxxxxxxxxsudo apt install nano
Create/open a file
xxxxxxxxxxnano 路径+文件名 Path + File nameeg:nano test_nano.txt
Control command
xxxxxxxxxxCtrl+v # 下一页 # Next pageCtrl+y # 上一页 # Previous pageCtrl+w # 搜索单词或短语 # Search for a word or phraseCtrl+x # 关闭当前文本,退出nano,返回shell # Closes the current text, exits nano, and returns to shellCtrl+\ # 搜索替换 # Search for replacementCtrl+k # 剪切文本行 # Cut the line of textCtrl+u # 粘贴文本行 # Paste lines of textCtrl+c # 显示光标在文本中的位置 # Displays 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 "Open" button to browse the list of recently opened files and open the files; Click the "Save" button to save the file currently being edited; Click on the menu bar on the right for more actions 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 only when the GEdIT editor can be displayed. The GedIT editor cannot be started remotely without a GUI, such as ssh, jupyter, and putty.
2.6、Ubuntu software operation commands
xxxxxxxxxxsudo apt-get update # 更新源 # Update sourcesudo apt-get install package # 安装包 # Install packagesudo apt-get remove package # 删除包 # Remove packagesudo apt-cache search package # 搜索软件包 # Search packagesudo apt-cache show package # 获取包的相关信息,如说明、大小、版本等 # Gets information about the package, such as description, size, version, etcsudo apt-get install package --reinstall # 重新安装包 # Reinstallsudo apt-get -f install # 修复安装 # Repair the installationsudo apt-get remove package --purge # 删除包,包括配置文件等 # Delete the package, including configuration files, etcsudo apt-get build-dep package # 安装相关的编译环境 # Install the relevant build environmentsudo apt-get upgrade # 更新已安装的包 # Updates the installed packagessudo apt-get dist-upgrade # 升级系统 # Upgrade the systemsudo apt-cache depends package # 了解使用该包依赖那些包 # Know which packages depend on using the packagesudo apt-cache rdepends package # 查看该包被哪些包依赖 # Shows which packages depend on the packagesudo 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 broken dependencies