Some Useful Raspbian commands

Conventions used here

  • filename appname directory path are used only as placeholders. Substitute your specific case.

  • The path you enter can be absolute (from the top root level) or relative to current directory. Paths from root always start with /. Use ../ to move up the directory hierarchy.

  • *deprecated means it still works but this command will eventually disappear.

  • > is used to denote your terminal prompt. Don’t enter it!

  • Comments are in bracketed (normal) text. Don’t enter these either!

Basic Raspbian commands

Show Pi configuration menu > sudo raspi-config
Start the desktop > startx (cannot be done via SSH)
Update installed packages > sudo apt-get update; sudo apt-get upgrade
Install a Linux package > sudo apt-get install packagename
Upgrade Raspbian version > sudo apt-get update; sudo apt-get dist-upgrade
Upgrade the Linux kernel > sudo apt-get install rbi-update; sudo rbi-update
Safely shutdown the Raspberry Pi > sudo poweroff (or) sudo shutdown -P –h 0

Where Am I?

Show working directory > pwd (print working directory)
Change to your home directory > cd (change directory)
Change to directory in current directory > cd directory
Change to higher level directory > cd .. or cd ../../ etc.
Change to another directory > cd path/directory

File commands

List files and directories in current directory > ls
List contents in more detail > ls -l (shows permissions and size)
List contents to show hidden files > ls -al (shows permissions and size)
List contents in human-readable format > ls -lh (shows permissions and size)
List files and directories in another directory > ls or ls path/directory
Rename file > mv filename newfilename
Move file > mv path/filename newpath/(new)filename
Delete file > rm path/filename (remove file)
Delete file in another directory > rm path/filename

Directory commands

Make new directory > mkdir path/directory
Make several new directories under a parent > mkdir –p path/newdir1/newdir2
Rename directory > mvdir directoryname newdirectoryname
Remove directory > rmdir path/directory
(directory must be empty, otherwise rmdir -r directory)


Show app version > appname --version
Show app location > which appname
Show help pages > appname --help
Show man pages > man appname

WiFi and Networks

Show WiFi networks > ifconfig wlan0 *deprecated
Show all network addresses > ip addr (ifconfig -a is *deprecated a=all)
Ethernet network commands – Substitute eth for wlan
WiFi turn on > sudo ifup wlan0 (0=1, 1=2, wlan1, wlan2 etc.)
WiFI turn off > sudo ifdown wlan0
WiFi forced on > sudo ifup --force wlan0
WiFi forced off > sudo ifdown --force wlan0
Show wireless configurations > iw (iwconfig is *deprecated)
Show events from your WiFi > iwevent
WiFi network 1 details > sudo iw wlan0
Show high level wireless information > iw wlan0 info
Show information to troubleshoot the wireless > iw dev wlan0 link
Scan WiFi network 1 > sudo iw wlan0 scan
Scan local wireless networks > sudo iw dev wlan0 scan (much information!)
Scan only your internal network > sudo nmap -sP
(Note: also works in OS X; substitute your router’s IP format)
Create wireless passphrase > wpa_passphrase ssid passkey
(Note: must have wpasupplicant installed)
WiFi Renew > sudo dhclient -r wlan0; sudo dhclient wlan0
(or whatever wlan number)
Restart networking > sudo /etc/init.d/networking restart
(Note: disconnects SSH/VNC!)

Internet commands

Internet addresses in use > ip addr show
Show all network routes > route -n or ip route (better)
Show IPv6 WiFi routes > ip -6 route


Service status > service --status-all
Start SMB service > sudo service smbd start (Windows file sharing)
Stop SMB service > sudo service smbd stop
Restart SMB service > sudo service smbd restart

VNC commands

Install tightvncserver > sudo apt-get install tightvncserver
Start tightvncserver > sudo /etc/init.d/tightvncserver start
or tightvncserver
Stop tightvncserver > sudo /etc/init.d/tightvncserver stop
Open SSH connection > ssh pi@pi.IP.address (in your computer Terminal)

DHCP commands *

Where are DHCP leases? > /var/lib/dhcp/dhclient.leases
Get IP Address or Renew network lease > sudo dhclient wlan0/eth0
Remove all leases and renew > sudo rm /var/lib/dhcp/dhclient.leases; sudo dhclient wlan0/eth0
* Note: These commands are only for when the Pi is being used as a DHCP server.

Other useful commands

List USB devices > sudo lsusb
List loaded modules > sudo lsmod
Root file access > (first) alt F2 (then) gksudo nautilus
Get AP info > iwlist scan
Get wireless info > iwlist (many options shown!)
DNS resolving via eth1 > cat /etc/resolv.conf
List devices/modules > lspci, lsusb, lshw, lsmod
Kernel messages > dmesg
Kill NWM > sudo killall NetworkManager

See also: