[ROS Basic-2] Basic operation and basic commands of Ubuntu system

Series Article Directory

[ROS Basics-1] Linux system introduction and ubuntu installation (virtualbox) [ROS Basics-2] Ubuntu system basic operations and basic commands explained


Preface

In the previous blog, we took you to have completed the installation of ubuntu. If you want to master the Linux system, you need to master its related operations and basic shell commands. The following introduces the commonly used operations and commands when we learn ROS.


One, Linux basic operation

1. Replace the source

There are many ways to change the source.

The first method is to operate directly under the graphical interface. Click on the extension in the lower left corner, click on all, find "Software and Updates" and open and
Insert picture description here
click on other sites.
Insert picture description here
There are a variety of sources to choose from here. Bloggers are used to using Ali sources when they are not in school. They can use the sources of the University of Science and Technology of China on the school network. Click "Select Server".
Insert picture description here
Click close, this prompt appears, click close again, and enter the password.
Insert picture description here
So far, the source has been changed, but subsequent updates and upgrades are needed.

The second method is to use commands to replace the source.

  1. Backup source
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
  1. Open the sources.list file from the command line
sudo gedit /etc/apt/sources.list
  1. Modify the sources, list file, here is Ali source as an example, other sources can be found using CSDN
#  阿里镜像源

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

So far, the second method is to replace the source, but we still need to update and upgrade . Remember to perform this step after each source change

sudo apt-get update && sudo apt-get upgrade

Be sure to remember to connect to the Internet.

2. Software installation and uninstallation

The software installation and uninstallation under the graphical interface is relatively simple, here we will introduce the installation and uninstallation method through the terminal

(1) apt method

  • Ordinary installation
apt-get install softname1 softname2 …
  • Repair installation
apt-get -f install softname1 softname2... 
  • re-install
apt-get --reinstall install softname1 softname2...
  • Removal uninstall
apt-get remove softname1 softname2 …
  • Clean uninstall
apt-get --purge remove softname1 softname2...

For the installation and uninstallation of software packages that are often used in later ROS learning, apt is the method that needs to be used frequently.

(2) dpkg way

  • Ordinary installation
dpkg -i package_name.deb
  • Removal uninstall
dpkg -r pkg1 pkg2 ...
  • Clean uninstall
dpkg -P pkg1 pkg2...

(3) Source code installation

First decompress the source code compressed package and then use the tar command to complete

  • Solution xx.tar.gz
tar zxf xx.tar.gz 
  • Solution xx.tar.Z
tar zxf xx.tar.Z 
  • Solution xx.tgz
tar zxf xx.tgz 
  • Solution xx.bz2
bunzip2 xx.bz2 
  • Solution xx.tar
tar xf xx.tar

Then use the cd command to enter the decompressed directory. It is recommended to read the description file such as README first, because at this time there may be differences between different source code packages or precompiled packages, and then it is recommended to use the ls -F command (in fact, my Just need the ll command) to check the executable file, the executable file will be marked with * at the end.
Generally executed sequentially

./configure
make
sudo make install

The installation is complete.

3. Document editing

Document editing can be done in the terminal or in gedit under the graphical interface. In the terminal, you can use the vi command or the vim command. Of the two, vi is the system's own, and vim needs to be installed through apt. But the vim editor is relatively easy to use.

(1) gedit edit

In the graphical interface, you can double-click the document that needs to be edited, and the system will automatically open the document for editing with gedit. The editor is very similar to the familiar win document editor, which is not detailed here; in addition to double-clicking to open, you can also use commands Open the document for editing.

gedit [profile_name]

The gedit document editor is very convenient, but why do we still need to learn terminal editing, because we cannot use gedit to open documents due to special circumstances during the development process, such as remote links. At this time, we need to use terminal to edit documents.

(2) vi editing

The vi editor is a standard editor under all Unix and Linux systems. Basically vi can be divided into three states, namely command mode (command mode), insert mode (Insert mode) and bottom line mode (last line mode). The functions of each mode are as follows:

  • Command mode

  • Insert mode

  • Bottom line mode (last line mode)

There is not much introduction to the vi command here. If you are interested, you can check the detailed explanation of the vi command .

(3) vim editing

vim is a very powerful editor for Linux. Vim can be used as an upgraded version of vi, it can display some special information in a variety of colors.

The installation command for ubuntu18 installed through the previous blog without vim is as follows

sudo apt-get install vim

Several modes of Vim

  • Normal mode: You can use shortcut key commands, or press: to enter the command line.
  • Insert mode: You can enter text. In normal mode, press i, a, o, etc. to enter insert mode.
  • Visual mode: In normal mode, press v to enter visual mode. In visual mode, move the cursor to select text. Press V to enter the visible line mode, and the entire line is always selected. ctrl+v enter the visual block mode.
  • Replacement mode: In normal mode, press R to enter.

The vim command system is relatively large. If you are interested, you can refer to the vim operation command list . Later bloggers will also publish a special blog for a brief explanation of vim commands.

2. Basic commands

The command system of the Linux system is very broad, and it is still difficult to master them all. Here we will mainly introduce some commands that we often need to use in the process of learning ROS.

#Add Chinese as a comment, not the content of the instruction structure

1. Files and directories

cd /home 				#进入 '/ home' 目录' 


