32

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 special filename dot shall refer to the directory specified by its predecessor. The special filename dot-dot shall refer to the parent directory of its predecessor ...


17

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 of the 1980s, a full decade and a half later. In practice, POSIX merely specified what was already being done by implementations. Rather, UNIX did very early on ...


10

To find only those leaf directories that contain files, you can combine an answer of the referenced question https://unix.stackexchange.com/a/203991/330217 or similar questions https://stackoverflow.com/a/4269862/10622916 or https://serverfault.com/a/530328 with find's ! -empty find rootdir -type d -links 2 ! -empty Checking the hard links with -links 2 ...


8

If the directory names are one-per-line, then you could avoid issues with directories that have spaces or tabs or wildcard characters in their names by using readarray (bash v4+): readarray -t dirs < subdirs2search.txt find "${dirs[@]}" ... That would still not help if some directory names start with -, but with GNU find, there's no way around that.


6

You can create the directories while hiding any error related to the directory already existing: for custDir in /media/storage/sqlbackup/CUSTOMER* do mkdir -p "$custDir"/{daily,weekly,monthly} done You cannot use /media/storage/sqlbackup/CUSTOMER*/{daily,weekly,monthly} because the {...} sequence is expanded before the wildcard, and a wildcard pattern ...


5

I found that it didn't limit the search to only text files ack is often a handy tool for recursive-grep type stuff. It does by default limit searching to text files (determined using heuristics based on file name and content) and will by default skip directories like .git/.svn which if you're a developer is likely what you want. https://beyondgrep.com/. ...


5

Naturally, posting the question helped snap me out of my fixation on doing this strictly with find and made me think of expanding the file via Bash. I'm posting an answer hoping it will help someone else (and also to document this for my own future use). The incantation for having Bash expand the file contents is $(<subdirs2search.txt). So, if ...


5

The typical use of a .d directory is to hold multiple config files (typically sharing a common file extension, such as *.conf) which are then merged or composed to produce a single logical configuration. This mechanism is typically equivalent to one where the multiple config files were concatenated to form a single config file. Applications typically ...


4

There is a lot of discussion over this topic. Nothing really definitive is apparent. For "official" guidance on what is 'correct' I say the definitive source would be the Filesystem Hierarchy Standard at The Linux Foundation. Unfortunately I didn't find anything definitive with some basic searches. You may have luck with more diligent searching. Failing ...


4

