Usefull Linux Commands…

So! You have received your Raspberry Pi or other Linux based computer and are now wondering what to do with it… Well don’t fret. I was thinking the same thing when I got mine.

After I had visited the Raspberry Pi website and installed the Debian “Wheezy” Operating System (OS) onto my Class 10 8Gb SD card I was ready to go… Or was I???

Being a hardened Windows user myself, I was a little daunted when faced with command lines. Here are some useful commands that have really helped me.

# Update your Debian “Wheezy” or other Linux OS software…

sudo apt-get update
sudo apt-get upgrade

# Start the graphical Interface (Linux version of Windows)…

startx

# Find the IP (internet protocol) address of your Pi…

sudo ifconfig

Next to the wlan0 entry you will see inet addr. This is the IP address of your Pi…

# Make a file executable (means you can run it in a terminal window)…

sudo chmod 755 /home/pi/path_to_file/file.sh

# Helpful instruction manuals…

man nameofprogram

e.g. man php5 will display the manual for php5

# Context help…

nameofprogram -h e.g. php5 -h

will display command help for php5

# Remove a directory…

rmdir /name/of/directory

# Remove a file…

rm /name/of/fi.le

# Change the current directory…

cd /home/pi/name_of_directory/

# list of files in he current directory…

ls

# list of directory sizes…

du -h

# Open a file in a text editor…

nano /name_of_folder/name_of_file.txt

type a new filename creates a new file

# Check how much free space you have…

df -h

or

free

# List directories & files recursively to a .txt file…

ls -1tr -l -R --group-directories-first | grep -v files > filedate.txt

# See how long your Pi has been on for…

uptime

# Change the home directory for user…
Login as a user with sudo privileges and enter the following:

sudo nano /etc/passwd

Nano text editor opens up. Locate the username you would like to change the home directory of (the last added user is in the end), and just enter whatever directory you would like. For example, the home directory for the user jack is set to /home/jack:

pi:x:1000:1000:,,,:/route/to/home/dir:/bin/bash

Now when the user pi logs in, his home directory would be /route/to/home/dir.

# Search for text in files (recursively)…

grep -ril "TEXT TO FIND" /path/to/search

# List Only Directories…

ls -l | grep ^d

Add the -R flag to ls to show all subfolders.

# List Only Files…

ls -l | grep ^-

Add the -R flag to ls to show all files in subfolders.

# MySQL Dump. Backup database…

mysqldump -u username -h localhost -p database_name | gzip -9 > backup_db.sql.gz

# Write all installed programs to a file…

dpkg --get-selections > installed_progs_04-05-2013.txt

# List all directories recursively to a file…

ls -l -R | grep ^d > filename.txt

# My prefered Mencoder settings for encoding 1280×720 video…

mencoder -nosound -mf fps=25 -o filename.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=8000 mf://@filename.txt

# Display information on a file or directory…

stat [filename]

# Set up private & public keys…

ssh-keygen -t dsa

Copy to remote machine…

ssh-copy-id -i ~/.ssh/id_dsa.pub <username>@<ip address>

# Correct the Raspberry Pi’s clock:

Start by shutting down ntpd with: /etc/init.d/ntp stop
Then use raspi-config to get the timezone set correctly (Option 4 change internationalization options from the main menu, then Option I2 set timezone from the submenu).
When ntpd starts it should do an initial sync with the time server to set the clock, but if your clock is off by too many days it won't work. So reset the clock with: date -s "3 Nov 2013 10:18:00"
Then restart ntp with: /etc/init.d/ntp start

Leave a Reply

Your email address will not be published. Required fields are marked *