Jump to content
  • Announcements

    • spinynorman

      Mandriva Official Documentation

      Official documentation for extant versions of Mandriva can be found at doc.mandriva.com.   Documentation for the latest release may take some time to appear there. You can install all the manuals from the main repository if you have Mandriva installed - files are prefixed mandriva-doc.
    • paul

      Forum software upgrade   10/29/17

      So you may have noticed the forum software has upgraded !!!
      A few things that have changed. We no longer have community blogs (was never really used) We no longer have a portal page.
      We can discuss this, and decide whether it is needed (It costs money) See this thread: Here
Sign in to follow this  
liquidzoo

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

×