Another skill you’ll use frequently is creating files. You might think of creating files as getting an empty bucket that you can later fill with water...or sand...or rocks...or whatever. When you create a file, you designate an empty space that you can fill with programs, activity logs, your resume, or configurations—practically anything you want, or nothing at all.
Of course, you can always create a file by writing something in an editor and saving it, as described in Chapter 4, but you will some times encounter situations where you just need an empty file as a placeholder for later use. You create empty files using the touch command, as shown in Code Listing 2.2.
$ ls $ touch file.to.create $ ls -l file* -rw-rw-r– 1 ejr users 0 Jun 29 11:53 file.to.create $ touch -t 12312359 oldfile $ ls -l total 0 -rw-rw-r– 1 ejr users 0 Jun 29 11:53 file.to.create -rw-rw-r– 1 ejr users 0 Dec 31 1998 oldfile $ touch -t 200312312359 new.years.eve $ ls -l total 0 -rw-rw-r– 1 ejr users 0 Jun 29 11:53 file.to.create -rw-rw-r– 1 ejr users 0 Dec 31 2003 new.years.eve -rw-rw-r– 1 ejr users 0 Dec 31 1998 oldfile $ |
1. | touch file.to.create
To create a file, type touch followed by the name of the file. This creates an empty file. |
2. | ls -l file*
Optionally, verify that the file was created by typing ls –l file*. As shown in Code Listing 2.2, you’ll see the name of the new file as well as its length (0) and the date and time of its creation (likely seconds before the current time, if you’re following along). |
✓ Tips
You can also use touch to update a file’s date and time. For example, typing touch -t 12312359 oldfile at the prompt would update oldfile with a date of December 31, 23 hours, and 59 minutes in the current year. Or, typing touch -t 200612312359 new.years.eve would update the file called new.years.eve to the same time in the year 2006.
Each time you save changes in a file, the system automatically updates the date and time. See Chapter 4 for details about editing and saving files.
Refer to the sidebar Naming Directories (and Files) in this chapter for file-naming guidelines.
18.191.43.149