Code Done Right!

Basic commands

This is the list of basic commands of the Command Line Interface (CLI) that you need to familiarize yourself with, in order to comfortably work on your server.

RaspbianOS is a fork of GNU/Linux Debian, which means that commands are compatible between those systems, excluding Raspberry specific like vcgenmod. If you need more help and examples of those commands then you can search for Debian topics as well, not only Raspbian. Moreover, one of the most popular distributions, Ubuntu, is also a fork of Debian which means that you can also search for help looking through Ubuntu tutorials.

In general, you can apply all tutorials on this site to a normal PC running Debian. Who knows, maybe after learning a thing or two you will set up a more powerful home server runnung Debian?

List of basic commands

To the best of my abilities I will try to guide you so that you will not have to research commands on your own, but just in case here is the list so that you know what said commands actually do. Sidenote, they all come with the system so you do not have to install additional packages.

  • man – shows manual entry for a given command, your most important command!
man apt
  • sudo – act as root, needed for most work
sudo apt update
  • apt – used to install, remove or upgrade packages, either from repository or from a local directory, has other uses as well
sudo apt upgrade
  • ls – lists the contents of a directory
ls /var
  • touch – create an empty file, can be used to alter save time of the file
touch ~/some_file.txt
  • cp – copy files or folders
cp /home/username/mypage.html /var/www/mypage.html
  • mv – move, used for renaming as well
mv ~/my_file.txt ~/my_file_with_new_name.txt
  • wget – download a file to the current directory
wget http://wordpress.org/latest.tar.gz
  • dd – copy/clone from one place to another, e.g. takes an .img image and flashes it on SD card
sudo dd bs=4MB if=/$path_to_raspbian.img of=/dev/sdb
  • chmod – change read, write, execute permissions of a file or folder
sudo chmod -R 775 /var/www/mypage
  • chown – change owner of a file or folder
sudo chown -R www-data:www-data /var/www/mypage
  • adduser – add user, creates home directory as well
sudo adduser my_new_user
  • removeuser – removes user, home directory remains
sudo removeuser my_new_user
  • reboot – reboots the system
sudo reboot now
  • shutdown – shuts down the system so that it is safe to unplug power, do NOT just unplug the power supply as it may damage the card!
sudo shutdown now
  • dhclient – allows a host to contact a central server i.e. connect your computer to router (not useful on raspberry as it automatically connects, keeping it here for myself)
dhclient
  • netstat -lntp – check ports on which active services are listening
sudo netstat -lntp
  • ping – test if a host can be reached, target has to have a ping client installed
ping google.com
  • Ctrl+C – keyboard shortcut to stop the current command, some commands will run until you tell them to stop, like ping for example, this will abort the command

My tutorials will assume you are using NANO text editor. It is installed with your system. Familiarize yourself with the following shortcuts, that are used in the editor. I will not prompt you for saving and closing files.

  • Ctrl+x – Close file
  • Ctrl+o – Save file
  • Ctrl+k – Cut line
  • Ctrl+u – Paste the cut line
  • Ctrl+SHIFT+v – Paste

For more information about basic commands visit Official Debian Wiki

If I missed a command used in tutorials or you think I should just include something here, feel free leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.