Learning More Command Line With Raspberry Pi

Reference

Working on my Raspberry Pi project. I’m doing a lot in its OS directly on the command line, since it’s easier and faster than using the Raspbian GUI (kind of a slow connection using remote desktop). In addition to working with bash shortcuts, I’ve learned some other things about bash scripting. Here are some of the things I’ve learned, as well as a general reference for useful commands working with a Raspberry Pi.

Open Raspbian terminal

~$ ssh pi@raspberrypi.local

Close Raspbian terminal

Ctrl + C

Open Raspberry Pi Raspbian config menu

pi:~ $ sudo raspi-config

List VNC Server Commands

pi:~ $ vncserver -help

Open VNC server to remote into Pi

pi:~ $ vncserver :1 -geometry 1920x1080 -depth 24

## alternative resolution if this is too janky:
pi:~ $ vncserver :1 -geometry 1280x720 -depth 24

Close the same VNC server

pi:~ $ vncserver -kill :1

Close the standard Raspbian GUI while on remote desktop

The remote desktop operates like a second screen, even if the Pi is not plugged in to make use of a first screen. So you may as well turn the first screen off—this saves memory and you’re not using it anyway.

pi:~ $ sudo service lightdm stop
# or restart:
pi:~ $ sudo service lightdm start

See and Manage Running Processes

This article gives a pretty good overview of how to figure out what processes are running (or hanging up) so that you can kill them if needed. The main useful things I learned are:

The default way to see all running processes:

$ top

There is also a more robust option available called htop which can be installed on Mac with:

$ brew install htop
$ htop

For either one, press ctrl + C to exit.

Copy files from a remote server to my local machine

This article is a comprehensive rundown of using the ssh and scp commands to work with remote servers. ssh lets you connect and manage a remote server, while scp let’s you copy files or directories from the remote server. I was focusing on scp:

$ scp -rp pi@192.168.0.97:/home/pi/Desktop/test\ images/timelapse-test-2/images2/ .

To break this down:

  • -r flag means recursive: all files in the selected directory will be copied. Alternative is to use an asterisk * at the end of the path
  • p flag means to preserve file information
  • pi@192.168.0.97 is the user & server location. IP address should be changed to whatever server you’re accessing
  • path needs to be from the server user root and must exist!
  • . at the end means copy the files to your present local directory, so make sure you’re in the place you want to copy the files to before running the command

Install AWS CLI For Easy File Transfers

sudo apt-get install awscli

Caveat from raspberry-projects.com: Amazon recommends using the pip package manager to install its awscli. However we prefer to keep things simple and have all our packages installed with one package manager APT. AWS states the awscli package is available in repositories for other package managers such as APT and yum, but it is not guaranteed to be the latest version unless you get it from pip or use the bundled installer. So use pip if you want the absolute latest, but APT is fine otherwise.

More things coming I’m sure, I’ll add them here later!