Page 1 of 1

bash wildcard question

Posted: Fri Jul 23, 2004 11:55 pm
by Magic
is there an argument for wildcards, say for example, you want to delete all files that start with "b" OR ends with ".zip"?

i know how to do AND by rm -f b*.zip, but is there a single command for OR, so it would delete .zips and files that start with b? or do i have to do two separate deletes?

thanks. sorry for the n00b question.

Archived topic from Anythingforums, old topic ID:651, old post ID:5648

bash wildcard question

Posted: Sat Jul 24, 2004 4:33 am
by megaspaz
seperate the filetypes you want to delete with a space.

rm -f *.txt *.cpp *.html

will delete all .txt text files, all .cpp files, and all .html files.

Archived topic from Anythingforums, old topic ID:651, old post ID:5658

bash wildcard question

Posted: Sat Jul 24, 2004 5:09 am
by Magic
So would the above be rm -f b* *.zip? Just a space and extra star?

Archived topic from Anythingforums, old topic ID:651, old post ID:5661

bash wildcard question

Posted: Sat Jul 24, 2004 4:01 pm
by megaspaz
Magic wrote: So would the above be rm -f b* *.zip? Just a space and extra star?
the b* would get rid of any file starting with a b, any directory that's empty starting with a b, and the *.zip would get rid of all zip files.

Archived topic from Anythingforums, old topic ID:651, old post ID:5702

bash wildcard question

Posted: Sat Jul 24, 2004 4:03 pm
by Magic
megaspaz wrote:
Magic wrote: So would the above be rm -f b* *.zip? Just a space and extra star?
the b* would get rid of any file starting with a b, any directory that's empty starting with a b, and the *.zip would get rid of all zip files.
yeah, read my first post. :P

:up: thanks.

Archived topic from Anythingforums, old topic ID:651, old post ID:5703

bash wildcard question

Posted: Sat Jul 24, 2004 4:04 pm
by megaspaz
ah... that would get rid of all the zip files starting with b.

Archived topic from Anythingforums, old topic ID:651, old post ID:5706

bash wildcard question

Posted: Sat Jul 24, 2004 4:06 pm
by Magic
megaspaz wrote: ah... that would get rid of all the zip files starting with b.
let me get this straight...rm -f b*.zip gets rid of .zip files starting with b, and

rm -f b* *.zip get's rid of ALL zip files regardless of what letter it starts with and ALL files starting with b regardless of ending, right?

Archived topic from Anythingforums, old topic ID:651, old post ID:5707

bash wildcard question

Posted: Sat Jul 24, 2004 4:09 pm
by megaspaz
Magic wrote:
megaspaz wrote: ah... that would get rid of all the zip files starting with b.
let me get this straight...rm -f b*.zip gets rid of .zip files starting with b, and

rm -f b* *.zip get's rid of ALL zip files regardless of what letter it starts with and ALL files starting with b regardless of ending, right?
almost on the last one. the last one will also get rid of any empty directories starting with a b.

Archived topic from Anythingforums, old topic ID:651, old post ID:5708

bash wildcard question

Posted: Sat Jul 24, 2004 4:10 pm
by Magic
megaspaz wrote:
Magic wrote:
megaspaz wrote: ah... that would get rid of all the zip files starting with b.
let me get this straight...rm -f b*.zip gets rid of .zip files starting with b, and

rm -f b* *.zip get's rid of ALL zip files regardless of what letter it starts with and ALL files starting with b regardless of ending, right?
almost on the last one. the last one will also get rid of any empty directories starting with a b.
how do i get rid of directories with files? use recursive argument?

rm- rf b* *.zip?

Archived topic from Anythingforums, old topic ID:651, old post ID:5709

bash wildcard question

Posted: Sat Jul 24, 2004 4:13 pm
by megaspaz
Magic wrote:
megaspaz wrote:
Magic wrote:

let me get this straight...rm -f b*.zip gets rid of .zip files starting with b, and

rm -f b* *.zip get's rid of ALL zip files regardless of what letter it starts with and ALL files starting with b regardless of ending, right?
almost on the last one. the last one will also get rid of any empty directories starting with a b.
how do i get rid of directories with files? use recursive argument?

rm- rf b* *.zip?
yep

Archived topic from Anythingforums, old topic ID:651, old post ID:5710

bash wildcard question

Posted: Sat Jul 24, 2004 4:17 pm
by Magic
:up:

oh yeah, what if i want to leave the directories alone? even empty ones? :huh:

Archived topic from Anythingforums, old topic ID:651, old post ID:5711

bash wildcard question

Posted: Sat Jul 24, 2004 4:20 pm
by megaspaz
add in the file extension. if no file extension, you'll need to write a shell script to check if the file is a directory.

Archived topic from Anythingforums, old topic ID:651, old post ID:5712

bash wildcard question

Posted: Sat Jul 24, 2004 4:21 pm
by Magic
megaspaz wrote: add in the file extension. if no file extension, you'll need to write a shell script to check if the file is a directory.
hehe, writing scripts is still new to me. is that basically creating your custom code?

Archived topic from Anythingforums, old topic ID:651, old post ID:5713

bash wildcard question

Posted: Sat Jul 24, 2004 4:26 pm
by megaspaz
not really as you're only basically going to use the commands and some logical constructs.

Archived topic from Anythingforums, old topic ID:651, old post ID:5714

bash wildcard question

Posted: Sat Jul 24, 2004 4:33 pm
by Magic
megaspaz wrote: not really as you're only basically going to use the commands and some logical constructs.
i don't understand your jargon, sorry. :wacko:

Archived topic from Anythingforums, old topic ID:651, old post ID:5715

bash wildcard question

Posted: Sat Jul 24, 2004 4:34 pm
by megaspaz
Magic wrote:
megaspaz wrote: not really as you're only basically going to use the commands and some logical constructs.
i don't understand your jargon, sorry. :wacko:
a shell script is basically a sequence of shell commands you normally use. logical constructs allow for action to be taken if they meet certain requirements.

Archived topic from Anythingforums, old topic ID:651, old post ID:5716

bash wildcard question

Posted: Sat Jul 24, 2004 4:43 pm
by Magic
megaspaz wrote:
Magic wrote:
megaspaz wrote: not really as you're only basically going to use the commands and some logical constructs.
i don't understand your jargon, sorry. :wacko:
a shell script is basically a sequence of shell commands you normally use. logical constructs allow for action to be taken if they meet certain requirements.
ahh, thanks there. B) :up:

Archived topic from Anythingforums, old topic ID:651, old post ID:5717