Linux where to store files

Where should I store my application files (data, cache, logs, crashes, etc.) [closed]

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

  • Temp files: /var/temp/app_name/* or /temp/app_name/*
  • Cache files: /var/cache/app_name/*
  • Config files: ~/.config/app_name/*
  • Log files: /var/log/app_name/*
  • Data files (database, etc.): .

Q1: Is that the right approach for the recent systems?

For the XDG standart that explained here:

  • Temp files: . or /temp/app_name/*
  • Cache files: ~/.cache/app_name/*
  • Config files: ~/.config/app_name/*
  • Log files: .
  • Data files (database, etc.): .

I cant understand why we store a cache file in the ~/.cache . It doesn’t make any sense to me because there was a built-in cache folder called /var/cache

In that case, I’m confused. Everywhere I investigate, there have been different approaches.

Q2: Where should we put the files (datas, logs, temps, configs, etc.) for a pure Linux distribution (which does not use $XDG) to create applications?

Q3: Some applications use the Linux structure, but some of use the XDG structure. How do they choose this? According to what situation? Do they use $XDG environment variables if we’re using them?

According to the above situation, my env | grep -i «XDG» output:

XDG_VTNR=1 XDG_SESSION_ID=1 XDG_DATA_DIRS=/home/furkan/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share XDG_RUNTIME_DIR=/run/user/1000 XDG_SEAT=seat0 

P.S: I don’t know the parts I’m showing with .

1 Answer 1

Part of your confusion may be the distinction between user applications and system applications.

So, for example, apache isn’t run as an end user («Harry» normally doesn’t run Apache; it’s run from a system startup script — systemd or init or however). These sort of applications typically will follow the file system standard and store log files in /var/log , configuration files in /etc and so on.

Similarly, commands executed by the systems administrator as root designed to impact the whole machine (e.g. apt or yum ) also follow the file system standard.

However, applications designed to be executed by the end user (e.g. a web browser and other desktop applications) follow the XDG standard. Here «Harry» has his own personal cache, which is different to «Julie»; they visit different web sites, so have cached different pages. Similarly, Harry may configure his desktop different to Julie, and so the configuration will be in the ~/.config area.

Some locations (eg /tmp ) are designed to be shared by all users, so even desktop apps can use them. but even here a more modern /run/user/ structure is sometimes used.

Источник

Linux and its way of storing files.

lfs.jpg

The file system is generally a built-in layer of a Linux operating system used to handle the data management of the storage. It helps to arrange the file on disk storage and manages the file name, file size, creation date, and much more information about a file. The Linux file system is a structured collection of files on a disk drive or a partition. A partition is a segment of memory that contains some specific data. In our machine, there can be various partitions of memory. Generally, every partition contains a file system. The files are stored in the hierarchical tree structure. Root folder comes first and then files are under root respectively. Whereas in windows, files are stored in folders on different data drives like C: D: E:

Читайте также:  Настроить ssh astra linux

Linux File System Overview

Filesystem Hierarchy Structure (FHS) in Linux – TecAdmin

/ or /root => root user’s home directory which is separate from other users /home => contains the home directories of all non-root users. /bin (stands for binaries) => executables for most essential user commands(all files are system-wide usable) What is binary?A binary is just a computer-readable format (a bunch of 0’s & 1’s) /sbin (system binaries) => essential system binaries, programs that admin would use(need superuser privileges) /lib, /lib32, /lib64, /libx32 => essential shared libraries that executables from /bin or /sbin use. /usr (user) => this was used for user home or directories*(contains the same* /bin , /sbin , /lib folders). Why do /usr contain these folders?

  • historic reasons(as UNIX also had those splits)
  • Because of storage limitations, it was split to root binary folders ad user binary folders.

NOTE: When we execute basic Linux commands they are executed from /usr/bin folder. In other distros, /bin or /sbin contains fewer commands and /usr/bin or /sbin contains all other commands.

Inside /usr , there is a folder /local that also contains the same files as /usr ( /bin or /sbin or /lib ).

/usr/local => programs that you install on the computer. Third-party applications like docker, minikube, etc go here. Programs installed here will be available for all users on the computer.

NOTE: If you want to install third-party applications and don’t want to be accessed by all the other users then you install them on your own /home directory.

/boot (booting) => contains files required for booting.

/opt (optional) => third-party programs you install(all programs will be available system-wide).

Difference between /usr/local & /opt:-

  • /usr/local : programs that split into their components.
  • /opt : programs which not split into their components.

NOTE: Till now all folders are read-only folders.

/etc (et cetera) => a place where the configuration for system-wide applications is stored. Originally for etc*(means everything else goes there)*. It emerged into the main configuration location.

/dev (devices) => location of device files like webcam, keyboard, hard drives, etc. Apps and Drivers will access this, NOT the user.

/var (variable) => contains files to which the system writes data during the course of its operation.

/var/log => contains log files.

/var/cache => contains cached data from application programs.

/tmp (temporary) => temporary resources required for some processes kept here temporarily.

/media (removable media) => contains subdirectories where removable media devices inserted into the computer are mounted. For example, when you insert a CD, a directory will automatically be created and you can access the contents of the CD inside the directory.

Читайте также:  Linux mint темы окон

/mnt (temporary mount points) => historically, sysadmins mounted temporary file systems there(or manually mounting folders).

Interacting with these folders

Usually, you are not interacting with these folders. Installing apps with a package manager is responsible to store the required files in the right corresponding folders.

Hidden Files

These are primarily used to help prevent important data from being accidentally deleted and are automatically generated by programs or operating system. The file name starts with . (dot). These are also called ‘dotfiles’.

Источник

The place to store user data in Linux

You’ve read one question discussing a multi-user operating system being used by a single user. You should instead read superuser.com/questions/181652, superuser.com/questions/694069, superuser.com/questions/870356, and superuser.com/questions/285095, just for starters.

3 Answers 3

enter image description here

Data should be stored in a different partition of the file system of your OS. In Linux, personal data is stored in /home/username folder. When you run the installer and it ask you for partition your hard disk, I suggest you to create an extended partition for the home folder.
If you need to format your computer, you only have to do it with the primary partition.
I attach you a screenshot of the Gparted utility; it shows my disk. When you reinstall an OS and you already got a home folder, you will necessary need to create a new home for the new user and link or move (carefully) all the files of the old folder to the new folder.

UPDATE
From my experience, having an exclusive partition for your /home (Linux) or D:\ (Windows) is better. Both in Windows and Linux, in your data folder, will create some files (mostly hidden files) that could give you some problems if you don’t be careful while you move the old files to the new folder (if you reinstall the OS).
I have reinstalled five times my Linux keeping my personal data untouched and I share it with my Win7 with no problems 🙂

Store the user data on a separate partition from the operating system. If you are careful not to overwrite this partition when reinstalling the operating system, this data will be safe. For example, if your computer has two hard drives, an SSD and an HDD, put the operating system on the SSD and the user data on the HDD.

My opinion is that it is better not to have a separate /home partition for two reasons:

  1. When reinstalling the operating system, some files in the /home directory are overwritten, but your user data will not be affected if it is in a separate partition.
  2. Frequently used files such as configuration settings and virtual machine images can be stored in the /home directory where they can be accessed more quickly if the /home directory is located on an SSD.

The data partition can be made accessible by automatically mounting it when the operating system starts up. This is done in Linux by editing the /etc/fstab file and adding a new line to it containing information about how the partition that you want to be automatically mounted at startup should be mounted into the filesystem.

You can use custom folders for folders in /home/ . Example:

 xdg-user-dirs-update --set DOWNLOAD /media/user/Downloads/ 

would switch from /home/$USER/Downloads/ to /media/user/Downloads/ and documents downloaded would then download to the HDD and not the SSD. The same applies for all the other directories. See ~./config/user-dirs.dirs on manually editing these settings. source

Читайте также:  Российский антивирус для linux

Источник

Where in the filesystem should I store shared data?

Where in the unix filesystem is the conventional location to save non-user specific data, for example data shared via nfs or ftp, or backups? I could obviously create and use any arbitrary folder (such as /home/shared, /data or /var/data), but I’m really wondering if there are any «best» or «common» practice guidelines. The Filesystem Hierarchy Standard doesn’t specify a location for shared data. For backups, I tend to use /var/backups, but as several cronjobs write to it should it really be left for their use?

4 Answers 4

This question does seem to have a clear answer in the Filesystem Hierarchy Standard, which specifies /srv as «contain[ing] site-specific data which is served by this system «. (3.16.1)

This main purpose of specifying this is so that users may find the location of the data files for particular service, and so that services which require a single tree for readonly data, writable data and scripts

Note: ‘Served by the system’ doesn’t necessarily refer to the Internet. It needn’t even mean a network. It’s applicable to even a shared system. Further, the words site and service should be understood in their pre-internet meanings. Your site can be «the physics department» or «the finances office».

On large systems it can be useful to structure /srv by administrative context, such as /srv/physics/www, /srv/compsci/cvs, etc. This setup will differ from host to host. Therefore, no program should rely on a specific subdirectory structure of /srv existing or data necessarily being stored in /srv. However /srv should always exist on FHS compliant systems and should be used as the default location for such data.

You should therefore further structure your data in directories such as /srv/nfs , /srv/backup and so on.

I should also mention that few people do this anymore. But there is no good reason why they don’t. The standard is by no means out of date.

/var is traditionally used for things like print-spools and log-files, but it’s also used by the Apache web server (on Debian systems anyway — SUSE use /srv); There doesn’t seem to be consensus on whether /var is a proper directory for shared data. But if you decide to use it instead, you will have no regrets I’m sure.

Note also: Karthick’s answer is by no means wrong. The FHS says /srv » should be used as the default location for such data», but the standard leaves some room for your own preference, depending on how you interpret the terms.

Источник

Оцените статью
Adblock
detector