0

My CentOS 7 filesIs it possible using CentOS to change the path or location of the user's files (e.g. desktop, documents, downloads etc.) to another folder or even a network/shared drive or other mounted drive. On my Windows10 PC, I have my desktop location set to a network drive folder which I can access from my CentOS computer, it would also be great if I could set the location of the folders on my CentOS pc so I always have an updated destkop etc. stored on my network drive..... this would work for any other local folder to change it too as well, the question isn't specific to network drives.

Any ideas?

The image below shows my directories locally /home/username but I want to change them to a location that you can see under network in the bottom left 'shared'.

2
  • Note /home/username is not the location of your user files. Well not in the way that you probably mean when you say location. It is not the physical location, it is the directory name. However these need not be related. E.g. everything under /home is often a different partition. You may mount a network file-system or encrypted file-system on /home/username. May 30 '20 at 10:42
  • @ctrl-alt-delor Thanks for your help
    – ekv_56
    May 30 '20 at 11:16
2

If you want to change these subdirectories individually, the right place is ~/.config/user-dirs.dirs. This is explained here.

The file looks like this:

# This file is written by xdg-user-dirs-update
# If you want to change or add directories, just edit the line you're
# interested in. All local changes will be retained on the next run.
# Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped
# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an
# absolute path. No other format is supported.
# 
XDG_DESKTOP_DIR="$HOME/Desktop"
XDG_DOWNLOAD_DIR="$HOME/Downloads"
XDG_TEMPLATES_DIR="$HOME/Templates"
XDG_PUBLICSHARE_DIR="$HOME/Public"
XDG_DOCUMENTS_DIR="$HOME/Documents"
XDG_MUSIC_DIR="$HOME/Music"
XDG_PICTURES_DIR="$HOME/Pictures"
XDG_VIDEOS_DIR="$HOME/Videos"

So you just edit it with your text editor, for instance, if you want to change your videos to an absolute location your replace the XDG_VIDEOS_DIR line with:

XDG_VIDEOS_DIR="/mnt/hdd2/Videos"

Or you want some directory elsewhere or under another name in your home tree:

XDG_DOWNLOAD_DIR="$HOME/Téléchargements"

Then make sure these directories exist and are readable/writable by your id, logoff/logon and you should be set.

9
  • See updated answer
    – xenoid
    May 27 '20 at 8:30
  • It's not working for me, I can access and change and save the file, but when I logout and log back in, the file is back to how it was before...... I am trying to connect to: smb://computername/sharedfoldername - this is accessable without credentials....
    – ekv_56
    May 27 '20 at 9:58
  • I can read and write in the folders @xenoid - it's just not working when I edit the file.....? Any ideas?
    – ekv_56
    May 27 '20 at 12:09
  • If it is accessible without credentials, you'd be better off setting it up as a mountpoint when you start the computer, so it'll be available when you log in, instead of needing to be mounted after you've logged in.
    – jsbillings
    May 27 '20 at 12:37
  • Will this automatically work on startup as well @xenoid? Thanks
    – ekv_56
    May 30 '20 at 9:27
1

Of course you can! If you want to change your home directory entirely, that's a field in the password database. If you just want to point individual folders elsewhere, you can use symlinks

If you want to change the home directory entirely, ensure that the intended location will be available upon boot and call (as root)

# usermod -md "path" user

where path is the location of the intended home directory and user is the login name of the user.

If you just want to change individual subdirectories, say you want Desktop to point to /mnt/Desktop, you might do:

$ mv ~/Desktop ~/Desktop.bak
$ ln -s /mnt/Desktop ~/Desktop
$ mv ~/Desktop.bak/* ~/Desktop/
8
  • Thanks for the update, you mention that it must be available on startup, what would happen if it wasn't - could I refresh or sign out and sign back in once it's back online..? And if I do the command you have put beginning 'usermod...', would I have to have folders named 'desktop', 'documents', 'downloads' immidiatly in that folder or do I set them manually for each one...? Thanks
    – ekv_56
    May 26 '20 at 18:08
  • The usermod command as shown moves (-m) the home directory to the new place, so everything will transfer. Not really sure what happens if a user's home directory is inaccessible though. In any case, @xenoid has a better answer for well-behaved programs
    – Fox
    May 27 '20 at 3:43
  • Thanks for all your help with this question, @xenoid has updated their post to make it more clear so I'm having a go at that now. Thanks
    – ekv_56
    May 27 '20 at 8:36
  • If you look at @xenoid 's answer, can you see any problems with being able to edit the file.... it won't let me, any ideas why?
    – ekv_56
    May 27 '20 at 12:17
  • Thanks for your help @Fox
    – ekv_56
    May 30 '20 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.