Creating a symlink gives cannot overwrite directory error

Hassan Baig

I have a Django app with a postgresql backend. Postgresql creates temporary files every now and then - this can be a killer if disk space is critical (as is my case).

One way to alleviate the problem is to create a symlink to some other storage location where disk space isn't a bottleneck. In my case, postgresql stores temporary files at /$PGDATA/base/pgsql_tmp. I have a big SSD mounted at /mnt, so I want the temp files to reside there instead. The following ought to take care of this:

ln -sTf /mnt/pgsql_tmp $PGDATA/base/pgsql_tmp
chown -R postgres /mnt/pgsql_tmp #ensuring user 'postgres' has the right perms
chmod o+x /mnt

Before I do this in production, I decided to test this out locally. I created /mnt and /pgsql_tmp on my desktop, and then tried ln -sTf /home/hassan/Desktop/mnt/pgsql_tmp /home/hassan/Desktop/pgsql_tmp.

But this ends up giving me ln: ‘/home/hassan/Desktop/pgsql_tmp’: cannot overwrite directory. Can anyone point out what I'm doing wrong? Being a neophyte, I'm really trying to wrap my head around how this works.

Frank Thomas

Your best bet is to delete ~/pgsql_tmp, and let the ln command create it.

First note that LN doesn't link two objects; it creates a link to a target with a specific name from a place.

ln [OPTION]... [-T] TARGET LINK_NAME

When you create a link with ln, the NAME argument should indicate an object that does not yet exist, and it will be created as the result of the command. In your case you already created it (~/pgsql_tmp) as a directory.

Usually, You can use the -f switch to force deletion of anything already overlaping the NAME's path, but in your case you specified -T which means that you want to create the link as a File, not as a Directory. So when -f goes to overwrite the object at NAME, its trying to overwrite a directory with a file.

So, you can either create the link as a directory and use -f, or you can delete the object that overlaps NAME, and then create your link. The later is the best option.

#create a test target with a file, but without an object at lnname
~/tmp$ mkdir lntarget
~/tmp$ touch lntarget/contentfile1
~/tmp$ ln -sTf lntarget lnname
~/tmp$ ls ./lnname
contentfile1

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Creating symlink gives 500 Internal Server Error

From Dev

Creating symlink gives 500 Internal Server Error

From Dev

Creating symlink for a file on Windows 7 gives error

From Dev

"ln -sf" does not overwrite a symlink to a directory

From Dev

Creating a symlink of directory inside home

From Dev

Overwrite directory with shutil.rmtree and os.mkdir sometimes gives 'Access is denied' error

From Dev

mv: cannot overwrite directory with non-directory

From Dev

Why change the current directory to the parent directory of a relative symlink before creating it

From Dev

How to overwrite a symlink in Go?

From Dev

Overwrite symlink with original file

From Dev

sourceing a setup.sh gives bash error /tmp/setup.sh.DPE4BtgiZY: cannot overwrite existing file

From Dev

QSerialPort gives error "no such file or directory"

From Dev

rmdir dir gives error 'Not a directory'

From Dev

unzip: gives: checkdir error: .../directory exists but is not a directory

From Dev

unzip: gives: checkdir error: .../directory exists but is not a directory

From Dev

XCode error: cannot overwrite dSYM file

From Dev

Is a symlink to a directory a file or a directory?

From Dev

Create symlink - overwrite if one exists

From Dev

Creating a directory in Ruby ENOENT Error

From Dev

"No such file or directory" Error when creating directory

From Dev

creating simple thread in swift gives error

From Dev

Creating a simple Iteratee gives type error ?

From Dev

creating simple thread in swift gives error

From Dev

Creating a linux symlink on Windows?

From Dev

Creating a Symlink in an NTFS share

From Dev

Creating Broken Symlink

From Dev

Creating symlink for Postgres

From Dev

Resolvconf -u gives the error "resolvconf: Error: /etc/resolv.conf must be a symlink"

From Dev

Resolvconf -u gives the error "resolvconf: Error: /etc/resolv.conf must be a symlink"

Related Related

  1. 1

    Creating symlink gives 500 Internal Server Error

  2. 2

    Creating symlink gives 500 Internal Server Error

  3. 3

    Creating symlink for a file on Windows 7 gives error

  4. 4

    "ln -sf" does not overwrite a symlink to a directory

  5. 5

    Creating a symlink of directory inside home

  6. 6

    Overwrite directory with shutil.rmtree and os.mkdir sometimes gives 'Access is denied' error

  7. 7

    mv: cannot overwrite directory with non-directory

  8. 8

    Why change the current directory to the parent directory of a relative symlink before creating it

  9. 9

    How to overwrite a symlink in Go?

  10. 10

    Overwrite symlink with original file

  11. 11

    sourceing a setup.sh gives bash error /tmp/setup.sh.DPE4BtgiZY: cannot overwrite existing file

  12. 12

    QSerialPort gives error "no such file or directory"

  13. 13

    rmdir dir gives error 'Not a directory'

  14. 14

    unzip: gives: checkdir error: .../directory exists but is not a directory

  15. 15

    unzip: gives: checkdir error: .../directory exists but is not a directory

  16. 16

    XCode error: cannot overwrite dSYM file

  17. 17

    Is a symlink to a directory a file or a directory?

  18. 18

    Create symlink - overwrite if one exists

  19. 19

    Creating a directory in Ruby ENOENT Error

  20. 20

    "No such file or directory" Error when creating directory

  21. 21

    creating simple thread in swift gives error

  22. 22

    Creating a simple Iteratee gives type error ?

  23. 23

    creating simple thread in swift gives error

  24. 24

    Creating a linux symlink on Windows?

  25. 25

    Creating a Symlink in an NTFS share

  26. 26

    Creating Broken Symlink

  27. 27

    Creating symlink for Postgres

  28. 28

    Resolvconf -u gives the error "resolvconf: Error: /etc/resolv.conf must be a symlink"

  29. 29

    Resolvconf -u gives the error "resolvconf: Error: /etc/resolv.conf must be a symlink"

HotTag

Archive