For Raspian Beginners: The Article

The Essential Raspbian Guide for Beginners
Notes on Navigating the Raspian OS Environment(s) on Raspberry Pi

*In some of what follows the commands are character specific including <spc> for space because in print it is sometime difficult to tell if a string does or does not include a space.

8 “Emergency” Pieces of Knowledge You Need to Begin
(besides the fact that much of what is on the web is not current)

1. You cannot trust much of what you find on the internet to be accurate or lucid.
2. Raspian (or any flavor of a Unix-derived operating system) is case sensitive.
3. If you get stuck in something in a command-line environment <ctl-c> will usually solve your dilemma.  q exits most listings. <exit()> or <ctl-d> exits Python.
4. sudo changes your permission level allowing many other command line commands to work when they would not otherwise do so. Often it is required preface to the command you want to issue. Think of sudo as a pre-command command that clears the way for you to make changes which could affect multiple possible users.
5. From PIXEL, the 7 command-line environments can be entered with <ctl><Alt><F#> where <F#> is a function key  <F1> to <F7>. Use <Alt><F7> to return you to PIXEL.
6. Unix systems hate spaces in names – you must enclose those in quotes, i.e., “My First File”. Make it easy on yourself and just stick to names with lower case letters and no spaces or use underscores instead of spaces, i.e., “my_first_file”.
7. Sanity Savers: <ctl-l> (lower case L) or <clear> clears the screen, puts the prompt at the top, and up/down arrows scroll through previous commands
8. Getting Assistance: <command><spc><–help>; help  lists your shell’s built-in commands and help<spc><command> yields detail of the command; info<spc><command> documents commands called invocations. The manual is invoked with man -k man | less to reveal the gazillion pages you can access.  (For a page example: if you are interested in the C library for GPIO, try man pigpio | less.)   whatis<spc><command> will yield just the description of what a command does.

The Two (make that eight) Most Important RPi Command Line Tools:

Special Note: apt is an updated utility that replaced apt-get. Much web documentation still says “apt-get” but should be revised to say “apt”.
According to the Raspberry Pi folks, the two most used command line functions are part of the apt utility:
(1) “apt update” or more likely you will call it with “sudo apt update” … but apt update does not actually update anything, it merely returns a list of packages which could be updated.  You then need to call “apt upgrade” (if nothing has to be removed) or maybe “apt full-upgrade” (if packages need removal first) – and again you may need to start everything with sudo unless you have root privileges to start with.

(2) “apt install <a program or utility>”  – you will need to use sudo in front of it also.

Other important apt commands include search, show_information and:
         apt<spc><install><spc><a program or utility>   install new package
         apt<spc><remove>     package removed – leaves configuration file
         apt<spc><purge>     removes all remnants that it can find
         apt<spc><auto-remove>    used to remove auto installed packages

7 Shortcuts You Really Need to Know Before You Move On

  • .     is an alias for the current directory
  • ..is an alias for the parent directory; so “cd ..” moves pwd up one level
  • ~    is an alias for the absolute path shortcut to the user’s home directory. Type “cd ~” to return to your home directory.
  • /   is an alias for the root directory
  • *”   is a wildcard character for one or more possible but unknown character(s) and “?” is a wildcard for a single character
  • |  constructs a “pipe” that joins commands output to input – frequently used with the commands less, more, and cat.

3 Key Commands You Need Immediately in a Command-line Environment

pwd   will display your present working directory – this is the directory you are “in” at any given moment.  (If you have not changed your default user from pi, you start out in /home/pi.)
cd<spc><some path modification string> changes your working directory
ls   lists files and directories in your current directory location.  ls, like almost all commands, can be modified with “flags” like -l or -a and flags can be combined. For example: “ls -la”.   In this example flag combination, the “l” calls for extended info and the “a” forces the display to list all files including those normally hidden.

Working with Files and Directories:

cat<spc><file>    lists contents of a file, for long files try cat | less to output in pages
chmod<options><filename>
   lets you change the permissions of your files. This is a little complicated but helpful to understand.  When you get a list of files and directories with a command like “ls -lah” the first 10 characters are the “permissions string”. This string is easier to understand if you look at the diagram. Position 0 defines the entry as a directory (“r’) or a file (“-“). The next 9 characters, in groups of 3, establish read, write, and execute permissions for the owner (“u” – probably for user originally), the group (“g”), and others (“o”)  respectively.