cd ..					#返回上一级目录 
cd ../.. 				#返回上两级目录 
cd 						#进入个人的主目录 
cd ~user1 				#进入个人的主目录 
cd - 					#返回上次所在的目录 
pwd 					#显示工作路径 
ls 						#查看目录中的文件 
ls -F 					#查看目录中的文件 
ls -l 					#显示文件和目录的详细资料 
ls -a 					#显示隐藏文件 
ls *[0-9]* 				#显示包含数字的文件名和目录名 
tree 					#显示文件和目录由根目录开始的树形结构
lstree 					#显示文件和目录由根目录开始的树形结构
mkdir dir1 				#创建一个叫做 'dir1' 的目录' 
mkdir dir1 dir2 		#同时创建两个目录 
mkdir -p /tmp/dir1/dir2 #创建一个目录树 
rm -f file1 			#删除一个叫做 'file1' 的文件' 
rmdir dir1 				#删除一个叫做 'dir1' 的目录' 
rm -rf dir1				#删除一个叫做 'dir1' 的目录并同时删除其内容 
rm -rf dir1 dir2 		#同时删除两个目录及它们的内容 
mv dir1 new_dir 		#重命名/移动 一个目录 
cp file1 file2 			#复制一个文件 
cp dir/* . 				#复制一个目录下的所有文件到当前工作目录 
cp -a /tmp/dir1 . 		#复制一个目录到当前工作目录 
cp -a dir1 dir2 		#复制一个目录 
cp -r dir1 dir2 		#复制一个目录及子目录
ln -s file1 lnk1 		#创建一个指向文件或目录的软链接 
ln file1 lnk1 			#创建一个指向文件或目录的物理链接 

2. File search

find / -name file1 		#从 '/' 开始进入根文件系统搜索文件和目录 
find / -user user1 		#搜索属于用户 'user1' 的文件和目录 
find /home/user1 -name \*.bin 		#在目录 '/ home/user1' 中搜索带有'.bin' 结尾的文件 

3. Users and groups

groupadd group_name 	#创建一个新用户组 
groupdel group_name 	#删除一个用户组 
groupmod -n new_group_name old_group_name 	#重命名一个用户组 
useradd -c "Name Surname " -g admin -d /home/user1 -s /bin/bash user1 	#创建一个属于 "admin" 用户组的用户 
useradd user1 			#创建一个新用户 
userdel -r user1 		#删除一个用户 ( '-r' 排除主目录) 
usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 	#修改用户属性 
passwd 					#修改口令 
passwd user1 			#修改一个用户的口令 (只允许root执行) 

4. File permissions-use "+" to set permissions, use "-" to cancel

ls -lh 					#显示权限 
ll	 					#显示权限 
chmod ugo+rwx directory1 	#设置目录的所有人(u)、群组(g)以及其他人(o)以读(r )、写(w)和执行(x)的权限 
chmod 777 directory1 	#设置目录的所有人(u)、群组(g)以及其他人(o)以读(r )、写(w)和执行(x)的权限 
chmod go-rwx directory1 	#删除群组(g)与其他人(o)对目录的读写执行权限 
chown user1 file1 		#改变一个文件的所有人属性 
chown -R user1 directory1 	#改变一个目录的所有人属性并同时改变改目录下所有文件的属性 
chgrp group1 file1 		#改变文件的群组 
chown user1:group1 file1 	#改变一个文件的所有人和群组属性 

5. Pack and compress files

tar -cvf archive.tar file1 		#创建一个非压缩的 tarball 
tar -cvf archive.tar file1 file2 dir1 	#创建一个包含了 'file1', 'file2' 以及 'dir1'的档案文件 
tar -tf archive.tar 			#显示一个包中的内容 
tar -xvf archive.tar 			#释放一个包 
tar -xvf archive.tar -C /tmp 	#将压缩包释放到 /tmp目录下 
tar -cvfj archive.tar.bz2 dir1 	#创建一个bzip2格式的压缩包 
tar -jxvf archive.tar.bz2 		#解压一个bzip2格式的压缩包 
tar -cvfz archive.tar.gz dir1 	#创建一个gzip格式的压缩包 
tar -zxvf archive.tar.gz 		#解压一个gzip格式的压缩包 
zip file1.zip file1 			#创建一个zip格式的压缩包 
zip -r file1.zip file1 file2 dir1 	#将几个文件和目录同时压缩成一个zip格式的压缩包 
unzip file1.zip 				#解压一个zip格式压缩包 

6. DEB package (Debian, Ubuntu and similar systems)

dpkg -i package.deb 	#安装/更新一个 deb 包 
dpkg -r package_name 	#从系统删除一个 deb 包 
dpkg -l 				#显示系统中所有已经安装的 deb 包 
dpkg -l | grep httpd 	#显示所有名称中包含 "httpd" 字样的deb包 

7. APT software tools (Debian, Ubuntu and similar systems)

apt-get install package_name 	#安装/更新一个 deb 包 
apt-cdrom install package_name 	#从光盘安装/更新一个 deb 包 
apt-get update 					#升级列表中的软件包 
apt-get upgrade 				#升级所有已安装的软件 
apt-get remove package_name 	#从系统删除一个deb包 
apt-get check 					#确认依赖的软件仓库正确 
apt-get clean 					#从下载的软件包中清理缓存 
apt-cache search searched-package 	#返回包含所要搜索字符串的软件包名称 

8. Network-(Ethernet and WIFI wireless)

ifconfig eth0 					#显示一个以太网卡的配置 
ifup eth0 						#启用一个 'eth0'网络设备 
ifdown eth0						#禁用一个 'eth0' 网络设备 
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 	#控制IP地址 
ifconfig eth0 promisc 			#设置 'eth0' 成混杂模式以嗅探数据包 (sniffing) 
dhclient eth0					#以dhcp模式启用 'eth0' 

to sum up

The above is the content of this blog, which mainly introduces the basic operations of Linux, including source replacement, software installation, etc. In addition, it also explains the basic commands commonly used in Linux systems for ROS learning.

ROS learning cannot be completed overnight. I will continue to publish notes about ROS learning. If there is anything wrong, please correct me. I wish you all become stronger!

Guess you like

Origin blog.csdn.net/qq_39502099/article/details/113357386
Recommended