Skip to content

Instantly share code, notes, and snippets.

@henrytriplette
Last active August 29, 2019 02:13
Show Gist options
  • Save henrytriplette/d54f6ff8f0272bd6e963cff6c2f13e7f to your computer and use it in GitHub Desktop.
Save henrytriplette/d54f6ff8f0272bd6e963cff6c2f13e7f to your computer and use it in GitHub Desktop.
RaspberryPi Useful commands

Disable screen blanking in X-Windows on Raspbian

xset s off         # don't activate screensaver
xset -dpms         # disable DPMS (Energy Star) features.
xset s noblank     # don't blank the video device

Disk space, memory and cpu

df -h: Shows information about the available disk space.
cat /proc/meminfo: Shows details about your memory.
cat /proc/partitions: Shows the size and number of partitions on your SD card or hard drive.
df /: Shows how much free disk space is available.
free: Shows how much free memory is available.
cat /proc/version: Shows you which version of the Raspberry Pi you are using.
lsusb: Lists USB hardware connected to your Raspberry Pi.
vcgencmd measure_temp: Shows the temperature of the CPU.
vcgencmd get_mem arm && vcgencmd get_mem gpu: Shows the memory split between the CPU and GPU.

Increase Swap space

/etc/init.d/dphys-swapfile stop
sudo nano /etc/dphys-swapfile
CONF_SWAPSIZE=100
/etc/init.d/dphys-swapfile start

Networking

hostname -I: Shows the IP address of your Raspberry Pi.
ifconfig: To check the status of the wireless connection you are using  (to see if wlan0 has acquired an IP address).
iwconfig: To check which network the wireless adapter is using.
iwlist wlan0 scan: Prints a list of the currently available wireless networks.
iwlist wlan0 scan | grep ESSID: Use grep along with the name of a field to list only the fields you need (for example to just list the ESSIDs).

Add wifi

sudo nano /etc/wpa_supplicant.conf

Raspberry Pi 3 WiFi drop outs

Turn off power saving for the internal wifi card. Check the status via:

sudo iwconfig

to turn off power saving permanently, add the following lines to “/etc/rc.local”

## Fix WiFi drop out issues
iwconfig wlan0 power off

Reboot and confirm via sudo iwconfig that it worked.

SSH

Check

ps -ef | grep sshd | grep -v grep # Check if ssh process is running
netstat -plant | grep :22 # Check if the process sshd is listening on port 22:
lsof -i # Use the lsof command to check if the port 22 TCP file is open
service sshd status / /etc/init.d/sshd status
/etc/init.d/sshd restart # Restart the service

Misc

Some more commands:

Remove folder

rm -rf foldername/

Create Alias

alias kickthemout="python folder/script.py"

Python version

python -V

Display CPU usage

top
htop

Manage Processes

ps -ef
ps ax

sudo killall my_project.a // Kill processes

Download from git

git clone https://github.com/ytisf/mdk3_6.1.git

Install Kali linux

apt-get install kali-linux-full

Expand and fill SD card

First make a backup of your SD Card using the instructions found here in case something goes wrong. From the command line or a terminal window enter the following

sudo fdisk /dev/mmcblk0

then type p to list the partition table You should see two partitions. if you look in the last column labeled System you should have

W95 FAT32
Linux

make a note of the start number for partiton 2, you will need this later. though it will likely still be on the screen (just in case). Next type d to delete a partition. You will then be prompted for the number of the partition you want to delete. In the case above you want to delete the Linux partition. So type 2

Now you can resize the main partition. type n to create a new partition.

This new partition needs to be a primary partition so type p. Next enter 2 when prompted for a partition number.

You will now be prompted for the first sector for the new partition. Enter the start number from the earlier step (the Linux partition) Next you will be prompted for the last sector you can just hit enter to accept the default which will utilize the remaining disk space.

Type w to save the changes you have made. Next reboot the system with the following command:

sudo reboot

once the system has reboot and you are back at the commandline enter the following command:

sudo resize2fs /dev/mmcblk0p2

Note: this can take a long time (depending on the card size and speed) be patient and let it finish so you do not mess up the file system and have to start from scratch.

Once it is done reboot the system with the following command:

sudo reboot

You can now verify that the system is using the full capacity of the SD Card by entering the following command:

df -h

Why This Works: The real magic here is that you delete the root and swap partitions, then recreate only the root partition (using the original start sector) before writing the data to the disk. As a result you don't erase the existing data from the root partition.

By removing the swap partition you allow the root partition room to grow beyond its current size and fill the unused portion of the disk (because of the placement of the partitions -the root partition is sandwiched between the boot and swap partitions - it can't simply be resized leaving the swap partition alone).

You then resize (which is safe to run on a mounted disk) the file system to use all the space in the new root partition.

ref:

http://www.youtube.com/watch?v=R4VovMDnsIE http://www.raspberrypi.org/phpBB3/viewtopic.php?f=5&t=5584

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment