Chapter 8 Discover States and Transitions

Software is full of surprises. No matter how careful or skilled you are, when you create software it can behave differently than you intended. Exploratory testing mitigates those risks. Part 1 introduces the core, essential skills of a master explorer. You’ll learn to craft charters to guide your exploration, to observe wh

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Creating Files

Small, Sharp Software Tools — by Brian P. Hogan (41 / 107)

👈 Chapter 4 Working with Files and Directories | TOC | Reading Larger Files 👉

In Creating and Reading Files, you learned how to use the echo command and redirection to create files. This is one of many ways to create files on the command line. Let’s look at a few alternatives.

If you only need to create an empty file, you can use the touch command. This command is designed to update the timestamp of a file. It’s common for programs to watch a file for changes and then react to those changes by executing a process. For example, you might have a process that runs tests whenever a file changes, but you don’t actually want to open the file and make a change. You can use touch to modify the file without actually changing the contents. This would then trigger the program or process monitoring the file.

However, if the specified file doesn’t exist, the touch command creates the file. This makes touch a very popular tool for creating files quickly.

Test it out. Navigate to your home directory:

Now, use touch to create a new file named file.txt:

Verify that it exists by using the ls -lh command:

The file doesn’t have any contents, but it was created successfully. This is a handy way to create a blank file that you can then modify elsewhere.

Remember that touch updates a file’s timestamp whenever you run it. Wait a minute and run the touch command on this file again. Then get a new listing:

You’ll notice that the timestamp has changed.

You can use touch to operate on more than one file at once. All you have to do is provide it with a list of filenames, separated with spaces. Give it a try:

This creates the three files, index.html, about.html, and style.css in the current directory. Verify this with the ls command:

Add a comment

Related posts:

Protect the Client Application and Data

Cyber-criminals have your web applications in their crosshairs. They search for and exploit common security mistakes in your web application to steal user data. Learn how you can secure your Node.js applications, database and web server to avoid these security holes. Discover the primary attack vectors against web applications,

Deleting Facebook made me a better friend.

When I deleted Facebook, I thought I was doing it for myself. Saving time, weaning myself off of my phone, protecting my privacy, etc. By scrolling through my newsfeed and “liking” posts and…

Landing Page Not Converting? Time for a Funnel

Your landing page is up with product pics proudly displayed. A beautiful “Buy Now” button is conspicuously featured on the page and users can get information on pricing, color selection, multiple…