create fileCreate File on Linux

By: - Last Updated:

File on linux computer system can be created, moved, renamed, modified, grown, shrunk (truncated), and deleted. In most cases, software programs that are executed on the computer handle these operations, but the user of a computer can also modify files if necessary.

For instance, Microsoft Word files are normally created and modified by the Microsoft Word program in response to user commands, but the user can also move, rename, or delete these files directly by using a file manager program such as Windows Explorer (on Windows computers) or via terminal with command lines (CLI).

How To Create File on Linux?

You can easily create file on linux with the following methods touch, Multiple Files, and More Information via terminal on your system with the command line.

touch

“touch” command allows us to update the timestamps on existing files and directories as well as creating new file or empty files. This is probably the easiest and most memorable way to create new empty files.

To create a new file on linux:

  1. Open “Terminal” on linux system
  2. Keep on the current working directory or go to the specific directory (use “cd” to change directory) that you want to create a new file inside it
  3. Use “touch” command and specify “output-file-name”
  4. The syntax for using the “touch” command as shown below
    touch [option] [file-name.extention]
    • Create a “new file” in the current directory.
      touch docs.txt
    • verify created file listing using the “ls” command.
      ls -l
      -rw-rw-r-- 1 username username    0 Mei  4 01:09 docs.txt
    • If the file docs.txt doesn’t exist the command above will create it, otherwise, it will change its timestamps.
  5. Done, now you have a new file

Multiple Files

To create multiple files on linux:

  1. Open “Terminal” on linux system
  2. Keep on the current working directory or go to the specific directory (use “cd” to change directory) that you want to create a new file inside it
  3. Use “touch” command and specify “output-file-name”
  4. The syntax for using the “touch” command as shown below
    touch [option] [file1 file2 file3]
    • Create a “new file” in the current directory.
      touch docs1.txt docs2.txt docs3.txt
    • verify created file listing using the “ls” command.
      ls -l
      -rw-rw-r-- 1 username username    0 Mei  4 01:18 docs1.txt
      -rw-rw-r-- 1 username username    0 Mei  4 01:18 docs2.txt
      -rw-rw-r-- 1 username username    0 Mei  4 01:18 docs3.txt
    • If the files doesn’t exist the command above will create it, otherwise, it will change its timestamps.
  5. Done, now you have a new files

More Information

“touch” command related information can be obtained with “–help”.

touch --help

Usage: touch [OPTION]… FILE…
Update the access and modification times of each FILE to the current time.

A FILE argument that does not exist is created empty, unless -c or -h
is supplied.

A FILE argument string of – is handled specially and causes touch to
change the times of the file associated with standard output.

Mandatory arguments to long options are mandatory for short options too.
-a change only the access time
-c, –no-create do not create any files
-d, –date=STRING parse STRING and use it instead of current time
-f (ignored)
-h, –no-dereference affect each symbolic link instead of any referenced
file (useful only on systems that can change the
timestamps of a symlink)
-m change only the modification time
-r, –reference=FILE use this file’s times instead of current time
-t STAMP use [[CC]YY]MMDDhhmm[.ss] instead of current time
–time=WORD change the specified time:
WORD is access, atime, or use: equivalent to -a
WORD is modify or mtime: equivalent to -m
–help display this help and exit
–version output version information and exit

Note that the -d and -t options accept different time-date formats.

create file
image: create file on linux

In modern computer systems, files are typically accessed using names (filenames). In some operating systems, the name is associated with the file itself. In others, the file is anonymous, and is pointed to by links that have names. In the latter case, a user can identify the name of the link with the file itself, but this is a false analogue, especially where there exists more than one link to the same file.

Many computer systems use extensions in file names to help identify what they contain, also known as the file type. Extensions consist of a dot (period) at the end of a file name, followed by a few letters to identify the type of file. An extension of .txt identifies a text file; a .doc extension identifies any type of document or documentation, and so on.

Files can be located in directories. A name that refers to a file within a directory must be typically unique. In other words, there must be no identical names within a directory. However, in some operating systems, a name may include a specification of type that means a directory can contain an identical name for more than one type of object such as a directory and a file.

Leave a Reply

Your email address will not be published. Required fields are marked *