Getting Started with Laser SLAM from Zero (2) - Ubuntu Basics

Hello everyone, I am a doctoral candidate in the direction of SLAM. I know the ups and downs of the SLAM learning process along the way, and I am very grateful to everyone for their high-quality articles and source code. With more and more knowledge, I am going to organize a column of my own laser SLAM study notes, from 0 to take everyone to quickly get started with laser SLAM, and it is also convenient for students who want to get started with SLAM and Xiaobai study reference, I believe you can read it There will be certain gains in the end. If there is something wrong, please point it out, and welcome everyone to exchange and discuss and make progress together.
  1. what is ubuntu

1.1 Introduction to Ubuntu

We generally need to build a project on Ubuntu to learn laser SLAM, and use ROS to transmit data. ROS is based on the Ubuntu operating system, so before installing and using ROS, you need to learn about the Ubuntu system. We will have a lot of inadaptability from the win we are used to to the ubuntu system at once. Learning the Ubuntu system patiently will improve a lot of efficiency and avoid many detours in the future.

Linux is a free, open, and free system software, and a multi-tasking and multi-user network operating system. It has good portability and runs widely on PCs, servers, workstations to mainframes, and various hardware devices including embedded systems, and is applicable to a wide range of platforms. It is open source, follows the spirit of the GPL, complies with the POSIX standard, and is a UNIX-compatible operating system. From another perspective, Linux is a set of UNIX-like operating systems that are free to use and spread freely. It can run on computers based on Intel x86 series processors and compatible chips from Cyrix and AMD.

Ubuntu is a Linux operating system mainly for desktop applications. A cooperative dedicated to creating free operating systems has created an operating system called Debian GNU/Linux, or Debian for short. The Debian system currently uses the Linux kernel. It is one of the few purely community-driven Linux distributions, not controlled by commercial companies or government agencies. It has the following advantages:

  1. Free and Open Source: Ubuntu is free and open source, allowing anyone to use, modify and distribute it freely.

  1. Stability and Security: Ubuntu is a very stable and secure operating system with a strong security architecture and an active community that quickly fixes any discovered vulnerabilities.

  1. Ease of use: Ubuntu has an intuitive user interface that is easy to use and configure. It also contains many pre-installed applications such as browsers, media players, document editors and more.

  1. Software Center: Ubuntu's Software Center provides a centralized location to find and install thousands of applications and tools, including many free and open source software.

  1. Community support: Ubuntu has a large community of developers, users, and volunteers who provide support and solve problems. This community will also provide a large number of documents and tutorials, making it easy for novices to learn and use Ubuntu.

Overall, Ubuntu is a powerful, stable, secure, easy-to-use and free operating system for individual users, businesses and developers. In Ubuntu, you can be the system master and modify it at will

1.2 Ubuntu system architecture

The difference between the Ubuntu system and the Win system is quite large. Unlike Win, which has several partitions, Ubuntu has only one root directory, and all files will be placed here. The overall file structure of the system is as follows. We just need to know the approximate function of each part at the beginning.

/ root directory

├boot/ startup file. All files related to system startup are saved here

│ └grub/ Grub boot loader related files

├dev/ device file

├proc/ kernel and process image

├mnt/ temporary mount

├media/ mount media device

├root/ $HOME directory of root user

├home/

│ ├user/ The $HOME directory of ordinary users

│ └.../

├bin/ system program

├sbin/ Administrator system program

├lib/ system library file

├etc/ System programs and global configuration files for most applications

│ ├init.d/ SystemV style startup script

│ ├rcX.d/ link to start script, define run level

│ ├network/ network configuration file

│ ├X11/ GUI configuration file

├usr/ system default installation file

│ ├bin/ Applications

│ ├sbin/ Administrator application

│ ├lib/ Application library files

│ ├share/ Application resource files

│ ├src/ Application source code

│ ├local/

│ │ ├soft/ User program

│ │ └.../ usually use separate folders

│ ├X11R6/ GUI system

├var/ dynamic data

├temp/ Temporary files

├lost+found/ disk repair file

1.3 Ubuntu installation

There are many online tutorials on how to install Ubuntu, so I won’t repeat them here. After installing Ubuntu, Xiaobai will generally be very confused in operation, and various problems will arise. Here you can refer to my previous blog, what needs to be done after installing Ubuntu.

https://blog.csdn.net/HUASHUDEYANJING/article/details/122572315

It should be noted that when we first installed the system, we needed to manually partition it. Many small partners did not know how many Gs were appropriate, resulting in insufficient system memory after a short period of time. Here are a few partitions that must be set.

  1. EFI boot area

