Hi all,
Just wanted to add my two cents to using Linux on the Pi’s. If you use the following rules then you are most likely to not fuck up stuff – and you can in Linux, especially as root or with sudo (superuser do).
Recommendations:
- Don’t run as root. We don’t really need it for our work. The Pi user (or your own if you have created one) will suffice.
- Don’t sudo unless you have to. Generally run commands without sudo first, if it doesn’t work without sudo you can type
-
$ sudo !!
(which will run the last command you just did with sudo).
Why:
If you are not 100% sharp on what you do you can ruin the OS or features.
Fx:
$ sudo ifconfig eth0 down
will stop the Ethernet port from running. Good luck connecting to the Pi with a cable again (if ssh daemon is running you can connect through wifi and set eth0 up).
Usefull stuff:
- Use “tab” key to autocomplete when using the CLI.
- cd (change directory):
- cd .. (go back one directory)
- cd – (go back to the directory you came from)
- cd ~ (go to /home/$YOUR_USER)
- And many more.
- Looking for something?
- find -name “your_search” (finding files)
- grep “your_search_pattern” (finding files or lines in files)
- What is in this directory?
- dir
- ls
- ls -lh
- The CLI is smart. It can run one-line scripts:
- for f in *.py; do echo “$f”; done
- Will loop over all files in current working directory that is called “something”.py
- for f in *.py; do echo “$f”; done
- Need more than one-line scripts?
- Use bash
- Create a file (e.g. touch “your_file”)
- Edit the file and add:
-
#!/bin/bash
at the top of the file
- Add you script to the file
- save the file and make it executable:
-
$ sudo chmod +x "your_file"
- Use bash
- * (asteriks) is a wildcard – it can be anything.