Find all dot files and directories

ls -a | egrep "^\.\w"
trying to copy all your dotfiles from one location to another, this may help
Sample Output
.bash_profile
.bashrc
.ssh

-2
By: kulor
2009-11-11 18:19:56

4 Alternatives + Submit Alt

What Others Think

This is possible with 'find', but is quite verbose: find -maxdepth 1 -regex '^\./\..*' -printf '%f\n' | sort piping through 'sort' to match default output of 'ls'.
pysquared · 465 weeks and 4 days ago
If the goal of "\w" in the regexp is to avoid listing . and .. then ls has the -A option.
rbossy · 465 weeks and 4 days ago
ls -1d .* no need grep here... Or simply $ ls .[tab]
sputnick · 465 weeks and 4 days ago
@pysquared considered find but as you mentioned, it is a bit to verbose. @rbossy the goal of the \w is to filter the results to return only dotfiles and folders but exclude '.' & '..' at the same time. The following code does not work in the context of searching dotfiles 'ls -aA .*' @sputnick ls -1d .* . .. So I would still need to inverse grep the results anyway
kulor · 465 weeks and 4 days ago
ls -1d .[[:alnum:]]*
sputnick · 465 weeks and 4 days ago
@sputnick nice one
kulor · 465 weeks and 4 days ago
@kulor: c'mon, if you use -A instead of -a, the \w in the regexp is useless. @sputnik: I think it does not exclude . and ..
rbossy · 465 weeks and 3 days ago
@pysquared: -name ".*". No need regex.
unixmonkey7109 · 464 weeks and 3 days ago
@unixmonkey7109: I tried -name ".*", but it does not exclude ".".
pysquared · 464 weeks and 2 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: