Linux Commands

These are some useful Linux commands:

Local

Command Description
sudo chmod 666 /dev/ttyUSB0 Change permissions of a device file
sudo chown $USER /dev/ttyUSB0 Change ownership of a device file
sudo chmod +x file Make a file executable
sudo usermod -a -G dialout $USER Add user to the dialout group
/bin/udevadm info --name=/dev/ttyUSB0 Get information about a USB device
ls -l /dev/serial/by-id/ List serial devices by ID
usb-devices List USB devices
lsusb List USB devices
sudo dmesg | grep tty Check kernel messages for serial devices
sudo dmesg | grep usb Check kernel messages for USB devices
ifconfig Display network interface information

Remote / Server

Command Description
sudo reboot Reboot the system
sudo shutdown -h now Shutdown the system immediately
htop Interactive process viewer
top Display running processes
ps aux List all running processes
netstat -tuln Display listening ports and services
scp /from/host /to/host Securely copy files between hosts
----------- scp /local/file user@192.168.0.1:/home/user/path/to/dir/ Copy local file to remote directory
----------- scp user@192.168.0.1:/home/user/path/to/file /local/path/ Copy remote file to local directory

Tools

Command Description
python -m http.server 8000 Start a simple HTTP server on port 8000 [u can access it and download files]
convert -trim input.png output.png Trim whitespace from an image
pdftk input.pdf burst Split a PDF into individual pages [install sudo apt install pdftk-java]
pdftoppm input.pdf output -png Convert PDF pages to PNG images
pdfcrop input.pdf output.pdf Crop the white margins of a PDF file

Docker

Run a Docker container with GPU support

docker run --gpus all -it --rm -v $(pwd):/workspace -w /workspace pytorch/pytorch:2.5.1-cuda12.1-cudnn9-runtime /bin/bash
            

Explanation of the command:

If you started the container without --rm and want to leave it running in the background, press Ctrl + P, then Ctrl + Q in sequence. This detaches from the container and returns you to your host shell while the container continues running.

You can reattach later with:docker attach <container_id>

To check that the container is still running: docker ps

To stop a detached container: docker stop <container_id>

To remove it completely after it has stopped: docker rm <container_id>

Command Description
docker ps List running Docker containers
docker ps -a List all Docker containers (running and stopped)
docker stop <containerId> Stop a running Docker container
docker rm <containerId> Remove a stopped Docker container
docker cp :/file/path/within/container /host/path/target Copy files between a container and the host
docker images List Docker images
docker -help Display Docker help information
docker exec -it <containerId> bash Multiple Terminal