0

I have created two directories in desktop: solid/ and liquid/. Initially liquid/ is empty. Directory structure:

├── liquid
├── solid
│   ├── rock.txt
│   └── water.txt

I tried to move water.txt to liquid/ but it throws and error.

$ mv water.txt /liquid

mv: cannot move 'water.txt' to '/liquid': Permission denied

How can i fix this?

1
  • Not sure why this got down voted. I found it very useful. +1. Commented Feb 5 at 16:10

1 Answer 1

1

Following your steps, your Desktop/ folder should look like this:

├── liquid
├── solid
│   ├── rock.txt
│   └── water.txt

There are two major issues causing this behaviour.

  1. Assuming you are currently in solid/ directory, you need to reference the relative path of the liquid/ directory. Since it resides in the same level as the parent directory of water.txt file, you need to use .. (double dots) according to the unix convention. ( for more context read dot definition)

    # currently in solid directory
    $ pwd    
    /c/Users/USER/Desktop/solid
    
    # move file to liquid directory ✔
    $ mv water.txt ../liquid/
    
  2. In Unix based systems, directories are typically represented by it's name followed by a front slash /, not the other way around. Ex: music/. In fact, putting / in front of a directory name is prohibited in both Windows and Linux. Moreover, when the two arguments are in the same directory, mv command interprets it as a rename operation on the first argument.

    # git bash thinks /liquid is a file in current directory; rename operation fails ❌
    $ mv water.txt /liquid
    
    # git bash thinks liquid to be in upper level; no renaming; move succeeds ✔
    $ mv water.txt ../liquid/
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.