Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I delete all files starting with ._ from the shell in Linux?

As the title really. I have copied over a number of files to a Raspberry Pi from a Mac. This has resulted in lots of superfluous files starting with the prefix ._. I want to delete every file in a folder that starts with ._. How would I do this?

like image 402
Garry Pettet Avatar asked Dec 06 '14 12:12

Garry Pettet


People also ask

How do I delete a file starting with Linux?

You can use standard UNIX or Linux rm command to delete a file name starting with - or -- . All you have to do is instruct the rm command not to follow end of command line flags by passing double dash -- option before -foo file name.

How do I delete all files from a certain type?

You can do this using the Windows GUI. Enter "*. wlx" in the search box in explorer. Then after the files have been found, select them all (CTRL-A) and then delete using the delete key or context menu.

How do I delete multiple files in Shell?

To delete multiple files at once, use the rm command followed by the file names separated by space. When using regular expansions, first list the files with the ls command so that you can see what files will be deleted before running the rm command.


2 Answers

Try something like:

cd /path/to/directory; \rm -rf ._*

OR if there are recursive files with in subfolders then try:

find /path/to/directory -name "._*" -type f -print0| xargs -0 \rm -rf
like image 193
SMA Avatar answered Nov 05 '22 01:11

SMA


The EASY WAY:

to remove files starting with a string like : example-1.html, example-2.js, ...

 rm examp*

to remove directories starting with a string like : example-1/, example-1-1-0/, example-2/, ...

rm -rf examp*

PS:

-r for recursively

-f for force (the erasing as used for not empty directories)

that's all folks!

like image 25
marcdahan Avatar answered Nov 05 '22 02:11

marcdahan