Linux

Commands.

Python

Commands

This page contains most commonly used Linux commands that will be handy while programming with Raspberry Pi.

Note that the idea is not to teach Linux commands extensively but instead to give users of Raspberry Pi a quick head start. This gives user a springboard for future research.

File management

Command              Description                                                                                                 
ls Shows the contents of the directory
ls -a Shows hidden files
pwd present working directory (default is /home/pi)
cd .. Go to parent directory
cd home Go inside home directory (home directory should be in current location)
mkdir java Make a directory called java
rm test.txt Remove the file called test.txt
rm -f test.txt Force remove the file called test.txt
rm -r java Remove directory called java
chmod 777 java read(4)-write(2)-execute(1) permission to User(7)Member(7)Others(7)
cp -r test java Copies directory called test to a directory called java (created if not present)
more Led.py Displays the contents of file called Led.py
head Led.py Displays first 10 lines of the contents of a file called Led.py
tail Led.py Displays last 10 lines of the contents of a file called Led.py
cat Led.py Displays the contents of file Led.py on screen
cat f1.py > f3.py Copies contents (try cat f1.txt f2.txt | sort > f3.txt) data in sorted order!
mv f1.py ../ Moves file f1.py to parent directory

System Information

Command              Description                                                                                                 
man chmod Shows the manual of the command called chmod
df  Shows disk usage
whoami Shows Login ID
date Shows current date
cal Shows current month's calendar
mv java jre Rename the directory called java as jre 
ping 10.0.0.138 pings the host names pi and outputs the info (use CTRL+Z to stop)
top running programs and theior IDs
ps current active processes and their PID
lsusb  Information about the USB devices connected to Pi 
echo hello  Outputs 'hello' on screen. This command is useful for debugging
date -s (string) sudo date -s "Thu May  4 12:20:46 AEST 2017"

Searching 

Command              Description                                                                                         
grep GPIO Led.py Search for GPIO in file called Led.py; if found then opens files & highlight them
grep -r bob java Search for bob in all the files within the directory called java
ls | grep py Search for the sub-string 'py' in the output of ls command
sudo find data.txt Search current directory for the file called data.txt
ls | more   Display contents one page at a time (try also ls | less)
clear Clears the screen

Keyboard Shortcuts 

Command              Description                                                                                                  
CTRL+Z Kills the current command
CTRL+D or exit Logout
CTRL+C  Halts
CTRL+R  Reverse-i-search. Type first few characters to go to recent used command

Sudo

Command               Description                                                                                                  
sudo reboot  Runs Rebootcommand as superuser
sudo nano bob.txt Makes (Opens) a file called bob.txt in root folder and can edit it
su Asks for root password (default = root), (note: CTRL+D to logout)
sudo passwd root Reset new password for root