Jump to content

CL-08: File Creation


Recommended Posts

Browse: [About the FAQ Forum] [Table of Contents] [FAQs] [Contribute] [CL: Command Line Questions]

 

CL-08: File Creation

 

This FAQ is to tell of some of the command line ways to create a file. There are many, and I won't say that this list is in any way complete; but here are a few:

  • Using a test editor (vi, vim, emacs, nano, etc.)
  • The Touch command

Let's start with the first one. I will go from the vim standpoint, because that's what I use. It's easy, but some people prefer other editors. That's what's great about Linux, though; everyone can have their choice. We're not forced into using 1 program over another.

 

The it's easy to create a file using vim. Just cd to the directory that you want the file in and

vim newfilename

 

If the file doesn't exist in the directory, it will be created and the editor (vim in this case) will be opened for you to edit the file.

 

Now, say you want to create a file but you don't want to edit it for whatever reason. For that you would use the touch command. For you to do this, it's easy. Just cd to your directory and

touch newfilename

 

This will create a file, with your users permissions, wherever you are in the directory structure (provided, of course, that you have the proper permissions).

 

There are other options for touch. Some of them, along with a brief description can be found here:

-a
--time=atime
--time=access
--time=use
 Change the access time only.

-c
--no-create
 Do not create files that do not exist.

-d
--date=time
 Use TIME instead of the current time. It can contain month names,
 timezones, `am' and `pm', etc.

-f
 Ignored; for compatibility with BSD versions of `touch'.

-m
--time=mtime
--time=modify
 Change the modification time only.

-r FILE
--reference=FILE
 Use the times of the reference FILE instead of the current time.

-t [[CC]YY]MMDDhhmm[.ss]
 Use the argument (optional four-digit or two-digit years, months,
 days, hours, minutes, optional seconds) instead of the current
 time. If the year is specified with with only two digits, then CC
 is 20 for years in the range 0 ... 68, and 19 for year in 69 ...
 99. If no digits of the year are specified, the argument is
 interpreted as a date in the current year.

 

You can also see the manfile on touch for more.

Link to comment
Share on other sites

 Share

×
×
  • Create New...