Exercise 9: Making Empty Files (Touch, New-Item)

In this exercise you learn how to make an empty file using the touch (new-item on Windows) command.

Do This

Linux/OSX

$ cd temp
$ touch iamcool.txt
$ ls
iamcool.txt
$

Windows

> cd temp
> New-Item iamcool.txt -type file
> ls


    Directory: C:\Users\zed\temp


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        12/17/2011   9:03 AM            iamcool.txt


>

You Learned This

You learned how to make an empty file. On Unix touch does this, and it also changes the times on the file. I rarely use it for anything other than making empty files. On Windows you don't have this command, so you learned how to use the New-Item command, which does the same thing but can also make new directories.

Do More

  • Unix: Make a directory, change to it, and then make a file in it. Then change one level up and run the rmdir command in this directory. You should get an error. Try to understand why you got this error.
  • Windows: Do the same thing, but you won't get an error. You'll get a prompt asking if you really want to remove the directory.

Buy Paper, PDF, or ePub (I Make 12%)

If you prefer Paper, PDF, or ePub then I recommend you buy it from my publisher at InformIT.com (run by Pearson). You can also sign up for the Free Support Course to receive a few key videos, get chat help, and errata for the book.

Buy Paper, PDF, or ePub from InformIT

Buy Learn Python the Hard Way, 5th Edition from Me (I make 100%)

When you buy Learn Python the Hard Way, 5th Edition directly from the author, Zed A. Shaw, you'll get access to the digital content for all 60 exercises, plus all 60+ videos that are normally sold separately. You'll also have access to direct help from Zed via Discord chat and live streams on special topics when I have time.

$29

Buy Learn Python The Hard Way, 5th Edition