Linux Basics¶
What is Linux?¶
Linux is an open-source operating system. It is the underlying operating system on which many popular operating systems like Android, Ubuntu, Raspbian and MacOS are based on.
Getting started¶
General Linux Commands¶
- SSH into a Raspberry Pi or use a computer with Ubuntu.
- Try out the following commands in the terminal:
- Make (create) directory with name
foo
mkdir foo
- List Files
ls
- Change directory to
foo
cd
- Print Working Directory
pwd
- Create Python script
nano helloworld.py
Note
nano
is the simplest Terminal based editor you can use. You
can also use vi
. If you are on the Desktop (via HDMI or VNC),
you can use graphical editors like gedit
and Atom
.
- Within
helloworld.py
, type the following: print("Helloworld!")
- Save the file using
Ctrl + X
>>Y
>>Enter
- Save the file using
- Run the Python script
python helloworld.py
- This should output
HelloWorld!
- This should output
- Concatenate (get contents) of a file
cat helloworld.py
- This should output
print("Helloworld!")
- This should output
- Copy file
helloworld.py
tocopy_of_helloworld.py
cp helloworld.py copy_of_helloworld.py
- Try
ls
now.
- Try
- Move file (
copy_of_helloworld.py
) to new directorybar
mkdir bar mv copy_of_helloworld.py bar/
Note
Sometimes, typing the entire filename or command takes too long. In
cases like this you can use Tab Completion
to quickly type the
commands. You write the partial file/directory name or command and
press Tab
to complete it (or choose from possible options by
double tapping Tab
).
Note
Use the UP Arrow Key
to use the fetch the previously used command.
- Rename file (
copy_of_helloworld.py
) to (renamed_helloworld.py
) cd bar/ mv copy_of_helloworld.py renamed_helloworld.py
- Go back a directory level
cd ..
- Delete a file or directory
rm bar/renamed_helloworld.py rm bar -R
- Manual for a command
man rm man sudo
- Update and upgrade your Linux packages
sudo apt-get update sudo apt-get upgrade
Note
sudo
is akin to an admin. Using it will sometimes ask you to
enter the user’s password.
- Installing a new package like
htop
sudo apt-get install htop htop
Note
htop
is a great terminal way of checking how much
processing power and memory your computer is using.
- Pinging a website like
www.google.com
ping www.google.com
- Show network configuration
ifconfig iwconfig
- Check date
date
- Clear screen
clear
- Check version of an installed package
htop -v
- Get local and global IP
hostname -I curl ifconfig.me
- Disk space information
df -h
Raspberry Pi Specific Commands¶
- Check the pinouts on the Raspberry Pi
pinout gpio readall
- Lists connected USB hardware
lsusb
- Show Raspberry Pi CPU Temperature
vcgencmd measure_temp
- Show CPU & GPU memory split
vcgencmd get_mem arm && vcgencmd get_mem gpu
Note
If you need more than one Terminal
open at one time, and you
do not want too many new Terminal windows, you can use Ctrl
+
Shift
+ T
.