Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove files when first two characters are ZZ

I want to delete all the files when the first two characters are equal to zz or ZZ. How can I do it?

like image 859
Diondk Avatar asked Jun 29 '11 08:06

Diondk


People also ask

How to delete files using wildcards in Linux?

The command line uses something called globbing. * is a wildcard for any string of characters. So by running rm *. log you are saying remove all files that end with .

How do I delete all files from a certain name?

To delete matching files: enter *_bad. jpg in the search box, select the results and press Delete or Del.

Which Linux command is used to delete all files whose filenames begin with a number from the current user's home directory?

You need to use the rm command to remove the files specified on the command line. You need to use bash special feature called globbing (a “wildcard”) for filename expansion.

How do you delete a file in PowerShell?

In PowerShell, the Remove-Item cmdlet deletes one or more items from the list. It utilizes the path of a file for the deletion process. Using the “Remove-Item” command, you can delete files, folders, variables, aliases, registry keys, etc.


2 Answers

Get all objects (including hidden, recursively) from a path with names starting with 'zz', filter out directory objects and delete the items.

Get-ChildItem <path> -Recurse -Force -Filter zz* | Where-Object {!$_.PSIsContainer} | Remove-Item
like image 74
Shay Levy Avatar answered Oct 25 '22 12:10

Shay Levy


This works for me:

Remove-Item zz*
like image 29
Tobb Avatar answered Oct 25 '22 10:10

Tobb