Tag Info

Hot answers tagged

56

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

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 ...


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 ...


15

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: ...


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.


14

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 ...


11

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.


11

#!/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.


11

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 ...


10

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 ...


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

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 ...


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 ...


8

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. ...


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

. 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

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

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 ...


6

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 ...


6

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 ...


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 {} \;


5

Probably caused by your locale, but if you do: LC_COLLATE=C ls -F --color=auto -l The dot files are sorted correctly


4

If you're on Linux, you can try grep -IR --exclude-dir=".." culprit .* Since you asked about shell wildcards, my first thought is .[!.]* ..[!.]*, as in grep -IR culprit .[!.]* ..[!.]* Which has the problem that grep will exit with an error if there are no files starting with ... To get around that, you can either add -s to grep to tell it to ignore ...


4

If you have bash available, you can use extglob to get only dotfiles. shopt -s extglob grep -IR 'foo' .!(|.) The ! operator in an extended glob is "not". This pattern matches anything starting with a dot, excluding '.' and '..'.


4

I've tried both, and preferred the symlink approach in the end: Check out to wherever make install Log out and in again to load the X settings Disadvantages: Have to move files to the repo before adding them Have to maintain the list of symbolic links in the Makefile Advantages: No need for a massive .gitignore (I have 133 dotfiles in ~ on my ...


4

With tcsh 6.17.01 and above: set globdot du -s -- * With older ones: du -s -- * .[^.]* ..?* (interestingly, that works better than its POSIX counterpart (* .[!.]* ..?*) because in tcsh (and in zsh in csh emulation (cshnullglob option)), contrary to POSIX shells, those pattern that don't match any file get expanded to nothing instead of themselves) ...


4

The shell is treating those files as hidden when it resolves the * character, so cp doesn't receive any of these file names as arguments. You can copy them by explicitly specifying cp foo/.* .



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