-1

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?

bijoy26
  • 133
  • 9
Franky11
  • 41
  • 5

1 Answers1

0

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/
    
bijoy26
  • 133
  • 9