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
Share:
28,120

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    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