One way to set the permissions is to define the settings you want for all three values for each set separately. For example: “chmod u=rwx,g=rw-,o=r–  myfile” gives the owner/u all privileges, lets the group/g read or write, and lets other/o read only with respect to the file “myfile”.
cp<spc><file><spc><path
or path and file name>    copy a file and put it in the directory as specified
curl    download or upload a file to or from a server
diff<spc><file1><file2>
compares file1 to file2 and shows differences
dir   displays a list of directories only, add -a to get everything
sudo find<spc><options><spc><path-name (use “/” for root)  ><spc><file name (can use wildcards) >”  **for an intermediate user <options> are irrelevant
grep<spc><”string”><spc><filename>
    looks for a string pattern in a file
mkdir<spc><new directory name>    
create a new directory in pwd
mkdir<spc><-p><spc><path/dir name>
   make a new directory on a path
mv<spc><file><spc><newfilename>  renames or moves a file
mv<spc><file><spc><path or path and file name>
   moves and/or renames a file to the directory specified
rename<spc><current file name><spc><new file name>    renames a file
** sudo mv is more dependable than rename in actually renaming a file
rm<spc><file>
   removes a file   *Note: there is no way to recover a deleted file
rm<spc><file list>   removes a list of files
rm<spc><-r><spc><directory name>
  removes a directory. Note: it is gone forever.
rm<spc><-R><directory name>            removes directory, sub-directories and all files
rmdir<spc><directory name>
               removes an empty directory
touch<spc><newfile name>    create a new empty file in pwd or change its time stamp
shred<spc><file>  ultra secure file destruction (paranoid a little?)
tree    show a tree structure of directories and files
vdir
    verbosely list directories – editor’s fav
wget<spc><url of file location>    used to download a file to the Pi from the web.
whereis    finds a command file in standard program location
wc
   list the number of lines, words, and characters in a file

Getting Information About Your System

PEOPLE
groups     displays a list of groups
id              
current user id (uid) and group (gid)
logname  
user’s name
users        
everybody logged in on the Pi
who
           shows every user logged in and working in a command environment
whoami    
 your log in name

NETWORK ENVIRONMENT
ifconfig    displays network status information
hostname<spc><-I> (the -I is a capital eye)   the host ip will be first 4 dot separated number series.  It is also the “inet” number displayed as part of the ifconfig command display
ping    checks communication with another host.
ssh    the secure shell that makes your Pi into a command-line client is not enabled by default but can be activated in “interfacing options” using the raspi-config utility. For a non-permanent solution use:   “sudo systemctl enable ssh” and then “sudo systemctl start ssh”.
tty    displays the screen or terminal number that is active

HARDWARE
arch    you processor name/id
du<spc><filename>
   shows disk space usage of files and directories, use “du | less”
pinout – this is a fun one for Pi hardware users – a graphic and info list of your Pi.
uname<spc><-a>
    to get all the most critical info about your system
lscpu     will present summary info on the cpu
vcgencmd    vast hardware info about RPi. NOT in the help or info commands so Google it for more info – see below also.  Ex: vcgencmd<spc><get_config><int>

SYSTEM AND SOFTWARE
<ps><>space><aux><spc><|><spc><less>    view all running processes
df
   mounted partition usage
ps<spc><-u><spc><yourusername>    info on your processes, including id in case you want to kill one
stat<spc><filename>
    get the status information on a file
stty
    print or change current terminal baud setting
top
    will list running processes showing real time activity
