Can anyone give me a bash script or one line command i can run on linux to recursively go through each folder from the current folder and delete all files or directories starting with '._'?
To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.
How do I delete folder recursively under Linux operating systems using a bash command line options? You need to use the rm command to remove files or directories (also known as folders) recursively. The rmdir command removes only empty directories. So you need to use rm command to delete folder recursively under Linux.
To loop through a directory, and then print the name of the file, execute the following command: for FILE in *; do echo $FILE; done.
The syntax to loop through each file individually in a loop is: create a variable (f for file, for example). Then define the data set you want the variable to cycle through. In this case, cycle through all files in the current directory using the * wildcard character (the * wildcard matches everything).
Change directory to the root directory you want (or change .
to the directory) and execute:
find . -name "._*" -print0 | xargs -0 rm -rf
xargs
allows you to pass several parameters to a single command, so it will be faster than using the find -exec
syntax. Also, you can run this once without the |
to view the files it will delete, make sure it is safe.
find . -name '._*' -exec rm -Rf {} \;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With