Skip to main content
239 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
60 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,049
56 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
  • 771
51 votes

Where should a local user executable be placed (under $HOME)?

As uther mentioned, /usr/local is intended as a prefix for, essentially, software installed by the system administrator, while /usr should be used for software installed from the distribution's ...
MattSturgeon's user avatar
45 votes

Find the total size of certain files within a directory branch

The ultimate answer is: { find <DIR> -type f -name "*.<EXT>" -printf "%s+"; echo 0; } | bc and even faster version, not limited by RAM, but that requires GNU AWK with bignum support: ...
rindeal's user avatar
  • 777
38 votes

Download files and create same file structure as the source

To get the structure you are asking for, I would suggest using -nH as well as -x. This will remove the hostname as well as create the expected directory structure. e.g. wget -x -nH http://xyz.abc....
Joe's user avatar
  • 481
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
  • 335k
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.4k
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
30 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
  • 37.2k
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

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
  • 242k
22 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,647
21 votes
Accepted

Why is /bin a symbolic link to /usr/bin?

Short summary of the page suggested by don_crissti: Scattering utilities over different directories is no longer necessary and storing them all in /usr/bin simplifies the file system hierarchy. Also, ...
rkhff's user avatar
  • 805
21 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.2k
18 votes
Accepted

Compact bash prompt when using a directory tree / filename

First of all, you might simply want to change the \w with \W. That way, only the name of the current directory is printed and not its entire path: terdon@oregano:/home/mydirectory1/...
terdon's user avatar
  • 242k
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
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

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
  • 551
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,068
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
  • 29k
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
  • 335k
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
  • 6,805
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.6k
13 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,443
13 votes
Accepted

Linux file hierarchy - what's the best location to store lockfiles?

/dev/shm : It is nothing but implementation of traditional shared memory concept. It is an efficient means of passing data between programs. One program will create a memory portion, which other ...
Rahul's user avatar
  • 13.6k
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
13 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

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