Your SlideShare is downloading. ×
0
Linux-Fu
for PHP Developers
About Me

Lorna Mitchell
Developer at Ibuildings
European Rep for http://phpwomen.org
Personal blog http://lornajane.net
C...
Linux-Fu
Outline

basic commands
first utilities
access
permissions
useful utilities
Linux Philosophy
Basic Commands
pwd

Print Working Directory - shows you where you
  are

lorna@taygete:~/Documents$ pwd
/home/lorna/Documents
ls

list files
-a for all including hidden files
 lorna@taygete:~/Documents$ ls -a
 .                        jam_labels.pd...
ls

-l for long list
ls -la
lorna@taygete:~/Documents$ ls -la
total 136
drwxr-xr-x 3 lorna lorna 4096 2009-04-24     09:37...
ls

-t for list by time
-r for sort in reverse order
lorna@taygete:~/Documents$ ls -lrt
total 128
-rw-r--r-- 1 lorna lorna...
ls

ls <path> to list contents of a different directory
cd

Change Directory
cd <dir> to enter a subdir
lorna@taygete:~$ cd /etc
lorna@taygete:/etc$ cd cron.d
lorna@taygete:/etc/...
cd

cd ~ to go home
lorna@taygete:/etc$ cd ~
lorna@taygete:~$ pwd
/home/lorna
lorna@taygete:~$



cd - to go back to where...
First Utilities
touch

creates an empty file with current timestamp
no feedback (this is *nix)


lorna@taygete:~/talks/temp$ touch unicorn...
cat

