LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-11-2013, 02:46 AM   #1
sryzdn
Member
 
Registered: Feb 2013
Posts: 248

Rep: Reputation: 1
file name starting with dot


Hi, I simply ask the question I encountered in a book:

Quote:
why does it make sense for "*" not to match file names starting with a dot?
 
Old 06-11-2013, 05:13 AM   #2
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 343Reputation: 343Reputation: 343Reputation: 343
Hi there,

Quote:
Originally Posted by sryzdn View Post
Hi, I simply ask the question I encountered in a book:
Quote:
why does it make sense for "*" not to match file names starting with a dot?
is that a quiz or a question from an exam or something?

Well ... Traditionally, files starting with a dot are treated as "hidden". They're not listed by 'ls' except with the -a switch, and they're usually not displayed by graphical file managers - unless you tell them to ignore that tradition and show everything.

So I think it makes sense to exclude these hidden files from the search pattern '*', because the danger is imminent that you'd accidentally delete something you haven't even seen before.

[X] Doc CPU
 
1 members found this post helpful.
Old 06-11-2013, 06:03 AM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
There is also a different problem. There are two special directories that begin with a dot (. and ..). Those depict the current and the parent directory. If * by default would match names starting with a dot those two would also be matched, leading to, for example, deleting all directories when doing an
Code:
rm -r *
as root.
 
1 members found this post helpful.
Old 06-11-2013, 06:25 AM   #4
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 343Reputation: 343Reputation: 343Reputation: 343
Hi there,

Quote:
Originally Posted by TobiSGD View Post
There is also a different problem. There are two special directories that begin with a dot (. and ..). Those depict the current and the parent directory. If * by default would match names starting with a dot those two would also be matched, leading to, for example, deleting all directories when doing an
Code:
rm -r *
as root.
actually I haven't thought of that issue, but then again I didn't have to, because others did. *g*
Fact is, even if you supply a file name pattern that matches '.' or '..', the system won't let you delete them by those pseudo-names. Any attempt to do that will fail, even if you're root.

Suppose there is a directory "sub" in the current directory. Whatever you do, you can't delete it using the '.' pseudo-name inside it:

Code:
#rm -r sub/.
rm: cannot remove directory: `sub/.'
#rmdir sub/.
rmdir: failed to remove `sub/.': Invalid argument
In Windows, it's the same if you try to delete '.' using an API call; from the console, however, many commands (like 'del') implicitly treat the '.' pattern as './*'. As a result, 'del .' isn't understood as "delete the current directory", but instead as "delete all files inside the current directory".

[X] Doc CPU
 
1 members found this post helpful.
Old 06-11-2013, 01:47 PM   #5
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
You are right with the single . directory, but not with the double .. directory (been there, done that, gladly I have a good backup scheme and the luck that I have done it as normal user with no rights above my /home, so that I could easily restore it)
 
1 members found this post helpful.
Old 06-11-2013, 02:44 PM   #6
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 343Reputation: 343Reputation: 343Reputation: 343
Hi there,

Quote:
Originally Posted by TobiSGD View Post
You are right with the single . directory, but not with the double .. directory (been there, done that, gladly I have a good backup scheme and the luck that I have done it as normal user with no rights above my /home, so that I could easily restore it)
wow, that's weird, thanks for mentioning this! When I saw my test results about the single dot directory, I didn't even think the double-dot might behave differently. By the way, you don't think I did that without any safety precaution, do you? ;-)
I ran my tests in a VM that I could easily roll back or throw away entirely (which is what I did, delete after use).

[X] Doc CPU
 
1 members found this post helpful.
Old 06-11-2013, 11:22 PM   #7
hanamilani
Member
 
Registered: Dec 2008
Posts: 66

Rep: Reputation: 0
Guys, thanks for the wonderful answers
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Make awk detect lines starting with a dot BlueSpirit Programming 12 05-15-2011 11:50 AM
du -hs .* does not show size of directories starting with a dot (anymore) Hannes Linux - Desktop 2 03-22-2011 01:34 PM
how to hide a file using file permissions in linux without using dot davender84 Linux - General 4 03-26-2009 01:13 AM
How to get file extension (without the dot) scls19fr Linux - General 11 08-21-2008 12:48 PM
useradd not accepting dot so i am not able to use dot in mail id hanu_raob Linux - General 5 05-13-2004 08:04 AM


All times are GMT -5. The time now is 08:16 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration