2

I have an alias named homework that cd's me into a directory that I wanna do homework in. I have my homework directory persist across sessions by writing it to a file: ~/.homework as I've seen other applications do similar (but not identical!) things: (~/.bashrc, ~/.ssh, ~/.vim, ~/.gitconfig, and ~/.npm, to name a few).

However, some of these files are scripts to run on startup, some are config files, and others are directories containing all sorts of stuff.

I've also read that you should be using /etc/ for this type of stuff (/etc/sudoers, /etc/manpath, /etc/hosts).

My question is: is there an accepted best practice for a certain location on my computer to store persistent data for shell scripts or tiny little aliases like the one I have? It feels wrong to throw everything in my home directory, but it also feels wrong to put something this trivial in my /etc folder.

Binaries go in */bin, special files that correspond to devices go in /dev, config stuff goes in /etc, temporary files go in /tmp. I know I can get away with moving my ~/.homework file anywhere, but I don't like practicing bad practices out of ignorance!

For reference, here's how my alias works:

$cat ~/.homework
/long/path/name/foo/bar/project-4

$ alias homework
alias homework='cd $(cat ~/.homework)'

edit: Since this question was put on hold as opinion-based, I'm assuming that there's no clear best-practice on where to store stuff like this. I suppose that "The nice thing about standards is that you have so many to choose from".

From now on, I'm going to put all my tiny config files in a ~/.config folder.

9
  • your ~/.homework file just contains a single line with a directory path in it?
    – jesse_b
    Commented Feb 27, 2018 at 23:49
  • Additionally this question is exceedingly more verbose than it needs to be.
    – jesse_b
    Commented Feb 27, 2018 at 23:55
  • @dsstorefile: There is absolutely no reason for him to explain to us how ~/.bashrc and various other config files are stored (he actually mistakes a bunch of directories for files anyway). There is no reason to explain (incorrectly) where binaries go, etc. Disagree all you want but this question could definitely be thoroughly asked in one paragraph max.
    – jesse_b
    Commented Feb 28, 2018 at 0:52
  • 1
    I coulda asked more concisely: "Where should I store persistent data from a command line utility". But then people might interpret it as "where can I store...", the answer of which would be anywhere. I don't just want an answer to "where should I store...", but I also wanna know why, the historical or standard reasons for placing data there. Commented Feb 28, 2018 at 20:47
  • 1
    I do not see why this question should be closed. It is certainly not a question with mainly opinion based answers (the right answer is "Do what you like in your home directory; XDG has some suggestions. Other than that there is the Linux FHS.") Commented Jun 8, 2020 at 10:01

1 Answer 1

4

Since you're only storing a single file for a personal alias, putting it in ~ is totally fine. There's an XDG Base Directory Specification that says configuration files should go in ~/.config, but that's up to you. After all, it's your home folder! If the path doesn't change often, consider hardcoding it into the alias instead of keeping it in a separate file.

/etc is for system-wide configuration files, while ~/.config is for the user. You're close about where system binaries can go (/bin), but also note that user binaries can go in ~/bin.

1
  • 3
    Thanks for the great answer! I'm going to make myself a ~/.config folder for all the small tinkerings like this that I'm messing with. I love having a ~/bin, because after putting it in my PATH it lets me tab-complete all my scripts! Commented Feb 28, 2018 at 20:49

Not the answer you're looking for? Browse other questions tagged .