With zsh: leafdirs=(**/*(ND/Fl2)) Sets the $leafdirs array with the list of matching leaf directories. You can print it one per line with: printf '%s\n' $leafdirs Or loop over them with: for dir ($leafdirs) something with $dir That's more or less a translation of @Bodo's GNU find answer, so like it works only on traditional Unix-like file systems like ...


4

If the */ filename globbing pattern expands to something that is not the name of a directory, then the current directory has no (non-hidden) subdirectories. With find: find root -type d -exec sh -c 'set -- "$1"/*/; [ ! -d "$1" ]' sh {} \; ! -empty -print Note that this would treat a symbolic link to a directory in a leaf directory as a directory since the ...


4

You could use nested find and count number of subdirectories: find . -type d \ \( -exec sh -c 'find "$1" -mindepth 1 -maxdepth 1 -type d -print0 | grep -cz "^" >/dev/null 2>&1' _ {} \; -o -print \)


3

/root is normally on the root partition. It's meant to be available even if something goes wrong and other partitions can't be mounted. Note that /root only contains what you put yourself. Sensitive data created by the system ends up under /etc or /var. These days, with most CPUs having accelerated AES instructions, disk encryption is very cheap. So if you'...


3

#!/usr/bin/perl -w use strict; use File::Find (); sub wanted; sub process_file ($@); my $dirfile = shift; # First argument is the filename containing the list # of directories. my $pattern = shift; # Second arg is a perl RE containing the pattern to search # for. Remember to single-quote it on the ...


3

Another tool similar to ack (Peter Cordes's answer) is ripgrep or rg. It supports the same usage: rg -- "desired text" $(<subdirs2search.txt) It also skips binary files by default.


2

${XDG_CONFIG_HOME:-~/.config} is exactly how xdg-user-dirs does it (it's a shell script). It hasn't changed since 2008, so you can consider this to be stable. Incidentally, you'd better not have whitespace or wildcard in the value of XDG_CONFIG_HOME. If XDG_CONFIG_HOME is unset, special characters in the home directory location are ok. Wildcards in the ...


2

libsystemd.so is a symbolic link provided by the libsystemd-dev package, which is only useful to build programs that use the library. Its target is libsystemd.so.0 which is provided by the libsystemd0 package, which provides what is needed to run programs that use the library. If you could find libsystemd.so on your PC but not on your Arm device, it's ...


2

There is a directory above /, / itself. The parent directory of the root directory is itself. cd .. or cd ../.. inside the root directory should leave you at the same place, not cause an error. Notice that neither . or .. may exist as actual directory entries in some filesystems, they may be simply emulated by the virtual file system layer of the OS. A ...


2

rsync -av --include='*/' --exclude='*' /opt/current/ /opt/New This would use rsync to exactly duplicate the directory structure of /opt/local in /opt/New while avoiding copying any files. The -a option (--archive) would make sure that all permissions etc. are preserved (this option also implies a recursive copy), and -v (--verbose) would be giving you an ...


1

A tree of files should be a directory structure. Then there is one detail: to use parens to not get lost. mkdir private public temp (cd private; mkdir lab ...) (cd public; mkdir music book ...) (cd public/book; mkdir java c++ Pascal) This imitates the way you would do it interactively, with cd .. maybe to return to the higher level.


1

/usr/local/share, /opt, or users directory. /usr/local follows the same structure as /usr however it is for you to put your own stuff into. /usr is for the system installer to manage. Don't get in its way. /usr/local will not be touched by built in tools, so can be backed up and managed more easily. /opt is also (like /usr/local) for your own use. However ...


1

Beyond all other reasons mentioned here it is design simplicity, something for which UNIX is known. All directories contain ..; special cases are always tripping hazards (for security or robustness) looming in the dark. So instead of forcing programmers to deal with one rare case in many places, all directories are designed to have . and .. entries and are ...


1

There's no standard location for this. The standard way to do things is that you have to be privileged to install a program in a place where other users would run it. It's your choice between a subtree of /usr/local like /usr/local/users/bin, a subdirectory of /home like /home/shared/bin, a subdirectory of /opt like /opt/users/bin, etc. Do use path ending ...


1

I've found it rather difficult to understand your earlier iterations of this question, so I'm going to restate a simplified version of what I think you mean, along with a corresponding worked example: Structure C:\iMazing\Backups\ AL\ files... BL\ files... iMazing.Versions\Versions\ AH\ files... BH\ ...


1

The following script will search the current working directory for paths of the form a/B/B/c and compress them to a/B/c. This also compresses a/B/B/B/B/c to a/B/c and a/B/B/c/D/D/e to a/B/c/D/e. You need GNU find to use the -regextype option and an implementation of mv supporting -n. If you don't have these please have a look at the unsafe posix version at ...


1

Not sure if it's what you need but... mv /maindir/fold2/ /maindir/renamed/ mv /maindir/renamed/fold2/ /maindir/fold2/ then, renamed should be empty, delete it. or this should do the job too mv maindir/fold2/fold2/{*,.*} maindir/fold2/ then /maindir/fold2/fold2/ should be empty


1

You should rewrite your command on this way: cd ~/data; find . -cmin -60 -mmin -60 -type f to be able to get from find relative paths And maybe something like find ... -exec cp -r "{}" ../vee/ \; will do the work with copy the files with subdirectory structure


1

IMAP is a communication protocol not a server! Theoretically a server can store files however it likes but you haven't specified which server you will be using. If you use Dovecot then you can stick with maildir format: https://wiki.dovecot.org/MailLocation/Maildir Dovecot will use the users's mail directory as the inbox. Dovecot will store other IMAP ...


1

x@x-device:/media/x$ cd Segate Backup Plus Drive bash: cd: too many arguments Your command did not work because you didn't quote the spaces. It has nothing to do with where the directory is physically located. A proper way to cd into a directory with spaces (or call any other command on it) would be $ cd 'Segate Backup Plus Drive' or $ cd "Segate ...


1

I finally wrote a solution and posted it on Github: https://github.com/minTaqa/mvrel It is not currently as flexible as "mv", in that only two arguments are allowed, and the second argument must be a directory. However, I found it useful for moving something that had a lot of relative symlinks. I wanted to make sure that it could deal with spaces, newlines,...


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