THIS SITE IS HOSTED ON A RASPBERRY PI 2 MODEL B COMPUTER
Linux-Apache2-MySQL-PHP5
.
.
Linux and Your Raspberry Pi Computer
FILE STRUCTURE
/ - Root Directory
/bin - Programs and commands that all users can run
/boot - Boot files
/dev - Special files for system devices
/etc - Config files
/home - Users home directories
/home/pi - Home directory for USER: pi
/lib - Kernel modules and drivers
/media - Mount location for external media
/sbin - System maintenance
/sys - special folder on the Pi for hardware devices
/tmp - Space for programs to put temp files
/usr - Space for programs usable by ALL users
/usr/bin - Space for accessible files and scripts
/var - system logs and spool files
/var/www/html - Location for Web Server files
SUDO, ROOT and SU
Linux is a multiuser operating system; the general rule is that each user is in charge of their
own files in their own space. Sometimes it is necessary to change system files or files created by other users.
To do this you will need Root or Super User privilage.
Gaining Root or Super User privileges gives you the right to damage your Linux system, so use it with caution
SUDO
To temporarily gain Root privileges you use the SUDO command.
Just type sudo before the command that requires the Root privilage.
The firt time you use SUDO it will give you a warning and ask for your password.
Example: sudo rm someFile.tar
ROOT
The Root user has access and control of everything on the system.
If you need access to the Root user, you will need to set the Root password.
To change the Root password type sudo root passwd it will ask you for the new password.
Instead of logging in as Root you should use SUDO
SU
To gain access to Root for an extended period of time (NOT RECOMENDED) you will use SU.
Just type SU at the prompt. It will ask for Roots password.
If you didn't set up a password for Root, see ROOT above.
Notice that the promt changes to root@youPIsName:/currentDirectory#
To leave the Root user, just type exit and you should EXIT ROOT ASAP!!!!
BASIC LINUX COMMANDS FOR YOUR PI
startx - Starts the Graphical Desktop (GUI)
sudo shutdown -h now - Shutsdown the Pi
sudo poweroff - Shuts down the Pi
sudo reboot - Reboots the Pi
sudo shutdown -r now - Restarts The Pi
man - Linux HELP, if you want to know more about a command just man it!
Use man commandName
--help - More Linux HELP, just type your command followed by --help
sudo raspi-config - Opens the Raspberry Pi config screen
clear - Clears the screen
nano - A text editor
vi - Another text editor
ARGUMENTS - To get lists of arguments just check the man pages man commandName
FILE COMMANDS
ls - Displays a list of the contents of the current directory
touch - Create or update a file
cd - Changes your directory
mv - Moves a file or Renames a file
rm - Removes (deletes) a file
rmdir - Removes a Directory, must be empty and can not be your current directory
mkdir - Make a Directory
pwd - Displays your current directory
cp - Will copy a file
wget - Downloads a file from the internet
cat - Will display all of the content of a file
tail - Will display the last ten lines of a file
head - Will display the first ten lines of a file
more - Will display the content of a file one screen at a time
less - Will display the content of a file one screen at a time and user can use arrows
grep - Searches for a string in a file
find - Searches for files that pass test criteria
tar - Is an archiving utility
rsync - A file copy tool
lsof - Shows a list of all open files
USER COMMANDS
chmod - Modifies the permissions of a file/directory
chgrp - Changes the group that has ownership to the file/directory
chown - Changes the user that has ownership of the file/directory
useradd - Adds a new user
adduser - Adds a user with prompts
passwd - Changes the password for a chosen user
usermod - Changes user settings
userdel - Deletes a user
groupadd - Adds a group to the database
groupmod - Modifies an exsisting group
NETWORK and INTERNET
hostname - To display the Pi's hostname
iwconfig - Displays the network info for the the wireless adaptor
ping - Sends a packet to an IP address and waits for a response
traceroute - Displays hops a packets takes to its destination
netstat - Shows network connection info
route - Displays the routing table information
host - Shows DNS records
ifconfig - Displays active network interfaces
nslookup - Used to look up information about internet servers in DNS records
dig - Dig is a tool for querying DNS nameservers for information about host addresses
w - Provides the uptime and the user information
SYSTEM COMMANDS AND TOOLS
df -h - Displays the amount of space left on the device
du -h - Shows your disk usage
lscpu - Displays CPU info
lsblk - Displays storage device information
lsusb - Displays the attached USB devices (lsusb -v for detail)
fdisk -l - Will display the file system partitions
cat /proc/cpuinfo - Displays info about the Pi's CPU
cat /proc/meminfo - Displays info about the Pi's Memory
cat /proc/partions - Displays info about the Pi's Partitions
cat /proc/version - Displays info about the Pi's version
vcgencmd measure_temp - Displays the CPU temp
vcgencmd get_mem gpu - Displays the GPU memory size
vcgencmd get_mem arm - Displays the ARM memory size
free -h - Displays memory statisics
vmstat - Displays memory information
uname -a - Displays all system information
ps -A - Displays a list of all running processes
top - Displays a list of programs that are using the most CPU
kill - Ends a process (must get id with ps -A)
uptime - Displays the time the computer has been running
ctrl C Kills whatever is running
THE APT PACKAGE MANAGER
The APT package manager keeps track of all packages on your system.
When you install a new package it finds all required dependecies and installs them for you.
When you uninstall a package it removes all dependent packages, but only the ones that are not use by other programs.
Index for the APT package manager is retrieved from /etc/apt/sources.list
UPDATING APT
To update your APT cache type sudo apt-get update
To update your APT installed packages type sudo apt-get upgrade
To do a "smart" upgrade type sudo apt-get dist-upgrade
INSTALLING PACKAGES
To search for a package type sudo apt-cache search yourSearchCriteria
To install a software package just type sudo apt-get install YourPackageName
To see a list of installed packages type dpkg --list
UNINSTALLING PACKAGES
To remove a package type sudo apt-get remove packageName
To remove a package and all its config files type sudo apt-get purge packageName
To remove all packages that were installed to satisfy dependencies that are now not used type sudo apt-get autoremove
To remove all downloaded archive files type sudo apt-get clean
To remove all downloaded archive files type that are no longer available sudo apt-get autoclean
SSH and RUNNING HEADLESS
If you want to connect to your Pi's terminal from another PC you can use SSH.
If you will only be using the terminal you can disconnect the monitor, keyboard and mouse
and just use a different PC to do your work via SSH
If you are using a Windows PC
You will need to install some sort of SSH client PuTTY works great with the Raspberry Pi
Just download it and run it. Type in the IP of the PI and Log in, that easy.
If you are using a Linux PC
Just go to the terminal and type ssh thePisIPaddress -l thePiUserName
Then just log in
If you want to connect to the full GUI of your PI remotely just use Remote Desktop
It is preinstalled with most modern Windows versions.
First you must install XRDP on your PI
Open a terminal window on your PI directly or via SSH
Type sudo apt-get install xrdp to install the package
Now reboot your PI, just type sudo reboot
Open up Remote Desktop
Type the IP of your PI in the Computer field
Hit connect and it should bring up a login screen
Put in your username and password and thats it
USB STORAGE DEVICES
In Linux your external storage devices are not automatically made available to you
Before you can access it you must mount the device to a folder in the /media directory
Boot your PI, Open a terminal window and Connect the USB device
To view the items attached to your PI type sudo fdisk -l
Find your device in the list and note the device name
Example Device Name: /dev/sdXN
X is the Drive Letter A, B, C, D
N is the drive partition
If you only have one device the name will be /dev/sda1
Now make a place to mount your device, just type mkdir /media/yourFolderName
The file will only be accessable to the Root user
To make it available to all users type
sudo chgrp -R users /media/yourFolderName
sudo chmod -R g+w /media/yourFolderName
To mount the device to the folder just type
sudo mount /dev/sdXN /media/yourFolderName -o=rw
You can now access your USB device from /media/yourFolderName
SETTING UP YOUR WIFI
If you are using the new Raspberry Pi 3 then you are good to go. If not plug in a WiFi USB device.
Scan the WiFi networks with sudo iwlist wlan0 scan
Now open the wpa-supplicant file
Just type sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Go to the bootom of the file and add your network info
network={
ssid="yourSSID"
psk="yourPassword"
}
Save and Exit
Shut down the interface with sudo ifdown wlan0
Then start the interface with sudo ifup wlan0
Type ifconfig wlan0 to check that you have a valid IP address
Thats it, your Pi will connect to your WiFi when it boots