LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 09-12-2007, 05:50 AM   #1
danielsbrewer
LQ Newbie
 
Registered: Aug 2007
Posts: 18

Rep: Reputation: 0
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?
 
Old 09-12-2007, 06:22 AM   #2
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
Use .[^.]*

for example, to list all hidden files and directories but not . and ..

Code:
ls -d .[^.]*
Try it out with something where you can't do any damage first.
 
Old 09-12-2007, 06:46 AM   #3
danielsbrewer
LQ Newbie
 
Registered: Aug 2007
Posts: 18

Original Poster
Rep: Reputation: 0
Thanks that worked great
 
Old 09-12-2007, 07:42 AM   #4
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
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.
 
Old 09-12-2007, 07:59 AM   #5
trashbird1240
Member
 
Registered: Sep 2006
Location: Durham, NC
Distribution: Slackware, Ubuntu (yes, both)
Posts: 463

Rep: Reputation: 31
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.

Joel
 
Old 09-12-2007, 08:06 AM   #6
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
Quote:
Originally Posted by trashbird1240 View Post
Whichever shell I'm using, I deal with the dots by quotation marks:
"."* only gets hidden files for me.
I am not familiar with Z shell, but in bash, the quotation marks won't make any difference. You will still pick up . and .. which the OP did not want.
 
  


Reply

Tags
chown, files, hidden, recursive, rm, shell



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM
LXer: Displaying "MyComputer", "Trash", "Network Servers" Icons On A GNOME Desktop LXer Syndicated Linux News 0 04-02-2007 08:31 AM
No UTMPX entry, You must EXEC "login" for the lowest "shell" ooihc Solaris / OpenSolaris 7 03-12-2007 02:09 PM
"NIM thread blocked" & "Deadman Switch (DMS) close to trigger" errors sosborne Linux - Networking 1 06-28-2006 02:07 PM
"X-MS" cant open because "x-Multimedia System" cant access files at "smb&qu ponchy5 Linux - Networking 0 03-29-2004 11:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration