Shell and batch operations on hidden files but not on ".." & "."
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Shell and batch operations on hidden files but not on ".." & "."
In the shell, is it possible to perform a recursive batch action on all of the hidden files but not on ".." & "."?
Let me give you an example of what I mean. Acting as root, I wanted to change the all the hidden files in a user's home directory including the contents of any hidden directory. So I did this:
chown -R user.group .*
This ended up changing not only the hidden files/directories but the normal files and directories and worst of all /home and everything within it.
I am assuming that I similar thing would happen if I tried the command rm -rf .* i.e. the contents of all parent directories up to "/" would be deleted.
The problem is that ".." and "." are picked up by .*.
Any ideas of how to perform these sort of actions correctly?
I just realized that .[^.]* will miss files that start with two dots! But you probably don't have too many of those. .*[^.]* is a little better, but will still miss files that consist of nothing but dots (for example, 3 dots only). I can't think of anything that completely meets your criterion.
CORRECTION: (albeit probably just an academic one!) You can cover all bases by using two globbing expressions:
Code:
ls -d .*[^.]* ...*
CORRECTION2: Drat! The above will (potentially) list some files twice. For this (probably) totally academic excercise, lets see if the third time is the charm:
Code:
ls -d .[^.]* ..?*
Last edited by blackhole54; 09-12-2007 at 07:55 AM.
I'd just like to put in a plug for my favorite shell, the Z Shell,
which you can still program in if you're running as root. One of the
nice things about the file-globbing in Z Shell is that if you know the
situation you want to solve, you can look it up on Google: somebody
has definitely already done it.
Whichever shell I'm using, I deal with the dots by quotation marks:
"."* only gets hidden files for me.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.