Function: This partition is used for efi boot, so that the computer can find the ubuntu partition ( you need to open uefi boot in Bios )

Type: logical partition

Size: It is only the boot partition rather than the system partition, it does not need to be very large, set it to 500M

  1. SWAP virtual memory area

Function: virtual memory for data exchange with CPU, used for temporary data storage

Type: primary partition

Size: Usually set to twice the computer memory, my computer is 8G, so it is set to 16*1024M

  1. Mount point: / root directory

Function: used to store ubuntu system files, which is equivalent to the C drive of win

Type: logical partition

Size: Depends on the actual space size. Generally allocated 60-100GB

  1. Mount point: /home

Function: Store all files of the user

Type: logical partition

Size: As large as possible. In the directory structure diagram, /home belongs to the root directory /, but when setting partition memory separately, they are considered separately. It can be seen that /home has its own memory space and does not occupy /. You can see that there is only 42.9GB of remaining space in /home and 95.2G in /home

Using the baobab visualization space, you can see that /home and / are also calculated separately.

2. Important concepts of Ubuntu

2.1 Spatial distribution

  • Baobab可视化空间分布

端输入baobab,没有的话安装一下,sudo apt-get install baobab

  • df指令查看空间分布

df-h 以GB形式展示所有分区

df-h /home** 查看特定分区

  • free指令查看内存

free -h 查看内存

free -ht 查看总体内存

free -h -s 1 每间隔1s打印一次信息

2.2 权限介绍

在Ubuntu中,权限的概念显得尤为重要,在搞命令时候和搞工程时候都会用到权限。我这里暂且根据用到的场景分为命令权限、文件权限和串口权限。

  • 命令权限

Ubuntu系统输入命令的时候很多时候需要加sudo,也就是管理员权限,相当于win的以管理员身份启动。root账户即为超级管理员账户,对系统具有超级的管理能力,可以访问所有资源,当然包括删除等不可恢复的操作,因此,必须慎重使用,一般在备份恢复系统时候使用。进入root模式sudo su,退出输入exit。

  • 文件权限

在Ubuntu中,每个文件和目录都有一个所有者和一个所属组。Ubuntu中的权限分类如下:

读取权限(r):允许用户读取文件或目录的内容。

写入权限(w):允许用户修改文件或目录的内容。

执行权限(x):允许用户执行文件或进入目录。

这些权限可以针对用户、组或其他用户进行控制。例如,可以允许某个用户读取文件,但不允许修改它,或者允许某个用户执行某个文件,但不允许其他用户执行它。

在Ubuntu中,权限可以使用命令行工具chmod和chown进行更改。chmod用于更改文件或目录的权限,而chown用于更改文件或目录的所有者或所属组。这些命令需要使用超级用户权限(即root用户)才能进行更改。下面给出样例

将文件 myfile.txt 的所有者的读取权限设置为只读:

chmod u=r myfile.txt

将文件 myfile.txt 的所有者和所在组的读取和写入权限设置为读写:

chmod ug=rw myfile.txt

将文件 myfile.txt 的所有用户的执行权限设置为允许执行:

chmod a+x myfile.txt

其他命令:

sudo chmod 600 ××× (只有所有者有读和写的权限)
sudo chmod 644 ××× (所有者有读和写的权限,组用户只有读的权限)
sudo chmod 700 ××× (只有所有者有读和写以及执行的权限)
sudo chmod 666 ××× (每个人都有读和写的权限)
sudo chmod 777 ××× (每个人都有读和写以及执行的权限)
  • 设备权限

在Ubuntu中,设备权限是指对设备文件或目录的访问权限。这些权限确定了哪些用户可以访问设备文件或目录,以及可以执行哪些操作,如读取、写入和执行等。设备权限的主要用途如下:

  1. 安全性:设备权限可以限制用户的访问权限,防止非授权用户访问和更改设备文件或目录,从而保护系统的安全性。

  1. 权限控制:设备权限可以确定哪些用户可以访问设备文件或目录,并授予不同的用户不同的权限,从而确保用户只能执行他们被授权的操作。

  1. 设备管理:设备权限可以使系统管理员对设备进行更好的管理,例如在使用USB设备时,可以限制哪些用户可以访问USB设备,从而防止非法访问和恶意软件的攻击。

