Linux Related
Subdirectories of Root Directory in Linux
Several subdirectories exist in the root directory. Some of them are listed below.
Directory | Description |
---|---|
/bin | It contains the essential binary files which are necessary for booting the system and running the basic commands. |
/boot | It contains the files needed for booting the system. |
/dev | It contains the device files for system devices such as hard drives, printers, and input-output devices. |
/etc | It contains system configuration files for various applications and services. |
/home | It contains the home directories of regular users. |
/lib | It contains the shared library files needed to run the programs on the system. |
/mnt | It is typically used as a mount point for temporarily mounting filesystems such as external hard drives, USB drives, and network file systems. |
/opt | It contains optional application software packages installed by the system administrator. |
/root | It contains the home directory of the root user. |
/sbin | It contains system binaries that are used for system administration tasks. |
/temp | It contains temporary files created by various programs and services on the system. |
/var | It contains variable data files such as log files and temporary files created by various programs and services on the system. |
dialout
将用户加入此分组可以以非root访问 /dev
sudo usermod -a -G dialout ${USERNAME}
根据标识符连接USB设备
-
查找设备的唯一标识符: 使用
udevadm
命令来查找设备的唯一标识符(如供应商 ID、产品 ID 和序列号)。udevadm info --name=/dev/ttyUSB0 --attribute-walk
这将显示设备的所有属性。查找包含
idVendor
、idProduct
和serial
的条目。 -
创建 udev 规则: 创建一个新的 udev 规则文件,例如 /etc/udev/rules.d/99-usb-serial.rules,并添加以下内容:
SUBSYSTEM=="tty", ATTRS{idVendor}=="XXXX", ATTRS{idProduct}=="YYYY", ATTRS{serial}=="ZZZZ", SYMLINK+="my_special_device"
将 XXXX 替换为设备的供应商 ID,将 YYYY 替换为设备的产品 ID,将 ZZZZ 替换为设备的序列号。my_special_device 是您希望为设备创建的符号链接名称。
-
重新加载 udev 规则: 重新加载 udev 规则并触发设备:
sudo udevadm control --reload-rules sudo udevadm trigger
-
在代码中使用符号链接: 在代码中使用符号链接名称来访问设备,而不是使用
/dev/ttyUSBX
。
自动启动 systemd
target.service example:
[Unit]
Description=Gesture Recognize Service
After=network.target
[Service]
ExecStart=/usr/bin/python3 /home/user/workspace/dh13_teleop/socket_server.py
WorkingDirectory=/home/user/workspace/teleop
StandardOutput=inherit
StandardError=inherit
Restart=always
User=paxini
Environment=PYTHONUNBUFFERED=1
Environment=LD_LIBRARY_PATH=/home/user/workspace/teleop/SDK/libs:$LD_LIBRARY_PATH
[Install]
WantedBy=multi-user.target
sudo cp ./target.service /etc/systemd/system/target.service
sudo systemctl daemon-reload
sudo systemctl enable target.service
# optional
sudo systemctl start target.service
sudo systemctl status target.service