outputs a file to your terminal
cat <file>
lorna@taygete:~/talks$ cat orange.txt
Oranges are not the only fruit
(name...
less/more

pager for viewing longer content
more <file>
less <file>
use less – it really is more in this case
stdin/stdout

stdin quot;standard inquot; – input to a program, usually
  command line arguments
stdout quot;standard outq...
stdin/stdout




               photo credit: ppdigital
pipe

quot;chainingquot; operator
output of one program pushed along the pipe to
  the input of the next
pipe

cat orange.txt index.php | more
lorna@taygete:~/talks$ cat orange.txt index.php | more
Oranges are not the only frui...
file redirection operators

a.k.a. quot;pointy bracketsquot;
< and >
> directs stdout to the named file

>> appends to the...
file redirection operators

lorna@taygete:~/talks$ mysqldump --compact -u root -p test
Enter password:
SET @saved_cs_clien...
file redirection operators

lorna@taygete:~/talks$ mysqldump --compact -u root -p test >
test.sql
Enter password:
lorna@ta...
file redirection operators

< directs the contents of the file to stdin


 lorna@taygete:~/talks$ mysql -u root -p test < ...
Access
telnet

not now used much for server access
useful for direct port access
telnet <host> <port>
ssh

Secure SHell
prompts for password, you arrive at command
  prompt
scp

secure copy
copies files over a one-off ssh connection
if you have ssh access, this is available
scp <source> <target...
scp

lorna@taygete:~$ scp cherries.jpg lorna@rivendell.local:fruit.jpg
lorna@rivendell.local's password:
cherries.jpg     ...
scp

lorna@taygete:~$ scp cherries.jpg lorna@rivendell.local:
lorna@rivendell.local's password:
cherries.jpg              ...
scp

lorna@taygete:~$ scp -r talks lorna@rivendell.local:talks/
lorna@rivendell.local's password:
thing.jpg               ...
sftp

SSH File Transfer Protocol
similar to FTP
many FTP clients handle SFTP
more secure
easy to set up, part of SSH server
Permissions
Permissions

10 characters of information
see in the output of ls
lorna@taygete:~/Documents$ ls -la
total 136
drwxr-xr-x 3...
Permissions
Permissions
chmod

change permissions
chmod <class><operator><mode> <file>
class: u,g,o,a (user, group, other, all)
operator: +, -, =
...
chmod

add execute permission for group
lorna@taygete:~/Documents$ chmod g+rx memcache.rtf
lorna@taygete:~/Documents$ ls -...
chown

chown lorna:users memcache.rtf
lorna@taygete:~/Documents$ chown lorna:users memcache.rtf
lorna@taygete:~/Documents$...
root

superuser
don't log in as root
log in, then su (substitute user)
may need root privileges, to perform certain
  acti...
sudo

avoids using root account
gives root for a single command
sudo




       http://xkcd.com/149/
Useful Utilities
cURL

tool for talking to the world over http
lorna@taygete:~$ curl http://localhost
Example Home Page

Array
(
)
cURL

<?php

echo quot;Example Home Pagennquot;;

print_r($_POST);

?>
cURL

checking actual browser response
  headers/content
curl -I http://localhost
lorna@taygete:~$ curl -I http://localhos...
cURL

posting variables
lorna@taygete:~$ curl -X POST http://localhost -d fruit=apple
-d user=lornajane
Example Home Page
...
wget

web downloader
lorna@taygete:~$ wget
http://www.splitbrain.org/_media/projects/dokuwiki/dokuwiki-2009-02-14.
--2009-...
wget

to mirror a site
  wget -m http://lornajane.net
to resume large downloads
  wget -c http://localhost
grep

finding things (Global/Regular Expression/Print)
grep [options] [pattern] [target]
grep

discover functions
lorna@rivendell:~/svndir/snapshot/lib$ grep function Service.class.php
 * This class holds the fu...
grep

look for class names in source tree
lorna@rivendell:~/svndir/phergie$ grep -R '^class ' * | grep -v .svn |
Phergie/E...
grep

 Recursive and case insensitive
lorna@rivendell:~/svndir/snapshot$ grep -Ri 'select * from' *
lib/Model/Miscinfo.cla...
find

powerful quot;grepquot; using file metadata rather than
  content
can search by name

find . -name .htaccess


also ...
diff

shows differences between files, doesn't show
  you what is the same
lorna@taygete:~/talks$ diff misc.php.old misc.p...
diff

 Unified diff format
lorna@taygete:~/talks$ diff -u misc.php.old misc.php
--- misc.php.old         2009-04-24 10:56:...
grep

lorna@taygete:~/talks$ diff -u misc.php.old misc.php > patch.txt
patch

patch applies diff files
patch

lorna@taygete:~/talks$ cat example.php
<?php

$link   = mysql_connect('localhost','app_user','yorkshirepud');

?>
l...
tar

Tape ARchive
for gluing together files, for transfer
 lorna@taygete:~/talks$ ls
 cherries.jpg example.php     long_fi...
nano

widely available lightweight editor
designed as a non-pine equivalent to pico (PIne
  COmposer)
instructions are on-...
nano
wc

word count
for counting lines

lorna@taygete:~/tek09$ wc -l linux-fu_content.txt
283 linux-fu_content.txt
tail

looking at the end of a file
tail -n50 access.log
tail -f access.log
screen

opening several sessions in one window
can detach, log out, come back
screen

protects against connection dropping
saves logging into the same server many times
use .screenrc for config
screen
man

man pages are the manual
man <command>
  name
  synopsis (example arguments)
  description (all the switches)
  examp...
man
lorna@taygete:~$ man pwd
PWD(1)                                           User Commands

NAME
       pwd - print name ...
Questions?




http://joind.in/201
File Locations
log files

/var/log
  /var/log/apache2/access.log
apache config

ubuntu, debian
  /etc/apache2/sites-available
redhat
  /etc/httpd/httpd.conf
/usr/local

for stuff that you've installed/added
Processes
ps

Process Status
shows what is running, pid, user
ps

ps ax
ps aux
use with grep
 6761   ?       Ss   0:00   /usr/sbin/apache2   -k   start
 8009   ?       S    0:00   /usr...
top

show current top processes
sort by zxc
z for colour
x for column highlight
c to show full command
< > to change which...
check apache is running

use grep - look for quot;apachequot; or quot;httpdquot;
if not:
apache2ctl restart
service httpd ...
check mysql is running

use grep
if not:
/etc/init.d/mysql start
Basic Commands
mkdir

mkdir
make directory

lorna@taygete:~/temp$ ls
lorna@taygete:~/temp$ mkdir examples
lorna@taygete:~/temp$ ls
exampl...
mv and cp

move and copy files
lorna@taygete:~/temp$ ls
cherries.jpg
lorna@taygete:~/temp$ mv cherries.jpg oranges.jpg
lor...
rm

remove files/directories
cherries.jpg examples oranges.jpg
lorna@taygete:~/temp$ rm oranges.jpg
lorna@taygete:~/temp$ ...
ln

    link - creates a symlink or alias between
       directories
 temp




mcached-0.26.tar.gz              ZendFramew...
cURL

great for services
flickr example
curl -X POST http://api.flickr.com/services/rest/
  -d method=flickr.photos.getRec...
cURL
<?xml version=quot;1.0quot; encoding=quot;utf-8quot; ?>
<rsp stat=quot;okquot;>
<photos page=quot;1quot; pages=quot;2...
Upcoming SlideShare
Loading in...5
×

Linux-Fu for PHP Developers

6,666

Published on

A tour of the main tools I use from the linux command line in my line of work as a PHP developer

Published in: Technology
1 Comment
21 Likes
Statistics
Notes
  • whats nice for me having looked at this is that I know all these commands so as a php developer maybe I'm doing something right :-D
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
6,666
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
265
Comments
1
Likes
21
Embeds 0
No embeds

No notes for slide

Transcript of "Linux-Fu for PHP Developers"

  1. 1. Linux-Fu for PHP Developers
  2. 2. About Me Lorna Mitchell Developer at Ibuildings European Rep for http://phpwomen.org Personal blog http://lornajane.net Compulsive keyboard user (for accessibility reasons)
  3. 3. Linux-Fu
  4. 4. Outline basic commands first utilities access permissions useful utilities
  5. 5. Linux Philosophy
  6. 6. Basic Commands
  7. 7. pwd Print Working Directory - shows you where you are lorna@taygete:~/Documents$ pwd /home/lorna/Documents
  8. 8. ls list files -a for all including hidden files lorna@taygete:~/Documents$ ls -a . jam_labels.pdf netball .. libmemcache_install_notes.txt tek_instruction advent_web_services.rtf linux-fu_geekup.txt using_the_commu girlgeek_post2.txt memcache.odt jam_labels.odt memcache.rtf
  9. 9. ls -l for long list ls -la lorna@taygete:~/Documents$ ls -la total 136 drwxr-xr-x 3 lorna lorna 4096 2009-04-24 09:37 . drwxr-xr-x 66 lorna lorna 4096 2009-04-23 17:33 .. -rw-r--r-- 1 lorna lorna 16790 2008-12-04 22:54 advent_web_services.rt -rw-r--r-- 1 lorna lorna 1263 2008-12-10 12:16 girlgeek_post2.txt -rw-r--r-- 1 lorna lorna 10700 2008-12-20 16:08 jam_labels.odt -rw-rw-rw- 1 lorna lorna 6747 2008-12-25 21:35 jam_labels.pdf -rw-r--r-- 1 lorna lorna 316 2009-03-19 19:28 libmemcache_install_no -rw-r--r-- 1 lorna lorna 189 2009-02-08 16:02 linux-fu_geekup.txt -rw-r--r-- 1 lorna lorna 33275 2008-12-04 11:37 memcache.odt -rw-r-xr-- 1 lorna users 28205 2008-12-04 11:37 memcache.rtf drwxr-xr-x 2 lorna lorna 4096 2009-04-24 09:37 netball -rw-r--r-- 1 lorna lorna 940 2008-12-09 09:43 tek_instructions.txt -rw-r--r-- 1 lorna lorna 461 2008-11-28 22:49 using_the_community.tx
  10. 10. ls -t for list by time -r for sort in reverse order lorna@taygete:~/Documents$ ls -lrt total 128 -rw-r--r-- 1 lorna lorna 461 2008-11-28 22:49 using_the_community.txt -rw-r--r-- 1 lorna lorna 33275 2008-12-04 11:37 memcache.odt -rw-r-xr-- 1 lorna users 28205 2008-12-04 11:37 memcache.rtf -rw-r--r-- 1 lorna lorna 16790 2008-12-04 22:54 advent_web_services.rtf -rw-r--r-- 1 lorna lorna 940 2008-12-09 09:43 tek_instructions.txt -rw-r--r-- 1 lorna lorna 1263 2008-12-10 12:16 girlgeek_post2.txt -rw-r--r-- 1 lorna lorna 10700 2008-12-20 16:08 jam_labels.odt -rw-rw-rw- 1 lorna lorna 6747 2008-12-25 21:35 jam_labels.pdf -rw-r--r-- 1 lorna lorna 189 2009-02-08 16:02 linux-fu_geekup.txt -rw-r--r-- 1 lorna lorna 316 2009-03-19 19:28 libmemcache_install_not drwxr-xr-x 2 lorna lorna 4096 2009-04-24 09:37 netball
  11. 11. ls ls <path> to list contents of a different directory
  12. 12. cd Change Directory cd <dir> to enter a subdir lorna@taygete:~$ cd /etc lorna@taygete:/etc$ cd cron.d lorna@taygete:/etc/cron.d$ cd .. to go up a level lorna@taygete:/etc/cron.d$ cd .. lorna@taygete:/etc$
  13. 13. cd cd ~ to go home lorna@taygete:/etc$ cd ~ lorna@taygete:~$ pwd /home/lorna lorna@taygete:~$ cd - to go back to where you came from lorna@taygete:~$ cd - lorna@taygete:/etc$ pwd /etc
  14. 14. First Utilities
  15. 15. touch creates an empty file with current timestamp no feedback (this is *nix) lorna@taygete:~/talks/temp$ touch unicorns.txt lorna@taygete:~/talks/temp$ ls -lA total 0 -rw-r--r-- 1 lorna lorna 0 2009-04-24 09:50 unicorns.txt
  16. 16. cat outputs a file to your terminal cat <file> lorna@taygete:~/talks$ cat orange.txt Oranges are not the only fruit (name of a book) lorna@taygete:~/talks$
  17. 17. less/more pager for viewing longer content more <file> less <file> use less – it really is more in this case
  18. 18. stdin/stdout stdin quot;standard inquot; – input to a program, usually command line arguments stdout quot;standard outquot; – output, usually to your screen
  19. 19. stdin/stdout photo credit: ppdigital
  20. 20. pipe quot;chainingquot; operator output of one program pushed along the pipe to the input of the next
  21. 21. pipe cat orange.txt index.php | more lorna@taygete:~/talks$ cat orange.txt index.php | more Oranges are not the only fruit (name of a book) <?php class Response { public function output() { header('Content-type: text/xml'); echo '<?xml version=quot;1.0quot;?>'; echo quot;nquot;; } } --More--
  22. 22. file redirection operators a.k.a. quot;pointy bracketsquot; < and > > directs stdout to the named file >> appends to the file rather than truncating it before outputting
  23. 23. file redirection operators lorna@taygete:~/talks$ mysqldump --compact -u root -p test Enter password: SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; CREATE TABLE `users` ( `user_id` int(11) NOT NULL auto_increment, `name` varchar(20) default NULL, PRIMARY KEY (`user_id`) ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; SET character_set_client = @saved_cs_client; INSERT INTO `users` VALUES (1,'lornajane');
  24. 24. file redirection operators lorna@taygete:~/talks$ mysqldump --compact -u root -p test > test.sql Enter password: lorna@taygete:~/talks$ lorna@taygete:~/talks$ mysqldump --compact -u root -p test | gzip > test.sql.gz Enter password: lorna@taygete:~/talks$
  25. 25. file redirection operators < directs the contents of the file to stdin lorna@taygete:~/talks$ mysql -u root -p test < test.sql Enter password: lorna@taygete:~/talks$
  26. 26. Access
  27. 27. telnet not now used much for server access useful for direct port access telnet <host> <port>
  28. 28. ssh Secure SHell prompts for password, you arrive at command prompt
  29. 29. scp secure copy copies files over a one-off ssh connection if you have ssh access, this is available scp <source> <target> source and/or target can be remote paths
  30. 30. scp lorna@taygete:~$ scp cherries.jpg lorna@rivendell.local:fruit.jpg lorna@rivendell.local's password: cherries.jpg 100% 162KB 162.3KB/s 00:00
  31. 31. scp lorna@taygete:~$ scp cherries.jpg lorna@rivendell.local: lorna@rivendell.local's password: cherries.jpg 100% 162KB 162.3KB/s 00:00
  32. 32. scp lorna@taygete:~$ scp -r talks lorna@rivendell.local:talks/ lorna@rivendell.local's password: thing.jpg 100% 162KB 162.3KB/s 00:00 credits.txt 100% 68 0.1KB/s 00:00 index.php 100% 167 0.2KB/s 00:00 cherries.jpg 100% 162KB 162.3KB/s 00:00 orange.txt 100% 44 0.0KB/s 00:00 misc.php 100% 59 0.1KB/s 00:00 long_file.txt 100% 2383 2.3KB/s 00:00 what.jpg 100% 162KB 162.3KB/s 00:00
  33. 33. sftp SSH File Transfer Protocol similar to FTP many FTP clients handle SFTP more secure easy to set up, part of SSH server
  34. 34. Permissions
  35. 35. Permissions 10 characters of information see in the output of ls lorna@taygete:~/Documents$ ls -la total 136 drwxr-xr-x 3 lorna lorna 4096 2009-04-24 09:37 . drwxr-xr-x 66 lorna lorna 4096 2009-04-23 17:33 .. -rw-r--r-- 1 lorna lorna 16790 2008-12-04 22:54 advent_web_services.rt -rw-r--r-- 1 lorna lorna 1263 2008-12-10 12:16 girlgeek_post2.txt -rw-r--r-- 1 lorna lorna 10700 2008-12-20 16:08 jam_labels.odt -rw-rw-rw- 1 lorna lorna 6747 2008-12-25 21:35 jam_labels.pdf -rw-r--r-- 1 lorna lorna 316 2009-03-19 19:28 libmemcache_install_no -rw-r--r-- 1 lorna lorna 189 2009-02-08 16:02 linux-fu_geekup.txt -rw-r--r-- 1 lorna lorna 33275 2008-12-04 11:37 memcache.odt -rw-r-xr-- 1 lorna users 28205 2008-12-04 11:37 memcache.rtf drwxr-xr-x 2 lorna lorna 4096 2009-04-24 09:37 netball -rw-r--r-- 1 lorna lorna 940 2008-12-09 09:43 tek_instructions.txt -rw-r--r-- 1 lorna lorna 461 2008-11-28 22:49 using_the_community.tx
  36. 36. Permissions
  37. 37. Permissions
  38. 38. chmod change permissions chmod <class><operator><mode> <file> class: u,g,o,a (user, group, other, all) operator: +, -, = mode: r,w,x, or any combination
  39. 39. chmod add execute permission for group lorna@taygete:~/Documents$ chmod g+rx memcache.rtf lorna@taygete:~/Documents$ ls -lA total 132 -rw-r--r-- 1 lorna lorna 16790 2008-12-04 22:54 advent_web_services.rt lrwxrwxrwx 1 lorna lorna 22 2009-03-16 12:04 downloads -> /home/lor -rw-r--r-- 1 lorna lorna 1263 2008-12-10 12:16 girlgeek_post2.txt -rw-r--r-- 1 lorna lorna 10700 2008-12-20 16:08 jam_labels.odt -rw-rw-rw- 1 lorna lorna 6747 2008-12-25 21:35 jam_labels.pdf -rw-r--r-- 1 lorna lorna 189 2009-02-08 16:02 linux-fu_geekup.txt -rw-r--r-- 1 lorna lorna 33275 2008-12-04 11:37 memcache.odt -rw-r-xr-- 1 lorna lorna 28205 2008-12-04 11:37 memcache.rtf -rw-r--r-- 1 lorna lorna 9939 2009-03-09 15:23 netball_cancellation.p -rw-r--r-- 1 lorna lorna 940 2008-12-09 09:43 tek_instructions.txt -rw-r--r-- 1 lorna lorna 461 2008-11-28 22:49 using_the_community.tx
  40. 40. chown chown lorna:users memcache.rtf lorna@taygete:~/Documents$ chown lorna:users memcache.rtf lorna@taygete:~/Documents$ ls -lA total 132 -rw-r--r-- 1 lorna lorna 16790 2008-12-04 22:54 advent_web_services.rt lrwxrwxrwx 1 lorna lorna 22 2009-03-16 12:04 downloads -> /home/lor -rw-r--r-- 1 lorna lorna 1263 2008-12-10 12:16 girlgeek_post2.txt -rw-r--r-- 1 lorna lorna 10700 2008-12-20 16:08 jam_labels.odt -rw-rw-rw- 1 lorna lorna 6747 2008-12-25 21:35 jam_labels.pdf -rw-r--r-- 1 lorna lorna 189 2009-02-08 16:02 linux-fu_geekup.txt -rw-r--r-- 1 lorna lorna 33275 2008-12-04 11:37 memcache.odt -rw-r-xr-- 1 lorna users 28205 2008-12-04 11:37 memcache.rtf -rw-r--r-- 1 lorna lorna 9939 2009-03-09 15:23 netball_cancellation.p -rw-r--r-- 1 lorna lorna 940 2008-12-09 09:43 tek_instructions.txt -rw-r--r-- 1 lorna lorna 461 2008-11-28 22:49 using_the_community.tx
  41. 41. root superuser don't log in as root log in, then su (substitute user) may need root privileges, to perform certain actions
  42. 42. sudo avoids using root account gives root for a single command
  43. 43. sudo http://xkcd.com/149/
  44. 44. Useful Utilities
  45. 45. cURL tool for talking to the world over http lorna@taygete:~$ curl http://localhost Example Home Page Array ( )
  46. 46. cURL <?php echo quot;Example Home Pagennquot;; print_r($_POST); ?>
  47. 47. cURL checking actual browser response headers/content curl -I http://localhost lorna@taygete:~$ curl -I http://localhost HTTP/1.1 200 OK Date: Mon, 16 Mar 2009 12:35:10 GMT Server: Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4.1 with Suhosin- Patch X-Powered-By: PHP/5.2.6-2ubuntu4.1 Vary: Accept-Encoding Content-Type: text/html (that's a capital i)
  48. 48. cURL posting variables lorna@taygete:~$ curl -X POST http://localhost -d fruit=apple -d user=lornajane Example Home Page Array ( [fruit] => apple [user] => lornajane )
  49. 49. wget web downloader lorna@taygete:~$ wget http://www.splitbrain.org/_media/projects/dokuwiki/dokuwiki-2009-02-14. --2009-04-24 10:40:16-- http://www.splitbrain.org/_media/projects/dokuwiki/dokuwiki-2009-02-14. Resolving www.splitbrain.org... 78.46.97.149 Connecting to www.splitbrain.org|78.46.97.149|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 1770454 (1.7M) [application/octet-stream] Saving to: `dokuwiki-2009-02-14.tgz' 100%[=================================>] 1,770,454 1.39M/s in 1.2s 2009-04-24 10:40:18 (1.39 MB/s) - `dokuwiki-2009-02-14.tgz' saved [1770
  50. 50. wget to mirror a site wget -m http://lornajane.net to resume large downloads wget -c http://localhost
  51. 51. grep finding things (Global/Regular Expression/Print) grep [options] [pattern] [target]
  52. 52. grep discover functions lorna@rivendell:~/svndir/snapshot/lib$ grep function Service.class.php * This class holds the functionality of the out-ward facing part of * This function is called to add a new request to the queue. public function requestShot($accountID, $requestURL, $returnURL = N $height=75, $width=100) { function getShotStatus($accountID, $transactionID) { function getAccountStatus($accountID) { function getShotList($accountID, $status=NULL) { function getShot($accountID, $transactionID) {
  53. 53. grep look for class names in source tree lorna@rivendell:~/svndir/phergie$ grep -R '^class ' * | grep -v .svn | Phergie/Event/Response.php:class Phergie_Event_Response Phergie/Event/Request.php:class Phergie_Event_Request Phergie/Driver/Streams.php:class Phergie_Driver_Streams extends Phergie bstract Phergie/Plugin/Drink.php:class Phergie_Plugin_Drink extends Phergie_Plu act_Command Phergie/Plugin/ModuleList.php:class Phergie_Plugin_ModuleList extends P ugin_Abstract_Command Phergie/Plugin/Debug.php:class Phergie_Plugin_Debug extends Phergie_Plu act_Command Phergie/Plugin/Twitter/twitter.class.php:class Twitter { Phergie/Plugin/Twitter/laconica.class.php:class Twitter_Laconica extend {
  54. 54. grep Recursive and case insensitive lorna@rivendell:~/svndir/snapshot$ grep -Ri 'select * from' * lib/Model/Miscinfo.class.php: $row = $dbh->read('select * fro lib/Model/Transaction.class.php: $row = $dbh->read('select * >quote($transaction_id).' limit 1'); lib/Model/Transaction.class.php: $row = $dbh->read('select * >quote($transaction_id).' and account_id = '.$dbh->quote($account_id).' lib/Model/Transaction.class.php: $sql = 'select * from trans lib/Model/Transaction.class.php: $sql = 'select * from trans lib/Model/File.class.php: $row = $dbh->read('select * from fi lib/Model/Account.class.php: $row = $dbh->read('select * fro lib/DBL/Database.class.php: * $rows = $db->read('select * from aTable')
  55. 55. find powerful quot;grepquot; using file metadata rather than content can search by name find . -name .htaccess also by modified time, by size, etc ...
  56. 56. diff shows differences between files, doesn't show you what is the same lorna@taygete:~/talks$ diff misc.php.old misc.php 3c3 < $link = mysql_connect('localhost','app_user','yorkshirepud'); --- > $link = mysql_connect('localhost','lorna','candyfloss');
  57. 57. diff Unified diff format lorna@taygete:~/talks$ diff -u misc.php.old misc.php --- misc.php.old 2009-04-24 10:56:08.000000000 +0100 +++ misc.php 2009-04-24 10:56:51.000000000 +0100 @@ -1,6 +1,6 @@ <?php -$link = mysql_connect('localhost','app_user','yorkshirepud'); +$link = mysql_connect('localhost','lorna','candyfloss'); $rhyme = quot;Mary Had A Little Lambquot;; echo $rhyme;
  58. 58. grep lorna@taygete:~/talks$ diff -u misc.php.old misc.php > patch.txt
  59. 59. patch patch applies diff files
  60. 60. patch lorna@taygete:~/talks$ cat example.php <?php $link = mysql_connect('localhost','app_user','yorkshirepud'); ?> lorna@taygete:~/talks$ patch example.php < patch.txt patching file example.php lorna@taygete:~/talks$ cat example.php <?php $link = mysql_connect('localhost','lorna','candyfloss'); ?> lorna@taygete:~/talks$
  61. 61. tar Tape ARchive for gluing together files, for transfer lorna@taygete:~/talks$ ls cherries.jpg example.php long_file.txt orange.txt temp test.s credits.txt index.php misc.php patch.txt test.sql thing. lorna@taygete:~/talks$ tar -zcf talks.tgz * lorna@taygete:~/talks$ ls cherries.jpg example.php long_file.txt orange.txt talks.tgz test. credits.txt index.php misc.php patch.txt temp test. lorna@taygete:~/talks$
  62. 62. nano widely available lightweight editor designed as a non-pine equivalent to pico (PIne COmposer) instructions are on-screen
  63. 63. nano
  64. 64. wc word count for counting lines lorna@taygete:~/tek09$ wc -l linux-fu_content.txt 283 linux-fu_content.txt
  65. 65. tail looking at the end of a file tail -n50 access.log tail -f access.log
  66. 66. screen opening several sessions in one window can detach, log out, come back
  67. 67. screen protects against connection dropping saves logging into the same server many times use .screenrc for config
  68. 68. screen
  69. 69. man man pages are the manual man <command> name synopsis (example arguments) description (all the switches) examples, if you are lucky some tools use quot;infoquot; instead
  70. 70. man lorna@taygete:~$ man pwd PWD(1) User Commands NAME pwd - print name of current/working directory SYNOPSIS pwd [OPTION] DESCRIPTION Print the full filename of the current working directory. --help display this help and exit --version output version information and exit NOTE: your shell may have its own version of pwd, which usually Please refer to your shellâÀÙs documentation for details about t
  71. 71. Questions? http://joind.in/201
  72. 72. File Locations
  73. 73. log files /var/log /var/log/apache2/access.log
  74. 74. apache config ubuntu, debian /etc/apache2/sites-available redhat /etc/httpd/httpd.conf
  75. 75. /usr/local for stuff that you've installed/added
  76. 76. Processes
  77. 77. ps Process Status shows what is running, pid, user
  78. 78. ps ps ax ps aux use with grep 6761 ? Ss 0:00 /usr/sbin/apache2 -k start 8009 ? S 0:00 /usr/sbin/apache2 -k start 8010 ? S 0:00 /usr/sbin/apache2 -k start 8011 ? S 0:00 /usr/sbin/apache2 -k start 8012 ? S 0:00 /usr/sbin/apache2 -k start 8013 ? S 0:00 /usr/sbin/apache2 -k start 24209 pts/4 S+ 0:00 grep apache
  79. 79. top show current top processes sort by zxc z for colour x for column highlight c to show full command < > to change which column we're sorting by ** q to quit
  80. 80. check apache is running use grep - look for quot;apachequot; or quot;httpdquot; if not: apache2ctl restart service httpd restart
  81. 81. check mysql is running use grep if not: /etc/init.d/mysql start
  82. 82. Basic Commands
  83. 83. mkdir mkdir make directory lorna@taygete:~/temp$ ls lorna@taygete:~/temp$ mkdir examples lorna@taygete:~/temp$ ls examples
  84. 84. mv and cp move and copy files lorna@taygete:~/temp$ ls cherries.jpg lorna@taygete:~/temp$ mv cherries.jpg oranges.jpg lorna@taygete:~/temp$ ls oranges.jpg lorna@taygete:~/temp$ cp oranges.jpg cherries.jpg lorna@taygete:~/temp$ ls cherries.jpg oranges.jpg lorna@taygete:~/temp$ cp /etc/php5/cli/php.ini php-cli.ini lorna@taygete:~/temp$ ls cherries.jpg oranges.jpg php-cli.ini
  85. 85. rm remove files/directories cherries.jpg examples oranges.jpg lorna@taygete:~/temp$ rm oranges.jpg lorna@taygete:~/temp$ touch examples/dewdrops.txt lorna@taygete:~/temp$ rm examples/ rm: cannot remove `examples/': Is a directory lorna@taygete:~/temp$ rmdir examples rmdir: failed to remove `examples': Directory not empty lorna@taygete:~/temp$ rm -rf examples lorna@taygete:~/temp$ ls cherries.jpg
  86. 86. ln link - creates a symlink or alias between directories temp mcached-0.26.tar.gz ZendFramework-1.7.6-minimal _andean_explorer_large.jpg ZendFramework-1.7.6-minimal.tar.gz resenter-screen-linuxintel.oxt
  87. 87. cURL great for services flickr example curl -X POST http://api.flickr.com/services/rest/ -d method=flickr.photos.getRecent -d api_key=853b05c9... -d per_page=5
  88. 88. cURL <?xml version=quot;1.0quot; encoding=quot;utf-8quot; ?> <rsp stat=quot;okquot;> <photos page=quot;1quot; pages=quot;200quot; perpage=quot;5quot; total=quot;1000quot;> <photo id=quot;3359907386quot; owner=quot;24259661@N03quot; secret=quot;abcd3374c4quot; server=quot;3593quot; farm=quot;4quot; title=quot;Sandford 2009quot; ispublic=quot;1quot; isfriend=quot;0quot; isfamily=quot;0quot; /> <photo id=quot;3359907364quot; owner=quot;12383345@N06quot; secret=quot;0e5637d188quot; server=quot;3607quot; farm=quot;4quot; title=quot;DSC00159quot; ispublic=quot;1quot; isfriend=quot;0quot; isfamily=quot;0quot; /> <photo id=quot;3359907350quot; owner=quot;84656095@N00quot; secret=quot;3ca7085d12quot; server=quot;3461quot; farm=quot;4quot; title=quot;greenquot; ispublic=quot;1quot; isfriend=quot;0quot; isfamily=quot;0quot; /> <photo id=quot;3359088077quot; owner=quot;20633056@N04quot; secret=quot;3d03f2b935quot; server=quot;3654quot; farm=quot;4quot; title=quot;03cquot; ispublic=quot;1quot; isfriend=quot;0quot; isfamily=quot;0quot; /> <photo id=quot;3359088059quot; owner=quot;33581202@N07quot; secret=quot;efa70c71f0quot; server=quot;3607quot; farm=quot;4quot; title=quot;DSCF4768quot; ispublic=quot;1quot; isfriend=quot;0quot; isfamily=quot;0quot; /> </photos> </rsp>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×