在Linux系统中,设备文件通常以 /dev 目录下的特殊文件的形式出现,这些特殊文件可以代表硬件设备(如串口、USB设备、声卡等)或软件设备(如终端设备)。通过设置设备文件的权限,可以控制用户对这些设备的访问权限,从而实现系统的安全性和稳定性。

sudo chmod 777 /dev/ttyACM0
/dev/ttyACM0 是一个代表 USB 串行设备的特殊文件路径。
chmod 命令用于更改文件或目录的权限。
777 将三个位都设置为 7 的意思是将读、写和执行权限都授予了所有用户,包括所有者、所属组和其他用户。

其他的特殊文件路径如下:

/dev/ttyS 代表标准串行接口(RS232)设备
/dev/ttyUSB 则代表USB串口设备
/dev/ttyACM:代表通过CDC(Communications Device Class)通信协议连接的设备,如Arduino开发板等。
/dev/ttyAMA:代表树莓派GPIO串口设备。
/dev/ttyHSL:代表海思芯片上的串口设备。
/dev/ttyTHS:代表Tegra处理器上的串口设备。
/dev/ttyLP:代表打印机串口设备。

2.3 bashrc与终端

首先我们在使用ubuntu的时候都逃避不了一个小黑框,它叫终端,利用ctrl+alt+t可以快速启动。.bashrc 文件是一个存在于 ubuntu 系统内,普通用户目录( / h o m e / d o n g ) 或 r oo t rootroot 用户目录( / r o o t ) (/root)(/root)下的隐藏文件。Linux 系统中很多shell,包括 b as h ,sh,zsh,dash和korn 等,不管哪种shell都会有一个.bashrc 的隐藏文件,它就相当于 shell 的配置文件。.bashrc 文件在每次打开新的终端时,都要被读取。简单的ls命令不会显示该文件,需要使用指令ls -al进行查看。这个文件主要保存一些终端配置和环境变量,例如:别名 alias、路径path等。

# 打开bashrc文件,在终端输入,没有gedit的安装一下sudo apt-get install gedit
sudo  gedit ~/.bashrc
# 更新bashrc,在终端输入
source ~/.bashrc

我们在使用阶段用到最多的bashrc的作用是3个,加环境路径,自定义命令,自启动命令。

1、加环境路径

一般安装第三方库文件的默认路径是/usr/local/lib,当你的安装路径与默认的不相同,需要在bashrc文件中添加路径,例如我自定义了opencv的安装路径。

sudo~/.bashrc
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/home/cxl/opencv-3.2.0/installed/lib/pkgconfig
exportPATH=$PATH:/home/cxl/opencv-3.2.0/installed/bin
exportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/cxl/opencv-3.2.0/installed/lib
source~/.bashrc

2、自定义命令

有时候输入很多重复且很长的命令是很烦人的,这时我们可以给命令起代号,之后输入代号就可以了,在bashrc文件中添加alias,即将 source/devel/setup.bash命令代号为sds

aliassds='source /devel/setup.bash'

3、自启动命令

有时我们在启动时需要首先输入一些命令,例如进入conda环境,每次都输入condaactivate yolo 是很麻烦的,这时我们在bashrc中直接添加你想要执行的命令,它将会在启动终端时候自动执行。

2.4 软连接

当我们需要在不同的目录,用到相同的文件时,我们不需要在每一个需要的目录下都放一个必须相同的文件,我们只要在某个固定的目录,放上该文件,然后在其它的目录下用ln命令链接(link)它就可以,不必重复的占用磁盘空间,只生成目标文件的一个镜像。ln命令会保持你每一处连接文件的同步性,不论更改源文件还是目标文件,另一处文件也会有相 同的改动。

ln -s file1 lnk1   #创建一个指向文件或目录的软链接,不占用空间
ln file1 lnk1   #创建一个指向文件或目录的硬链接,移动删除源文,硬链接不会被破坏。与软连接不同的是,硬链接会在你选定的位置上生成一个与原来文件大小相同的文件。无论是软连接还是硬链接都具有文件的同步性。
rm -rf  lnk1  #删除软连接

3、Ubuntu常用命令

3.1 文件路径

  • 路径目录指令pwb与cd

打开终端默认是在家路径下也就是/home/name

pwd——显示当前路径
cd /home——到/home路径
cd——回到初始路径也就是家路径
cd .. ——返回上一级路径
cd / ——到根目录
  • tree与ls

ls ——列出当前目录文件(不包括隐含文件)
ls -a—— 列出当前目录文件(包括隐含文件)
ll ——列出当前目录下文件的详细信息
tree——列出该目录的文件结构
tree -d—— 只列出文件,不显示文件
  • grep与locate查找文件的路径

