![]() |
Write a shell scriprt to delete files size of 56KB
I wanna know how to write a shell script that deletes specific kind of a file type with a 56KB
example : exe files with 56KB |
find . -type f -name "*.exe" -size 56k -exec rm -f {} \;
|
Code:
#!/bin/bashCode:
#!/bin/bashCode:
#!/bin/bashThe first example deletes all .exe files which are precisely 56KB from the directory you are in (PWD) and all subdirectories. The second example deletes all .exe files 56KB and under starting from root directory and all subdirectories, meaning it'll delete 56KB and under .exe files throughout the entire file system. The third deletes all files larger than 56KB from root and all subdirectories. There are many ways to use the find command, this shows two ways, one may be safer than the other. |
Test any scripts you get from forums/online on expendable files in a testing directory first before executing in valuable areas of the file system.
Just a safety precaution. |
With find, it's usually safest to run it without the -delete or -exec part first. It will just display a list of files that meet the given criteria. So, for example
find . -name "*.exe" -size 56k and see if the list makes sense before running find . -name "*.exe" -size 56k -exec rm -f {} \; |
| All times are GMT -5. The time now is 04:59 PM. |