Find packages installed: (see the Debian site at https://wiki.debian.org/ListInstalledPackages)
.    dpkg-query<spc><-l>    a very nice table with version and description; (“-l” is lower case L).
.    dpkg-query<spc><-f><spc><’${binary:Package}\n’><spc><-W>  
one package name per line
.    dpkg-query<spc><-l><spc><’search pattern’>
    add search pattern to list command
NOTE: The Debian site can be a considerable resource. A good place to begin is : https://wiki.debian.org/WordIndex .  Also, find a come-back-to-reality look at the Raspberry Pi and some problematic issues is at: https://wiki.debian.org/RaspberryPi

MULTIPLE TYPES OF INFORMATION
Get many Pi settings from the config.txt file:  (See “Configuring Your Pi” below.)
Accessing the <proc> information has more than a hundred status and environment attributes to be displayed. Try these four,
   cat</proc/version>       Raspberry Pi version 
cat</proc/cpuinfo>
       shows details on all 4 processors
cat</proc/meminfo>
    memory use data
   cat</proc/partitions>    how your sd card is divvied up

Changing Your Command Line Environment:

alias<’command equation’> -create your own command:   Ex: ‘alias “lx=ls -lah”’
<ctl-d>    logs a user out, presents log in que
exit   or    logout    terminates a session –   sometimes <ctl-D> will work also
kill<spc><PID, i.e., a process id>   stop a process – (ref Pixel – see “A Few Other Things to Know”)
passwd    lets you change your password
poweroff
– will do just that
reboot    will also do just that if you have only one user active: see systemctl below.
shutdown<spc><-h><spc><now>  – the safest way to shutdown
shutdown<spc><-r> 
gives you 1 minute then restarts computer
shutdown<spc><-c>   
cancel a shutdown command
su<spc><alternate user> –   change users – must have a registered account
systemctl<spc><reboot><spc><-i>    will restart the Pi

Updating, Adding and Deleting Software Packages:

Assume sudo<spc> to begin any of the following:
apt<spc><update>
  generates a list of software packages that need to be upgraded. To actually do an upgrade you need:
apt<spc><upgrade>[<spc><package name>]    is there is nothing in the old existing package that needs to be removed. This may come back with just the number of packages that could be upgraded, in which case you need to use “apt list –upgradeable” to see the list.  Then you will need to call:
apt<spc><upgrade>[<spc><package name>]    if there is nothing in the old existing package that needs to be removed.  Otherwise you will need to use:
apt<spc><full-upgrade>[<spc><package name>]    which will remove the old package before installing the new one
apt<spc><install><spc><a program or utility>    to install a new package
apt<spc><remove>     package removed but leaves configuration file
apt<spc><purge>     removes all remnants that it can find
apt<spc><auto-remove>     used to remove auto installed packages

Additional Commands You May Need:

adduser<spc><new user name in small letters>  – then follow the directions

deluser<spc><–remove home><spc><victim’s  user name>  – then follow the directions
less   – an vast utility replacing more – usually connected by the pipe (as in …
cat<spc><something generating output><spc><|><less>) to display just one page at a time.
echo<string>    send string to standard output
fold    wrap long input lines
date    displays current date and time
<ctl-U>   
 cancels whole line being input

timeout    put a time limit on a command – connecting to remote storage might be the most useful place to use timeout – use it anyplace a process can get “hung”.  The easiest example is to limit a ping command, i.e., “timeout 2 ping raspberrypi.org” will ping the rpi server for 2 seconds.
>
   a single character command to change standard output; for example, to a printer
lpr<spc><filename>

Configuring Your Pi Hardware with config.txt

Special note: the Pi’s config fille is found at /boot/config.txt

While information in much of this article was gathered from textbooks, articles, many Linux, Debian and GNU sites and (mostly) from direct research using help and info; several tips here are from https://www.raspberrypi.org/documentation/configuration/config-txt/ which in turn sites “the eLinux wiki page RPiconfig, which is shared under the Creative Commons Attribution-ShareAlike 3.0 Unported license .”

There is a ton of stuff that you can research, and another ton of stuff that you can configure, by accessing the  Pi configuration file. There is no sense in reinventing (most) of the wheel so see the Raspberry Pi Foundation’s overview at: https://www.raspberrypi.org/documentation/configuration/config-txt/
where they break the options down into sections including
.   Memory
.   Licence Keys/Codecs
.   Video/Display
.   Audio
.   Camera
.   Boot
.   Ports and Device Tree
.   GPIOs
.   Overclocking
.   Conditional Filters
.   Miscellaneous

On the page starting https://elinux.org/RPiconfig these are the 3 basic access commands:
   vcgencmd<spc><get_config><spc><int>         get all integer configuration options
   vcgencmd<spc><get_config><spc><str>         get all string configuration options
   vcgencmd<spc>< get_config><spc><config>  get a specific configuration that is one of those listed by the two invocations above.  But there is more.

There are apparently a few commands added just for the Pi, which you can see listed with vcgencmd<spc><commands>.  These will not show up with help or info and are not in the manual. There appear to be lots of diagnostic tests available and some measurements like voltage and temperature. For example, try: vcgencmd<spc><measure_temp>   for a centigrade reading (note: 1.8C+32 = real temp (i.e., Fahrenheit))  or vcgencmd<spc><get_lcd_info> for your monitor resolution.

For those interested in incorporating the Pi in projects, the most important feature of config might be that it allows configuring GPIO pins to be set up at boot time. See https://www.raspberrypi.org/documentation/configuration/config-txt/gpio.md .

Configuring Your Pi Command-Line Shell: .bashrc  and raspi-config

Assuming you retain Bash as your command line shell there is a fair amount you are able to configure for yourself by editing the file “.bashrc” which is in your home directory.  Before you do anything to your .bashrc file it would be a capital idea to back it up. For example, if it is November 15, 2019, you might make a copy like this: “cp .bashrc .bashrc111519”. That way you have a copy and you know when you made it easily just by the name.  You can edit .bashrc with any text editor but make sure you are familiar with the one you choose before you start.  The nano editor is friendly and we suggest it.  No need to reinvent this wheel either. A minute of research and you will find many references.

But there is an easier – and safer – way to edit most of the important .bashrc settings.  Type “sudo raspi-config” and you will find an extensive, user friendly access to almost everything of interest in .bashrc.

Random Other Helpful Things to Know:

*   pip3<spc><command><[options]> is the command to install python packages. If you accidentally use just “pip” you could end up with an archaic software module. Commands include: help, install (some options are PyPI, VCS, and Local project directories), uninstall, list, show, search).  Options are -h or –help, -v or –verbose, -V or –version
*   How to kill your PIXEL session: open terminal and type: pkill<spc><lxsession>
*   How to start a PIXEL session in the tty you have active: startx
 You can open multiple terminals in multiple environments organized by tabs in PIXEL.
