[EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

12
7/28/2019 [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi http://slidepdf.com/reader/full/emc-311-chapter-2-getting-around-linux-on-raspberry-pi 1/12

Transcript of [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

Page 1: [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

7/28/2019 [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

http://slidepdf.com/reader/full/emc-311-chapter-2-getting-around-linux-on-raspberry-pi 1/12

Page 2: [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

7/28/2019 [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

http://slidepdf.com/reader/full/emc-311-chapter-2-getting-around-linux-on-raspberry-pi 2/12

Chapter 2 : Using the Linux commands

• LXTerminal – gives access to the command line (or shell) – autocomplete fixture :

• type few characters then hit tab, shell will attempt to autocomplete based ondirectory

 – command history fixture :•

hit up arrow on command line, able to step back through command history

2

Page 3: [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

7/28/2019 [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

http://slidepdf.com/reader/full/emc-311-chapter-2-getting-around-linux-on-raspberry-pi 3/12

Chapter 2 : Using the Linux commands

• Home directory prompt

pi@raspberrypi ~ $ 

• Change directory ( cd ) – Change to home directory

cd /home/pi/

cd ~

 – Move up to the top of file

systempi@raspberrypi ~ $ cd ..

pi@raspberrypi /home $ cd ..

pi@raspberrypi ~ $ cd / 

3

Page 4: [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

7/28/2019 [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

http://slidepdf.com/reader/full/emc-311-chapter-2-getting-around-linux-on-raspberry-pi 4/12

Chapter 2 : Using the Linux commands

• List ( ls )

 –

List files in directorypi@raspberrypi / $ ls 

 – More details listing

pi@raspberrypi ~ $ ls -l 

 – List all files including hidden ones

pi@raspberrypi ~ $ ls -la 

• Rename (mv)

 – Create empty dummy file first,

then checked the list

pi@raspberrypi ~ $ touch foo

pi@raspberrypi ~ $ ls

foo Desktop python_games

 – Rename the file, then rechecked

the list

pi@raspberrypi ~ $ mv foo baz

pi@raspberrypi ~ $ ls

baz Desktop python_games 4Table : Important directories in the Raspbian file system

Page 5: [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

7/28/2019 [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

http://slidepdf.com/reader/full/emc-311-chapter-2-getting-around-linux-on-raspberry-pi 5/12

• Make directory, bundle files into

single file, and compress (mkdir,tar, gzip)

 – Make directory and change to that

directory

pi@raspberrypi ~ $ mkdir myDir

pi@raspberrypi ~ $ cd myDir  – Create empty dummy files first,

then bundles files into single tar file,

finally compress using gzip

pi@raspberrypi ~ $ touch foo bar baz 

pi@raspberrypi ~ $ cd ..pi@raspberrypi ~ $ tar -cf myDir.tar myDir

pi@raspberrypi ~ $ gzip myDir.tar 

* becomes a .tar.gz achieve of that

directory that can be distributed via

internet 

• Remove (rm)

 –

Remove the filerm

 – Remove empty directory

rmdir

 – Remove non-empty

directory ( includeeverything in directory)

rm  – r

• Help / find command

details(--help)

pi@raspberrypi ~ $ man curl

pi@raspberrypi ~ $ rm --help

5

Chapter 2 : Using the Linux c

ommands

Page 6: [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

7/28/2019 [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

http://slidepdf.com/reader/full/emc-311-chapter-2-getting-around-linux-on-raspberry-pi 6/12

• Pipes : way of 

chaining 2 programsThe output of one can serve asthe input to another. All Linuxprograms can read data from

standard input (stdin), writedata to standard output (stdout ), and throw errormessages to standard error (stderr ). Use the | operator, as in

this example:pi@raspberrypi ~ $ ls -la | less

* list all files, including hiddenfiles, then display on the

screen

• Redirection 

A command is executed and the

stdout output can be sent to afile. To redirect output from aprogram use the > operator:

pi@raspberrypi ~ $ ls > directoryListing.txt

6

Chapter 2 : Using the Linux c

ommands

Page 7: [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

7/28/2019 [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

http://slidepdf.com/reader/full/emc-311-chapter-2-getting-around-linux-on-raspberry-pi 7/12

Chapter 2 : Using the Linux

commands

• Redirect, then display the contents of a file on screen (less)

pi@raspberrypi ~ $ ls > flob.txt

pi@raspberrypi ~ $ less flob.txt 

• Dump the entire contents of a file to standard output (cat)

pi@raspberrypi ~ $ ls > wibble.txt

pi@raspberrypi ~ $ cat wibble.txt > wobble.txt

pi@raspberrypi ~ $ cat wibble.txt wobble.txt > wubble.txt 

*equivalent of copying one file to another with a new name

Look at just the last few lines of a file (such as the mostrecent entry in a log file), use tail and to see the beginning,

use head. 

• Searching for a string in one or more files (grep)

pi@raspberrypi ~ $ grep Puzzle */* 

7

Page 8: [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

7/28/2019 [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

http://slidepdf.com/reader/full/emc-311-chapter-2-getting-around-linux-on-raspberry-pi 8/12

• Processes – To see all processes (top)

pi@raspberrypi ~ $ top 

 –

list all the processes and their idnumbers (ps)

pi@raspberrypi ~ $ ps -aux | less 

 – Kill to stop it : incase

unresponsive(kill)

pi@raspberrypi ~ $ kill 95689 

8

Chapter 2 : Using the Linux commands

• Sudo and Permissions (sudo,

chown, chgrp, chmod)Linux is a multiuser operating system; the

general rule is that everyone owns their own

files and can create, modify, and delete them

within their own space on the filesystem. 

 – Allow users to act like super users for

performing tasks like installing softwarewithout the dangers of being logged in

as root (sudo). ie : interacting with

hardware directly,changing system-wide

configurations.

 –

Change the owner of file (chown) – Change the group of file (chgrp)

* Must be root to use chown and chgrp

pi@raspberrypi ~ $ sudo chown pi

garply.txt

pi@raspberrypi ~ $ sudo chgrp staff 

plugh.txt 

Page 9: [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

7/28/2019 [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

http://slidepdf.com/reader/full/emc-311-chapter-2-getting-around-linux-on-raspberry-pi 9/12

Chapter 2 : Using the Linux commands• Set individual permission (chmod )

 – File permissions for owner, group and everyone

 – The switches that can be used with chmod 

9

Page 10: [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

7/28/2019 [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

http://slidepdf.com/reader/full/emc-311-chapter-2-getting-around-linux-on-raspberry-pi 10/12

Chapter 2 : Using the Linux commands

• The Network

 – displays all of your network interfaces and the IP addresses

(ipconfig)

 – Test two way connection (ping)pi@raspberrypi ~ $ ping yahoo.com

 – Remote connection

*Setting the Secure Shell (ssh) by running raspi-config10

Page 11: [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

7/28/2019 [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

http://slidepdf.com/reader/full/emc-311-chapter-2-getting-around-linux-on-raspberry-pi 11/12

Chapter 2 : Using the Linux commands

• Remote connection

 – Setting the Secure Shell (ssh) by running raspi-config

 – From other computer running MS Window

• Click Start button>>All programs>>Accessories>>Remote

Desktop Connection• Type Computer: IP address

• Click connect button

• Select Module: sesman-Xvnc

• Type Username: pi

• Type Password: raspberry

• Same Raspberry Pi desktop will be displayed

11

Page 12: [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

7/28/2019 [EMC 311] Chapter 2 Getting Around Linux on Raspberry Pi

http://slidepdf.com/reader/full/emc-311-chapter-2-getting-around-linux-on-raspberry-pi 12/12

Chapter 2 : Using the Linux commands

• Setting the Date and Time (date  – set)

 – Need manually set because Raspberry but doesn’t have

additional hardware and a back up battery to save.$ sudo date --set="Sun Nov 18 1:55:16 EDT 2012“ 

• Installing New Software (apt-get, -install)

 – The program apt-get with the -install switch is used to

download software apt-get will even download all of the

other software that your package requires so you don’thave to go hunting around for dependencies (this

command installs the Emacs text editor):pi@raspberrypi ~ $ sudo apt-get install emacs

12