4 minute read

If you manage a Linux system with multiple users, you may want to encourage users to store their data in a shared location to avoid cluttering the root directory. You can create a data folder for each user on a shared storage drive and configure their home directories to include symbolic links to their corresponding data directories.

Additionally, if you use Conda to manage packages, you can move the Conda package cache to the shared storage drive to conserve space on the root directory.

Creating Data Folders

To create a data folder for each user on a shared storage drive:

  1. Log in to the Linux system with an account that has administrative privileges.
  2. Create a subdirectory in the shared storage drive (e.g. /mnt/data) for each user by running the following command for each user:
sudo mkdir /mnt/data/<username>

Replace <username> with the username of the user you’re creating the directory for.

  1. Set the ownership and permissions of the user’s data directory to the corresponding user by running the following command for each user:
sudo chown <username>:<username> /mnt/data/<username>
sudo chmod 700 /mnt/data/<username>

Replace <username> with the username of the user you’re setting the ownership and permissions for.

  1. Create a symbolic link from the user’s home directory to their corresponding data directory by running the following command for each user:
ln -s /mnt/data/<username> ~/data

Replace <username> with the username of the user you’re creating the symbolic link for.

This will create a symbolic link named data in the user’s home directory that points to their corresponding data directory in the shared storage drive.

Moving Conda Packages

To move the Conda package cache to the shared storage drive:

  1. Open a terminal window.
  2. Navigate to the default Conda package cache directory by running the following command:
cd ~/.conda/pkgs/

This directory contains all of the Conda packages that have been downloaded or installed on the system.

  1. Copy the contents of the package cache directory to the shared storage drive by running the following command:
sudo cp -r * /mnt/data/

This will recursively copy all of the contents of the package cache directory (*) to the shared storage drive.

  1. Modify the CONDA_PKGS_DIRS environment variable to include the shared storage drive. Add the following line to your .bashrc or .bash_profile file:
export CONDA_PKGS_DIRS=/mnt/data,/home/yourusername/.conda/pkgs

Replace yourusername with your own username.

This will set the CONDA_PKGS_DIRS environment variable to include both the shared storage drive and the default package cache directory.

With these steps, each user will have their own data directory on the shared storage drive that they can use to store their files, and a symbolic link in their home directory that points to that directory. Additionally, Conda packages will be stored on the shared storage drive rather than the root directory, which can help conserve space.

Note: It’s important to be careful when using sudo, since it grants you full privileges on the system and can potentially cause damage if used improperly. Always double-check the commands before running them, and make sure you understand their consequences