Basic knowledge of robot linux

Browse folder hierarchy

Install tree program:

sudo apt-get install tree

type:  

tree catkin_ws

If at any point you want to see the hierarchy of all folders under a particular folder, just type:

tree <path to the folder>

Navigate between folders

1.dir

Can display the files in the current folder

2.pwd

Check the path of this directory

3.cd..

Back to previous file

4. cd file

Go to a file at the next level

5. cd~sum cd

back to main file

6.ls

List all files in file (excluding hidden files)

7.ls -la

List all files (including hidden files)

Create folders and files

mkdir test_folder - create a folder

cd test_folder

touch new_file.txt - create a file

gedit new_file.txt - edit a file

Move files:

mv <file we want to move > <destination>

Copy files:

cp <file we want to copy > <destination>

Copy folder:

cp -r <file we want to copy > <destination>

Delete files/folders:

rm <file> 

rm -r <file>

Explore permissions in linux

 

Create a conflict script 

Linux has something called  bash scripting . Bash scripts are text files that can contain commands that we usually type manually in the Linux terminal. Then, when you want to run a set of commands, all you have to do is run the bash script (which contains the commands to execute)

New to a scripts script folder:

touch bash_scripts.sh - create bash scripts

gedit bash_scripts.sh

The first line of code tells linux that this is a bash script file

The second line of code should echo a sentence

chmod +x bash_scripts.sh Don't forget to add execution permission to the bash script

./bash_scripts.sh execute

pass parameters to bash script

touch demo.sh

gedit demo.sh

$1 means the first parameter. We can have $1, $2, $3...$N... depending on the number of arguments to be passed to the script. In the above example, we are passing only one parameter. This parameter is stored in the ARG1 variable.

 The fi  at the end of the if statement is required to close the if statement.

save document.

chmod +x demo.sh change execution permissions

./demo.sh AutomaticAddison runs and enters parameters

Browse the .bashrc file

In the main directory ls -la can find a .bashrc file

.bashrc is a special bash script that is always located in your home directory. It contains various commands, aliases, variables, configurations, settings and useful functions.

.bashrc scripts run automatically whenever you open a new terminal, window, or pane in Linux. However, if you have a terminal window open and want to re-run the .bashrc script, you must use the following command:

source .bashrc

explore environment variables

Open the terminal and enter export to see various environment variables

Environment variables are variables that describe the environment in which a program runs. Programs running on your computer use environment variables to answer questions like: What is the user name for this computer? What version of ROS is installed? Where is ROS installed? wait

There are many environment variables. How can we filter this list to only get variables containing ROS? Type the following command:

export | grabbed ROS

The ROS_PACKAGE_PATH variable tells system programs where to find ROS packages.

If at any time you want to change the value of a variable, use the following syntax:

export ROS_PACKAGE_PATH="<some new path>"

Among them, grep is very useful and can be used with other commands to filter the specified file name

For example: ls | grep hello This command will only select the file name with hello

process in linux

1. Foreground process

2. Background process

Start the foreground process:

ps wrong

Kill the process:

kill process number

The way to push the foreground process to the background process is ctrl z

Start the background process:

rosrun move_bb8_pkg hello_world.py & (just enter an & at the end of the command)

ctrl z and ctrl c are invalid for background processes, and the process can only be terminated by killing the process number

SSH protocol in linux

How to remotely control a 'server' computer from a client computer

sudo apt update

Server installation:

sudo apt install openssh-server

Client installation:

sudo apt install openssh-client

The server starts ssh:

sudo /etc/init.d/ssh start

Check to see if it works:

ps -e | grep ssh

If the startup is successful, it will contain sshd and ssh two programs.

You can set the server ssh to start automatically at boot

sudo systemctl enable ssh

The client connects to the server:

ssh account@ip address

exit exit

Guess you like

Origin blog.csdn.net/weixin_62705892/article/details/127037566