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'.

ekv_56
  • 57
  • 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. – ctrl-alt-delor May 30 '20 at 10:42
  • @ctrl-alt-delor Thanks for your help – ekv_56 May 30 '20 at 11:16

2 Answers2

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.

xenoid
  • 8,888
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/
Fox
  • 8,193
  • 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 03: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 08: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 09:27
  • Do you know anything about fstab? - LINK – ekv_56 Jun 08 '20 at 07:50
  • +Fox Do you know anything about this? - INTERNAL LINK: unix.stackexchange.com – ekv_56 Jun 13 '20 at 14:21
  • Sorry, it's been a while since i've done anything with SMB, so i'm afraid i won't be of much help there – Fox Jun 13 '20 at 15:33