Tag Info

Hot answers tagged

71

Zsh mv Foo/*(DN) Bar/ or setopt -s glob_dots mv Foo/*(N) Bar/ (Leave out the (N) if you know the directory is not empty.) Bash shopt -s dotglob nullglob mv Foo/* Bar/ Ksh93 If you know the directory is not empty: FIGNORE='.?(.)' mv Foo/* Bar/ Standard (POSIX) sh for x in Foo/* Foo/.[!.]* Foo/..?*; do if [ -e "$x" ]; then mv -- "$x" Bar/ done ...


45

You can't rename a file to . or .. because all directories already contain entries for those two names. (Those entries point to directories, and you can't rename a file to a directory.) mv detects the case where the destination is an existing directory, and interprets it as a request to move the file into that directory (using its current name). ...


17

Because those applications that place configuration files in $HOME are ignoring the XDG Base Directory Specification, notably: There is a single base directory relative to which user-specific configuration files should be written. This directory is defined by the environment variable $XDG_CONFIG_HOME... If $XDG_CONFIG_HOME is either not set or empty, a ...


17

Bash, ksh and zsh have better solutions, but in this answer I assume a POSIX shell. The pattern .[!.]* matches all files that begin with a dot followed by a non-dot character. (Note that [^.] is supported by some shells but not all, the portable syntax for character set complement in wildcard patterns is [!.].) It therefore excludes . and .., but also files ...


17

I always get burned when I try using .* for anything and long ago switched to using character classes: chown -R username.groupname .[A-Za-z]* is how I would have done this. Edit: someone pointed out that this doesn't get, for example dot files such as ._Library. The catch all character class to use would be chown -R username.groupname .[A-Za-z0-9_-]*


16

Keep the dotfiles as portable as possible and avoid OS dependent settings or switches that require a particular version of a tool, e.g. avoid GNU syntax if you don't use GNU software on all systems. You'll probably run into situations where it's desirable to use system specific settings. In that case use a switch statement with the individual settings: ...


16

.. is not special, it is just that it already exists. On Unix, Dos and MS-Windows every directory has a directory . it links back to itself, and a directory .. it links to its parent directory (or self if root directory). If .. and . are special it is only because you can not remove them (actually you can, you just remove the directory that contains ...


14

#!/bin/bash shopt -s dotglob mv Foo/* Bar/ From man bash dotglob If set, bash includes filenames beginning with a '.' in the results of pathname expansion.


14

. is the relative reference for the current directory. .. is the relative reference for the parent directory. This is why cd .. makes the parent directory the new working directory.


13

You've misinterpreted the primary rationale for "hidden files". It is not to prevent users from messing around with things. Although it may have this consequence for very new users until they learn what a "dot file" is (dot file and dot directory are perhaps more appropriate and specific terms than "hidden"). All by itself it doesn't prevent you from ...


12

A complement to jasonwryan's great answer, addressing some of your issues: Your $XDG_CONFIG_HOME is not set to ~/. It simply isn't set. So applications that follow the XDG Speciifcation use the default ~/.config The dirs inside /.config are not hidden because they don't have to. The whole point of using a ~/.config dir is to un-clutter the user's $HOME. ...


12

To start with ~/somedirectory and ~/.somedirectory are different directories (mkdir wont fail with a File Exists message). The ls command will not show those entries starting with the .. If you ls -a, then ls will show both directories.


12

Disclaimer: This answer deals with Bash specifically but much of it applies to the question regarding glob patterns! The star character (*) is a wildcard. There are a certain set of characters that it will take the place of and the first character being a dot (.) isn't one of them. This is a special case just because of how the Unix filesystems work, files ...


11

I wouldn't want my entire home directory checked into version control simply because it means every subdirectory I go into would have the version-control context of my home dir. Commands like git checkout would have an actual action in that case, causing issues if I accidentally run something from the wrong directory, whether that something is git itself or ...


10

Using the extended globbing (shopt -s extglob), you can use .!(.|) i.e. dot not followed by dot or nothing.


10

The character . is only excluded from wildcard matching when it's the first character of the file name and it would be matched by a wildcard. In the pattern .*, the * matches strings beginning with ., so .* includes .. (as well as ., with * matching the empty string). This is a straightforward consequence of the pattern matching rules, annoying though it may ...


9

Quoting from the Single Unix specification version 2, volume ”Commands & Utilities", §2.13.3: If a filename begins with a period (.) the period must be explicitly matched by using a period as the first character of the pattern or immediately following a slash character. (…) It is unspecified whether an explicit period in a bracket expression matching ...


9

You can remove hidden directories (with . at the beginning of the name) like normal directories: rm -rf .directory_name (r for recursive, f for force). To display hidden directories use -a option for ls: ls -a You can also use mc or some other file manager to remove them. Most of them will have option to display hidden directories in View menu or in ...


9

Yes, there is at least one major pitfall when considering git to manage a home directory that is not a concern with subversion. Git is both greedy and recursive by default. Subversion will naively ignore anything it doesn't know about and it stops processing folders either up or down from your checkout when it reaches one that it doesn't know about (or ...


9

According to Wikipedia, The notion that filenames preceded by a . should be hidden is the result of a software bug in the early days of Unix. When the special . and .. directory entries were added to the filesystem, it was decided that the ls command should not display them. However, the program was mistakenly written to exclude any file whose name ...


8

The .config directory is a newish development courtesy of XDG that seems, deservedly, to have won favour. Personally, I don't mind a dot directory of your own. A bunch of separate dot files (ala bash and various old school tools) in the toplevel of $HOME is a bit silly. Choosing a single dot file is a bad idea, because if in the future you realize maybe ...


8

You can use the GLOBIGNORE bash variable. GLOBIGNORE A colon-separated list of patterns defining the set of filenames to be ignored by pathname expansion. If a filename matched by a pathname expansion pattern also matches one of the patterns in GLOBIGNORE, it is removed from the list of ...


8

Files starting with a dot are ignored by default by the command "ls", which has more or less the same effect of "hidden" files but is not the same (other commands may choose to do the same or not). Files starting with a dot are not "hidden" because "hidden" is not one of their attributes. Unlike in DOS/Windows, "hidden" is not an attribute in Unix. There are ...


7

For details on the Unix file system check the standard. Specifically, dot files are used for configuration files in a users directory, and if a program has more than one, it should put them into a dot directory. This hides the files from the user, unless they want to find them. That way they don't get in the way, and tools don't go messing with them ...


7

. and .. are hard links to the current and the parent directory (/ is the parent of itself). With the -a option ls shows all inodes in the current directory, i.e. also the hidden files which filenames begin with ad dot, therefore . and .. are shown.


7

With zsh, the typical way is to use the D globbing qualifier (to include [D]ot files): cp foo/*(D) .


6

You can use the the extended globbing in bash: shopt -s extglob ls .!(.|git) This also matches ., though, so you probably need ls .!(|.|git)


6

This works if all of the filenames contain at least three characters (including the dot): chown -R root .??* For a more robust solution, you can use find: find . -maxdepth 1 -name '.*' -exec chown -R root {} \;


6

Consider using find (-maxdepth is a non-POSIX extension, but it should be readily available on Linux): find . -maxdepth 1 -type d -name '.*' -exec chown -R user:group {} +


6

If the directory itself shares the same ownership as its files (hidden or not), then you can chown it recursively instead. The -R option will include hidden files when recursing inside the current directory. $ chown user:group . -R # Will include all hidden files



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