LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-15-2007, 03:58 AM   #1
zomane
Member
 
Registered: Sep 2005
Location: Austria
Distribution: Debian, CentOS, OpenBSD, FreeBSD
Posts: 52

Rep: Reputation: 16
bash, filenames, special chars


Hello.
This is the situation :
Directory with many subdirs, I want to delete, mv or cp ( this is not important in that case) all jpg files, I wrote a simple pipe :
find . | grep .jpg | xargs rm
But I have files that containing special chars like space, (, ) and so on, and of course pipe simply doesnt work . I know (on theory) how to escape special chars using \ " and ' but how to do this in my case, in man page of xargs i didnt find option for quoting .
In ABS guide I didnt find similar example.
Please give me an idea which is the "right" way how to proceed in cases such as this .
Thanks.
 
Old 06-15-2007, 04:11 AM   #2
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Code:
find ./ -iname "*.jpg" -exec rm "{}" \;
That works on my system. Substitute rm for mv or cp if you want, but give a destination if that's the case.

edit: if you're using rm, make sure you're in the correct directory first, and be very careful! This is a very efficient way of deleting large numbers of files, very quickly. Probably best to mv the files rather than rm them. So make a directory in home called tmp, and then run:
Code:
find ./ -iname "*.jpg" -exec mv "{}" ~/tmp/ \;

Last edited by pwc101; 06-15-2007 at 04:20 AM.
 
Old 06-15-2007, 04:45 AM   #3
zomane
Member
 
Registered: Sep 2005
Location: Austria
Distribution: Debian, CentOS, OpenBSD, FreeBSD
Posts: 52

Original Poster
Rep: Reputation: 16
Thank you very much . It works great .
 
Old 06-15-2007, 04:55 AM   #4
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
It's a pleasure
 
  


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
HowTo: special chars (ŰűŐő) in file names ceetrom Linux - Newbie 1 11-03-2006 12:53 PM
bash and filenames with special characters CoolAJ86 Programming 2 03-09-2005 02:50 PM
Problem with special chars in general smokylux Linux - General 6 05-26-2004 04:46 AM
German umlaute (special chars) in file system steltner Linux - General 5 10-27-2003 02:07 PM
telnet and special chars csDraco_ Slackware 7 05-21-2003 09:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:18 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