Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
To find files in the present directory try:
find . -name [filename]
To delete said file:
rm [filename]
If you would like to run this through a script so you can invoke the script and have it look for a certain file, or group of files, and then delete them if they exist will take a little more work.
Something like the following might work:
#!/bin/sh if [ $# -eq 0 ] then echo "Usage: $0 [ordinary file]" exit 1 elif [ $# -gt 1 ] then echo "Usage: $0 [ordinary file]" exit 1 elif [ -d "$1" ] then echo "Usage: $0 [ordinary file]" exit 1 else if [ -s "$1" ] then find . -name $1 rm $1 echo "$1 deleted" else echo "File does not exist or is zero bytes" fi fi

find . -type f -exec rm {} \;
It will delete all the files in current directory and directories below current directory

This is more efficient:
find . -type f |xargs rm
as it does not spawn a process for each file that is removed.
If you want to restrict find to only the current directory, check this out:
http://www.computing.net/answers/un...
http://www.computing.net/answers/un...

>> find . -type f |xargs rm
also if you have GNU find,
find . -type f -exec rm {} +;
same as using xargs

find /home/personal/ -type f -name "*.txt*" -exec rm { } \;the command will delete the all *.txt files from /home/personal/ folder.

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |