Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create file at specified directory with touch command

Tags:

linux

touch

In Linux the touch-command creates files. But it always creates it in the current directory. How can I create files in a specified directory?

For example

touch file ../my_directory
like image 488
deniz Avatar asked Feb 22 '13 21:02

deniz


People also ask

How do you create a file using touch command?

To create an empty file using touch, type touch followed by the filename. The aforementioned command will create a new file named newemptyfile in the current working directory. You can verify that the file has been created using the ls command.

Can we create directory using touch command?

How to Create Files and Directories in Linux using "touch" and "mkdir" Commands. You can create new files and directories within the directory hierarchy using the touch and mkdir commands. The touch command creates a new, empty file, and the mkdir command creates a new directory.

How do I create a file in a specific directory?

To create a file inside a specific directory, we need to open a file using the absolute path. An absolute path contains the entire path to the file or directory that we need to use. It includes the complete directory list required to locate the file. For example, /user/Pynative/data/sales.

Can you touch a directory in Linux?

yes, the definition of "FILE" in the documentation does include directories, so you can use touch to change their timestamps, BUT... touch is a standard Unix program used to change a file's access and modification timestamps. It is also used to create a new empty file.

How do I create a file using touch in Linux?

The simplest way to use the touch command is without any options: If a file does not exist, touch creates the file. For example, to create a file called test, run: List directory contents to see the file using the ls command. If the file already exists, touch changes the timestamp to the current time.

How do I create a new directory using the touch command?

The touch command creates a new, empty file, and the mkdir command creates a new directory. You can use the touch command to create an empty file. You can create multiple files on the same command line. If the file name or directory name already exists, the touch command updates the modification time and access time to the current date and time.

What is the use of touch command in Linux?

The most basic use of the touch command is to create new empty files. Unlike the cat command, which prompts you to add content to your file at the time of creation, the touch command creates an empty file without such prompts.

How do I create a new directory in Linux terminal?

You can create new files and directories within the directory hierarchy using the touch and mkdir commands. The touch command creates a new, empty file, and the mkdir command creates a new directory. You can use the touch command to create an empty file.


1 Answers

Try

touch ../my_directory/file

it won't create ../my_directory though, but I think this is not what you asked for.

like image 177
Patrick B. Avatar answered Sep 28 '22 05:09

Patrick B.