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/macOS

$ 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 DRM-Free

When you buy directly from the author, Zed A. Shaw, you'll get a professional quality PDF and hours of HD Video, all DRM-free and yours to download.

$29.99

Buy Directly From The Author

Or, you can read Learn Ruby the Hard Way for free right here, video lectures not included.