*   Put yourself in root mode: sudo -i  *Tip: don’t stay in root mode.
*   How to give a user sudoer privledges:  log in as a root user; then type sudo<spc><usermod><spc><-aG><spc><sudo><user name>
*   Bash is not the only shell you can use by a long shot.  A pretty good concise web review of a few alternatives can be found at https://www.maketecheasier.com/alternative-linux-shells/    This is not the only site to tout Fish as the best alternative though the author concedes he has stayed with Bash.
\    escapes itself and other special characters
[ ]    brackets pattern for matching a single character
*    matches any 0 to many characters
?   matches any single character
;    separates commands on a single line; terminates a pipe
“ “    contents in quotes treated as one argument
#    changes line to a comment
<    if followed by <spc><filename> it means “take input from this file”
>    if followed by <spc><filename> it means “send output to this file”;  overwrites file.
Many new Pi owners have complained that the Raspberry Pi site makes it hard to find documentation.  The best access is at: https://www.raspberrypi.org/documentation/
&    runs a command in the background – the shell is then available in the foreground.
scrot<spc><-s>    takes a screen snippit, saves in pwd as a .png file

Text Editors and Other Utilities:

ed    original/classic GNU line editor – ed-1.10-z.1 as of this writing  –  avoid and use nano or vim
vi     very old, use vim instead
vim    a programmer’s text editor upward compatible with vi; use vim<spc><filename to edit>. You may need to install vim: “sudo apt install vim”
nano a very nice, friendly, text editor with ancient commands that predate the common era

emacs    a good command-line editor for programming.  Install with “sudo apt install emacs”.
dc – reverse polish calculator – try and use only if world coming to immediate end otherwise
talk<spc><username>    enables a typed conversation
elm    email client
gzip<spc><filename>   compresses a file
gunzip<spc><filename>   un-compresses a file
ssh    a secure shell making the pi a command-line (only) client of another computer

A Brief Explanation about Debian, Raspian and Unix for the Confused:

Raspian is the operating system you will most likely use on your Raspberry Pi if you install NOOBS. (If not, good luck, you are on your own.) Raspian is an operating system optimized for the Raspberry Pi but not affiliated with the Raspberry Pi Foundation. Raspian is the system that underlies or supports PIXEL, the graphic environment – or GUI – that you probably think of as the “desktop” of the Raspberry Pi.  PIXEL runs “on top” of one of Raspian’s seven available virtual or “command-line” environments. Raspian employs the Debian version of GNU.  Debian is an extensive free operating system which is coupled with the Linux kernel. Linux is a free, highly secure, open source operating system which originally was based on GNU and looks and acts exactly like Unix except it has no Unix code. Unix is the Mother system of all the above. Other operating systems based on Linux include Ubuntu and Fedora.

Think of PIXEL, and the terminal environment you access when you select Terminal from the PIXEL desktop, as being in Raspian environment #7.  When the Pi is booted it utilizes environment #1. All of these command-line environments are available independently and each one you enter will run a “shell”.  Several shells are available. The default shell is referred to as “bash”. There are many utility programs that can be run in any command-line environment. A very useful example is “nano” which is a friendly traditional text editor which, be warned, does not use current conventional commands. For example, you do not <ctl-s> to “save”, instead you <ctl-x> to “writeout”.

A Few Common Option Flags:

-a    all
-d    debug, has lots of options
-e    execute (with options)
-l     list
-m    message – has other arguments, pass in a string for some purpose
-n<argument>    pass in some needed integer for some reason
-q    quiet – suppressed results output
-u    user + argument
-V    version
-z    enable compression