locate *** ——查找包含***的所有文件路径
grep -rn **——查找文件内容包含**字样的路径

3.2 系统管理

  • 查看设备信息

uname -a ——查看内核版本
uname -m——显示机器的处理架构
sudo lshw -c video 显示显卡的信息;
cat /proc/cpuinfo ——查看cpu信息
lshw ——查看当前硬件信息
sudo fdisk -l ——查看磁盘信息
df -h ——查看硬盘剩余空间
free -m ——查看当前的内存使用情况
ps -A ——查看当前有哪些进程
kill ——进程号(就是ps -A中的第一列的数字)或者 killall 进程名( 杀死一个进程)
kill -9 ——进程号 强制杀死一个进程
sudo lshw -short 显示简略的所有硬件设备的信息。
lspci | grep -i nvidia——查看GPU版本
cat /etc/issue ——查看ubuntu版本
lsusb ——查看usb设备
  • 查看网络信息

sudo ethtool eth0—— 查看网卡状态
ifconfig ——查看ip与网络配置
ifconfig eth0 显示一个以太网卡的配置 
ifup eth0 启用一个 'eth0' 网络设备 
ifdown eth0 禁用一个 'eth0' 网络设备 
sudo service network-manager stop——关闭网络服务
sudo service network-manager start——启动网络服务
lshw -c network 查看网卡驱动
  • 关机重启

reboot——重启
shutdown -r now ——立刻重启
shutdown -r 10 ——过10分钟自动重启
shutdown -r 22:00 ——在时间为22:00时候重启

3.3 文件管理

  • 文件夹

mkdir a——建立a文件夹
rmdir 空目录名——删除一个空目录
rm 文件名 文件名——删除一个文件或多个文件
rm -rf 非空目录名——删除一个非空目录下的一切
touch b.cpp——创建一个b.cpp文件
rm -r  b.cpp   文件名——删除一个b.cpp文件
mv 文件  路径——移动一个文件到
cp -r 文件  路径——拷贝一个文件到
  • deb包命令

sudo dpkg -i “xxx.deb”——安装
sudo dpkg -r “xxx.deb” ——移除
sudo dpkg -info “xxx.deb” ——获取包相关信息
  • 压缩包命令

tar -cvf a.tar ./usb-cam——把usb-cam文件夹打包压缩包tar
tar -xvf a.tar——解压tar压缩包
tar -jxvf linux-source-5.4.0.tar.bz2——解压 tar.bz2
unzip a.zip -d a——把a.zip解压到a文件夹下
zip -r a.zip ./a——把a文件夹下的文件压缩成a.zip
unrar e a.rar—— # 解压rar压缩包到当前文件夹
rar -a filename.rar filename——压缩file成rar压缩文件

3.4 软件包管理

  • 软件包安装、删除

sudo apt-get install package ——安装包
apt-get install <<package name>>=<<version>>——安装制定版本
apt-cache madison <<package name>>——列出能够选择的版本
sudo apt-get install package ——reinstall 重新安装包
sudo apt-get -f install package——修复安装”-f = –fix-missing”
sudo apt-get remove package ——删除包
sudo apt-get remove package - - purge—— 删除包,包括删除配置文件等
sudo apt-get update ——更新源
sudo apt-get upgrade ——更新已安装的包
sudo apt-get dist-upgrade ——升级系统
sudo apt-get dselect-upgrade ——使用 dselect 升级
sudo apt-get build-dep package ——安装相关的编译环境
apt-cache search package ——搜索包
apt-cache show package ——获取包的相关信息,如说明、大小、版本等
apt-cache depends package ——了解使用依赖
apt-cache rdepends package ——是查看该包被哪些包依赖
sudo apt-get clean && sudo apt-get autoclean ——清理无用的包
sudo apt-get check ——检查是否有损坏的依赖
sudo apt-get clean ——清理所有软件缓存
sudo aptitude install  package——安装包及依赖
aptitude remove pkgname    ——删除包
aptitude purge pkgname——删除包及其配置文件

到这里你已经知道什么是Ubuntu和基本会使用Ubuntu了,下节内容将带你学习ROS

感谢各位小伙伴能读到这里,如有不清楚或不对的地方欢迎评论区讨论,博主也是初学者,按自己理解区解释,恳请各位理解,下一篇将很快到来~
如果喜欢就关注一下吧!

Guess you like

Origin blog.csdn.net/HUASHUDEYANJING/article/details/129708256