Without changing your current directory, create an empty file in another directory in Linux?
28,120
Simply like that :
$ touch ../lastname/test2.txt
Note that instead of touch, you can use >
$ > ../lastname/test2.txt
You can also use an absolute path
$ > /Users/Directories/lastname/test2.txt
Related videos on Youtube
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on September 18, 2022Comments
-
Admin almost 2 years
Suppose my current working directory is:
/Users/Directories
Under Directories, there are two separate directories called: firstname & last name. I move into the first name directory:
$ cd firstname
and inside firstname, I want to create an empty file called test1.txt, so I type:
$ touch test1.txt
This is where I am stuck: without leaving firstname, I want to create a file called test2.txt in the directory lastname. I've tried this, but it doesn't seem to work. Thanks in advance.
$ touch test2.txt../lastname