Helping ordinary people create extraordinary websites!

PHP in the Command Line

By Robert Plank
2005-05-25

Pipe down over there
Type this in: echo `date +%Y`

Gives us "2004".  You could even do something like this: echo `dir`

Which puts the directory listing all on one line.

But now, we put our newfound knowledge to good use.  Unix has another neat feature called piping, which means "take everything you would normally output to the screen here, and shove it whatever file I tell you to."  So say I had something like this:

echo "hey" > test.txt

Now type "dir" and you'll see a new file, test.txt, that wasn't there before.  View it off the web, or FTP it to your computer, do whatever you have to, to read the file.  It should contain the word "hey".

Likewise, dir > test.txt would store the directory listing into "test.txt".



Tutorial pages:
 1 Votes

You might also want to check these out:


Leave a Comment on "PHP in the Command Line"
You must be logged in to post a comment.

Link to This Tutorial Page!


GET OUR NEWSLETTERS