Linux touch Command Tutorial with

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-touch-command-tutorial/
PINTEREST
PINTEREST
INSTAGRAM

Linux touch command is used to create files and change files date time related attributes like access time etc. Creating empty files is most popular use case by the way. In this tutorial we will look how to use different features of touch command.

Create Empty File

The most popular usage of touch command is creating empty files. For this option we do not need to provide any option. We will just put file name we want to create. In this example we will create an empty file named file1 .

Create Multiple Empty Files

In previous example we have created a single empty file. What if we need multiple files to be created in a single command shot. touch supports multiple file creation. In this file we will create multiple files named file2 , file3 , file4 .

Create Files Named A..Z

We can provide multiple file names to the touch to create them in a empty state. But providing them one by one if they are structures is trivial task. We can use bash feature to expand given ile names. In this example we will create files named A , B , C , … , Z .

Create Files Named A..Z

Create Files Named A..Z

Create Files Named 1…100

Another example to create multiple  files is file names 1 to 100 .

Create Files Named 1...100

Create Files Named 1…100

Specify Multiple Files Extension

We may need too specify the extension of files we are creating. In this example we will create files from 1 to 100 those file extension is txt .

LEARN MORE  Git - File Operations

Specify Multiple Files Extension

Specify Multiple Files Extension

Change File Access of File

File system hold information like last access a about files. touch command can change these values easily. We will use -a option to update last access  time to the current time.

Change Modification Time of File

We can also update last modification time to the current time with the -m option like below.

Do Not Overwrite

By default whether the given file exist newfile is created and if a file with the same name exist it is overwritten. We can prevent this behavior with -c option like below. If file exist it will not created by touch .

Set Access Time of File

In previous examples we have updated last access time of the file to the current time. We also have the ability to set different times for the last acess time. We will use -a option and provide the date and time information. In this example we will set the last access time of file1 to January 02 15:45 of current year. It’s format is MMDDHHMM.

Set Modification Time of File

Like previous example we can set last modification date of a file with -m option.

Use Other File Timestamp

We can use other files date , time and timestamp information while setting newly created file. We will -r option and the file we want to inherit its access and modification timestamp. In this example we will use file2 last access and modification timestamp for newly created file1 .

LEARN MORE  locate Command Tutorial With Examples For Linux To Find Files

 

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-touch-command-tutorial/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)