244
votes
Accepted
Where do I put my systemd unit file?
The best place to put system unit files: /etc/systemd/system
Just be sure to add a target under the [Install] section, read "How does it know?" for details. UPDATE: /usr/local/lib/systemd/...
59
votes
How to create a file and parent directories in one command?
You can combine the two commands on a single line. If you use a variable you can do this:
file="./nested/folder/deep/more.txt"
And then this:
mkdir -p "${file%/*}" && touch "$file"
Or all ...
57
votes
Where to search for the core file generated by the crash of a linux application?
Systems using systemd are usually configured to dump cores to
/var/lib/systemd/coredump/
You may use the coredumpctl command to list core dumps.
See also no-more-coredumps-after-migrating-to-...
47
votes
Find the total size of certain files within a directory branch
The Ultimate Solution for Summing File Sizes
If you're looking for an efficient way to sum the sizes of files in a directory, here's the ultimate answer:
find <DIR> -type f -name "*.<EXT&...
34
votes
Accepted
Why does '/' contain '..'?
The .. entry in the root directory is a special case.
From the POSIX standard (4.13 Pathname Resolution, where the . and .. entries are referred to as "dot" and "dot-dot" repsectively):
The ...
31
votes
Accepted
Can I prevent a folder of a certain name being created?
You can't, given the user creating the directory has sufficient permission to write on the parent directory.
You can instead leverage the inotify family of system calls provided by the Linux kernel, ...
31
votes
Accepted
What is the difference between /lib and /usr/lib and /var/lib?
Someone else can probably explain this with much more detail and historical reference but the short answer:
/lib
is a place for the essential standard libraries. Think of libraries required for your ...
30
votes
Can I prevent a folder of a certain name being created?
To answer literally based on the question of preventing a folder of a certain name to be created.
touch shop
You can't create a directory if a file with a identical name existing
mkdir: cannot ...
23
votes
Accepted
Standard location for holding software source files
Whenever you ask yourself something like this, check out the Filesystem Hierarchy Standard (FHS).There, you will find the following entry:
usr/src : Source code (optional)
Purpose
Source code may be ...
23
votes
Accepted
How to prepend a directory to files placed in a tar archive?
You can use the --transform option. For example:
touch foo bar
tar cf archive.tar foo bar --transform 's,^,bazdir/,'
tar tvf archive.tar
-rw-r--r-- tigger/tigger 0 2017-10-11 19:32 bazdir/foo
-...
22
votes
Accepted
Why are init.d scripts in etc?
Early on (both historically, and in the process of booting...), /etc is a part of / (the first mounted filesystem), while /usr was not (until disks got large). /var holds temporary data, while these ...
22
votes
Accepted
Is there a home directory location for overriding icons?
The historical equivalent is ~/.icons, the XDG equivalent is ~/.local/share/icons (strictly speaking, icons subdirectories of the paths in $XDG_DATA_DIRS). When you specify an icon by name only in a ....
19
votes
Standard location for holding software source files
/usr/local/src is a safe place to keep source code, and build it too. The FHS says: (last line on the table):
/usr/local : Local hierarchy
[...]
Requirements:
The following directories, or symbolic ...
18
votes
Accepted
Have group permission but unable to create file
/sys directory is special. You can't just poke around and create files
Wikipedia excerpt:
Modern Linux distributions include a /sys directory as a virtual filesystem (sysfs, comparable to /proc, ...
18
votes
What's the right way to add directories to XDG_DATA_DIRS?
The German ubuntuusers wiki has a nice list of files and directories that can be used for that purpose.
Setting it globally
From my research, appending to that environment variable globally is not ...
17
votes
How to find a depth of a directory
One way to do it, assuming GNU find:
find . -type d -printf '%d\n' | sort -rn | head -1
This is not particularly efficient, but it's certainly much better than trying different -maxdepths in turn.
17
votes
Accepted
How to find only directories without subdirectories?
To find only those leaf directories that contain non-directory files, you can combine an answer of the referenced question https://unix.stackexchange.com/a/203991/330217 or similar questions https://...
17
votes
Why does '/' contain '..'?
Kusalananda has already told you that this is the behavior specified by the POSIX standard. However, the history of UNIX began in earnest in the early 1970s. POSIX dates back only to the second half ...
15
votes
Accepted
Is the bin/ directory for storing binary files?
No, a bin directory is not for storing only binary files. It's for keeping executable files, primarily.
Historically, before scripts written in various scripting languages became more common, bin ...
15
votes
Accepted
Why is /var/lib used by application for storing data?
/var/lib is indeed the correct directory; as described in the filesystem hierarchy standard,
This hierarchy holds state information pertaining to an application or the system. State information is ...
15
votes
What is the difference between /lib and /usr/lib and /var/lib?
Files in /lib and /usr/lib are supposed to be mostly read only and identical between systems. (If it was a container image, they could be fully read only and shared between systems; on a stand alone ...
14
votes
Where do I put my systemd unit file?
If you want to know all the places where systemd will look for unit files, the following commands should be helpful.
Using systemd-analyze command:
All folders which can contain user services:
These ...
14
votes
Why are init.d scripts in etc?
Startup scripts are actually an important part of the system configuration.
Even though the boot-up process is much less customized than it was 15-30 years ago, and most of the startup configuration ...
14
votes
Accepted
How to extract a specifically named folder from a recursive directory, delete the others?
what about
find . -type d -name run -exec mv {} /path/to/X \;
where
/path/to/X is your destination directory
you start from this same place.
then use other answer to remove empty directories.
(...
13
votes
Is the bin/ directory for storing binary files?
“Binary files” is the etymology of the bin directory, but not its current meaning. Originally, it was for binary files, as in compiled programs — files containing machine code that could be loaded ...
12
votes
Role of the /usr/local directory in FreeBSD
Under Linux it was nice to have custom-built scripts or software in the /usr/local tree for them to be clearly separated from the distribution software
And that is exactly what you are getting on ...
12
votes
Accepted
Why would a directory have the sticky bit set without the executable bit?
From the manual page for sticky:
STICKY DIRECTORIES
A directory whose `sticky bit' is set becomes an append-only directory, or, more accurately, a directory in which the deletion of
files is ...
12
votes
The different uses of folders in the / (root) directory
The official reference for this on Linux is the Filesystem Hierarchy Standard. Distributions mostly follow the FHS (currently at version 3.0), but can occasionally deviate. Other Unix variants have ...
11
votes
Where is program installed after ./configure
To install to a custom directory, use this:
./configure --prefix=/desired/path
make
sudo make install
By default, programs installed without the added prefix will be located in /usr/local/bin. To ...
11
votes
Accepted
How to mirror directory structure and files with zero size?
GNU cp (from coreutils) can do this:
cp -r --attributes-only original_folder/* mirrored_folder/
From man cp:
--attributes-only
don't copy the file data, just the attributes
-R, -r, --recursive
copy ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
directory-structure × 473linux × 76
directory × 54
software-installation × 42
filesystems × 40
fhs × 32
files × 30
home × 24
bash × 21
shell-script × 20
permissions × 20
find × 18
mount × 16
shell × 14
debian × 13
ubuntu × 13
symlink × 13
filenames × 10
package-management × 9
compiling × 9
non-root-user × 9
freebsd × 8
configuration × 8
ls × 8
path × 8