Skip to main content
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/...
Jonathan Komar's user avatar
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 ...
bashBedlam's user avatar
  • 1,059
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-...
StefanQ's user avatar
  • 781
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&...
rindeal's user avatar
  • 792
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 ...
Kusalananda's user avatar
  • 341k
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, ...
heemayl's user avatar
  • 56.9k
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 ...
jesse_b's user avatar
  • 38.1k
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 ...
Miati's user avatar
  • 3,150
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 ...
terdon's user avatar
  • 245k
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 -...
Tigger's user avatar
  • 3,697
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 ...
Thomas Dickey's user avatar
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 ....
Stephen Kitt's user avatar
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 ...
Faheem Mitha's user avatar
  • 35.5k
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, ...
Vlastimil Burián's user avatar
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 ...
xeruf's user avatar
  • 581
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.
Satō Katsura's user avatar
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://...
Bodo's user avatar
  • 6,138
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 ...
user's user avatar
  • 29.4k
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 ...
Kusalananda's user avatar
  • 341k
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 ...
Stephen Kitt's user avatar
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 ...
user10489's user avatar
  • 7,737
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 ...
smac89's user avatar
  • 1,493
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 ...
Julie Pelletier's user avatar
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. (...
Archemar's user avatar
  • 31.8k
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 ...
Gilles 'SO- stop being evil''s user avatar
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 ...
JdeBP's user avatar
  • 69.9k
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 ...
DopeGhoti's user avatar
  • 77.4k
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 ...
Gilles 'SO- stop being evil''s user avatar
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 ...
clk's user avatar
  • 2,156
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 ...
αғsнιη's user avatar
  • 41.6k

Only top scored, non community-wiki answers of a minimum length are eligible