LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 04-01-2015, 06:44 PM   #1
kevz
LQ Newbie
 
Registered: Mar 2015
Posts: 4

Rep: Reputation: Disabled
Removing files starting with dot


Hello,

I would like to remove those files:

MyDir/boo.tmp
MyDir/.zip.tmp

rm MyDir/*.tmp removes only boo.tmp but not .zip.tmp (No such file or directory).

I want to be able to remove any file that finishes with the .tmp extension even if the filename starts with .something.tmp

Thanks for your help :}
 
Old 04-01-2015, 06:49 PM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,253

Rep: Reputation: 559Reputation: 559Reputation: 559Reputation: 559Reputation: 559Reputation: 559
Code:
find -iname ".*.tmp" -delete
But be careful with the -delete option to find as you can SERIOUSLY fubar your system, read the man page for find first.
 
Old 04-01-2015, 07:23 PM   #3
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 476Reputation: 476Reputation: 476Reputation: 476Reputation: 476
In addition to what Keith suggested. I would say before you go ahead with delete get the list. So here is how you have to do:

Code:
find -iname ".*.tmp" -print >> list_of_files_to_be_deleted
Once you have checked that whatever showing up in the list are indeed the files you want to delete and nothing useful, then you can run a for loop to delete those files like this:

Code:
for i in cat `list_of_files_to_be_deleted`
do
{
     rm -rf $i
}
done
 
Old 04-01-2015, 11:13 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Quote:
Originally Posted by kevz View Post
Hello,

I would like to remove those files:

MyDir/boo.tmp
MyDir/.zip.tmp

rm MyDir/*.tmp removes only boo.tmp but not .zip.tmp (No such file or directory).

I want to be able to remove any file that finishes with the .tmp extension even if the filename starts with .something.tmp

Thanks for your help :}
This is because files starting with "." are skipped by the shell evaluating "*". It prevents bad things like "rm -rf *" from trying to delete "." and/or "..". Actually deleting these that way would cause you to loose all your files (an rm "..", would remove the parent directory...).

The safer way is to do an "rm .*.tmp", and though it requires a second command, you could do a "rm *.tmp .*.tmp" which will delete both.
 
1 members found this post helpful.
Old 04-07-2015, 06:35 PM   #5
kevz
LQ Newbie
 
Registered: Mar 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thank you for your replies.
I'll probably go with the safer way "rm *.tmp .*.tmp"

Also...
How do you safely remove a file called "*." ?
 
Old 04-07-2015, 06:44 PM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
You just delimit the *

Code:
rm \*.
 
Old 04-07-2015, 06:47 PM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Quote:
Originally Posted by kevz View Post
Thank you for your replies.
I'll probably go with the safer way "rm *.tmp .*.tmp"

Also...
How do you safely remove a file called "*." ?
I usually do it with a "rm './*.'", where the single quotes disable the substitutions that the shell would do. But if you have a mix characteristics where you want to use wildcards as well as non-wildcards you have to escape the non-wildcards...
 
Old 04-07-2015, 07:36 PM   #8
timl
Member
 
Registered: Jan 2009
Location: Sydney, Australia
Distribution: Fedora,CentOS
Posts: 582

Rep: Reputation: 127Reputation: 127
I guess
Quote:
rm -i
is an option. This prompts before removal
 
  


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
file name starting with dot sryzdn Linux - Newbie 6 06-11-2013 11:22 PM
rsync problems due to dot files (.*.ext) from Mac OSX created files rjo98 Linux - Server 11 03-29-2013 02:19 PM
How to remove all (dot) files without removing toplevel dir? mattengland Linux - Software 8 07-19-2011 03:57 PM
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


All times are GMT -5. The time now is 12:51 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration