LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 07-17-2017, 09:36 AM   #1
Weapon S
Member
 
Registered: May 2011
Location: Netherlands
Distribution: Debian, Archlinux
Posts: 260
Blog Entries: 2

Rep: Reputation: 49
rm directory/{.[^.],}* has unexpected result


I had a directory I wanted to remove all files from. So I did `rm -Rf directory/*`. That of course didn't remove the hidden files. So I did an internet search and found `rm directory/{.[^.],}*`. I understand that pattern. The weird part is the result.
(FYI it was actually the tmp directory of a system I chrooted into and out of.)
Code:
$ rm tmp/{.[^.],}*
rm: cannot remove 'tmp/.font-unix': Is a directory
rm: cannot remove 'tmp/.ICE-unix': Is a directory
rm: cannot remove 'tmp/.X11-unix': Is a directory
rm: cannot remove 'tmp/.XIM-unix': Is a directory
rm: cannot remove 'tmp/*': No such file or directory
Considering I forgot the -R flag, pretty predictable, right? But then:
Code:
$ ls -a tmp/
. ..
As you can see it removed all directories despite the warnings and the lack of the -R flag. What the heck happened here? Why did it remove the directories?
 
Old 07-18-2017, 01:55 AM   #2
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,745

Rep: Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791
Something else must have deleted the directories.
--
Other methods to clean a directory:
Code:
find . -mindepth 1 -maxdepth 1 -exec rm -Rf {} +
Or
Code:
find . -depth -mindepth 1 -delete
These can easily be expanded if certain files or subdirectories should be excluded.
 
Old 07-18-2017, 03:28 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,513

Rep: Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552
rm cannot delete directories without -r.
So actually all of those messages are (can be) acceptable.
 
Old 07-19-2017, 04:19 PM   #4
tofino_surfer
Member
 
Registered: Aug 2007
Posts: 472

Rep: Reputation: 150Reputation: 150
Quote:
rm cannot delete directories without -r.
So actually all of those messages are (can be) acceptable.
This obviously isn't the issue. Of course the messages from rm are acceptable as the -r flag wasn't given.

However if you had read the whole post the directories got deleted somehow anyway. The whole point of the post is that it is a mystery how the directories got deleted since the rm command refused to delete them.

Last edited by tofino_surfer; 07-19-2017 at 04:38 PM.
 
Old 07-20-2017, 12:23 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,513

Rep: Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552
Quote:
Originally Posted by tofino_surfer View Post
This obviously isn't the issue. Of course the messages from rm are acceptable as the -r flag wasn't given.

However if you had read the whole post the directories got deleted somehow anyway. The whole point of the post is that it is a mystery how the directories got deleted since the rm command refused to delete them.
Yes, sorry, my mistake.

so either something else deleted that, or the two dirs are not the same tmp .
 
Old 07-20-2017, 11:57 PM   #6
Weapon S
Member
 
Registered: May 2011
Location: Netherlands
Distribution: Debian, Archlinux
Posts: 260

Original Poster
Blog Entries: 2

Rep: Reputation: 49
I have been unable to recreate this. Hopefully I was just confused and deleted those directories in the mean-time. Thank you for your time.
 
  


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
[SOLVED] awk -- asorti produces unexpected result danielbmartin Programming 16 03-01-2017 10:32 AM
[SOLVED] SORT - unexpected result danielbmartin Programming 3 09-30-2015 10:18 AM
Unexpected result in while do done loop reading file steven.c.banks Linux - General 2 05-01-2008 12:32 PM
mysql count(*) unexpected result kpachopoulos Programming 3 01-03-2008 10:08 AM
cp command problem..... unexpected result hamster Linux - General 2 04-10-2003 04:57 PM

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

All times are GMT -5. The time now is 08:05 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
Open Source Consulting | Domain Registration