Stumped! rm -r *.txt does not do it. Google foo has deserted me!
Cheers
Steve
Delete all files - *.txt from a directory and sub directorys
Forum rules
LMDE 2 has reached end of support as of 1-1-2019
LMDE 2 has reached end of support as of 1-1-2019
Delete all files - *.txt from a directory and sub directorys
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: Delete all files - *.txt from a directory and sub direct
Be careful with rm and its syntax but...
should do what you want. Validate your regex syntax before with:
Code: Select all
find (directory) -type f -name *.txt -exec rm -f {} \;
Code: Select all
find (directory) -type f -name (regex)
Re: Delete all files - *.txt from a directory and sub direct
Must be doing something wrong:
Any ideas?
Code: Select all
find /home/molly3/temp -type f -name *.txt -exec rm -f {} \;
find: paths must precede expression: 2.txt
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
Re: Delete all files - *.txt from a directory and sub direct
Maybe you have file names found containing spaces. Try
Code: Select all
find /home/molly3/temp -type f -name "*.txt" -exec rm -f {} \;
Re: Delete all files - *.txt from a directory and sub direct
The solution will give you trouble when there are files with space in their names. It is also better to use xargs rather than exec. To get round that problem use the following command :
Regards.
Code: Select all
find dirname -name "*.txt" -print0 | xargs -0 rm
Re: Delete all files - *.txt from a directory and sub direct
After this experience you can see why, under Linux, it is best not to have file names with spaces.
Use some thing like - or _ between words if you must have a space.
I use capitols for things like GrubLegacy.
Makes life easier if you go with what the file system wants.
Use some thing like - or _ between words if you must have a space.
I use capitols for things like GrubLegacy.
Makes life easier if you go with what the file system wants.
Re: Delete all files - *.txt from a directory and sub direct
True, but unfortunately I did not create the files