bash wildcard question

Computer builds, hardware and software discussion or troubleshooting, including peripherals. Essentially a general place to talk about desktop computers.
Locked
User avatar
Magic
Posts: 362
Joined: Thu Jun 24, 2004 5:26 pm

bash wildcard question

Post 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
megaspaz
Posts: 340
Joined: Wed Dec 18, 2002 10:08 pm

bash wildcard question

Post 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
Image
Resistance is futile...

Registered Linux User #321628
Anime/Toon Avatars
Other Cool Forums

"Never hold your farts in. They travel up your spine, into your brain, and that's where you get s**tty ideas from..." - Woyaya - January 10, 2004
User avatar
Magic
Posts: 362
Joined: Thu Jun 24, 2004 5:26 pm

bash wildcard question

Post 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
megaspaz
Posts: 340
Joined: Wed Dec 18, 2002 10:08 pm

bash wildcard question

Post 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
Image
Resistance is futile...

Registered Linux User #321628
Anime/Toon Avatars
Other Cool Forums

"Never hold your farts in. They travel up your spine, into your brain, and that's where you get s**tty ideas from..." - Woyaya - January 10, 2004
User avatar
Magic
Posts: 362
Joined: Thu Jun 24, 2004 5:26 pm

bash wildcard question

Post 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
megaspaz
Posts: 340
Joined: Wed Dec 18, 2002 10:08 pm

bash wildcard question

Post 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
Image
Resistance is futile...

Registered Linux User #321628
Anime/Toon Avatars
Other Cool Forums

"Never hold your farts in. They travel up your spine, into your brain, and that's where you get s**tty ideas from..." - Woyaya - January 10, 2004
User avatar
Magic
Posts: 362
Joined: Thu Jun 24, 2004 5:26 pm

bash wildcard question

Post 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
megaspaz
Posts: 340
Joined: Wed Dec 18, 2002 10:08 pm

bash wildcard question

Post 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
Image
Resistance is futile...

Registered Linux User #321628
Anime/Toon Avatars
Other Cool Forums

"Never hold your farts in. They travel up your spine, into your brain, and that's where you get s**tty ideas from..." - Woyaya - January 10, 2004
User avatar
Magic
Posts: 362
Joined: Thu Jun 24, 2004 5:26 pm

bash wildcard question

Post 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
megaspaz
Posts: 340
Joined: Wed Dec 18, 2002 10:08 pm

bash wildcard question

Post 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
Image
Resistance is futile...

Registered Linux User #321628
Anime/Toon Avatars
Other Cool Forums

"Never hold your farts in. They travel up your spine, into your brain, and that's where you get s**tty ideas from..." - Woyaya - January 10, 2004
User avatar
Magic
Posts: 362
Joined: Thu Jun 24, 2004 5:26 pm

bash wildcard question

Post 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
megaspaz
Posts: 340
Joined: Wed Dec 18, 2002 10:08 pm

bash wildcard question

Post 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
Image
Resistance is futile...

Registered Linux User #321628
Anime/Toon Avatars
Other Cool Forums

"Never hold your farts in. They travel up your spine, into your brain, and that's where you get s**tty ideas from..." - Woyaya - January 10, 2004
User avatar
Magic
Posts: 362
Joined: Thu Jun 24, 2004 5:26 pm

bash wildcard question

Post 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
megaspaz
Posts: 340
Joined: Wed Dec 18, 2002 10:08 pm

bash wildcard question

Post 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
Image
Resistance is futile...

Registered Linux User #321628
Anime/Toon Avatars
Other Cool Forums

"Never hold your farts in. They travel up your spine, into your brain, and that's where you get s**tty ideas from..." - Woyaya - January 10, 2004
User avatar
Magic
Posts: 362
Joined: Thu Jun 24, 2004 5:26 pm

bash wildcard question

Post 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
megaspaz
Posts: 340
Joined: Wed Dec 18, 2002 10:08 pm

bash wildcard question

Post 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
Image
Resistance is futile...

Registered Linux User #321628
Anime/Toon Avatars
Other Cool Forums

"Never hold your farts in. They travel up your spine, into your brain, and that's where you get s**tty ideas from..." - Woyaya - January 10, 2004
User avatar
Magic
Posts: 362
Joined: Thu Jun 24, 2004 5:26 pm

bash wildcard question

Post 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
Locked