Post History
For each file named foo.xyz, you want to delete foo.xyz.part. It doesn't matter if foo.xyz.part exists, you can just attempt it and skip errors. You can get a list of all files with find etc. But ...
Answer
#2: Post edited
- For each file named `foo.xyz`, you want to delete `foo.xyz.part`. It doesn't matter if `foo.xyz.part` exists, you can just attempt it and skip errors.
- You can get a list of all files with `find` etc. But you don't want the ones with `.part`, so you use grep to take them out: `find | grep -v '\.part$'`. `$` means end of string and `\.` is because otherwise `.` means any character in regex.
- You can then attempt to [delete each one](https://linux.codidact.com/posts/288310#answer-288311): `find | grep -v '\.part$' | parallel rm {}`
If the file doesn't exist, Parallel will show you the error message, but it will still delete the ones that do exist. You can do a bunch of extra filtering with `comm`, but there's no need.
- For each file named `foo.xyz`, you want to delete `foo.xyz.part`. It doesn't matter if `foo.xyz.part` exists, you can just attempt it and skip errors.
- You can get a list of all files with `find` etc. But you don't want the ones with `.part`, so you use grep to take them out: `find | grep -v '\.part$'`. `$` means end of string and `\.` is because otherwise `.` means any character in regex.
- You can then attempt to [delete each one](https://linux.codidact.com/posts/288310#answer-288311): `find | grep -v '\.part$' | parallel rm {}`
- If the file doesn't exist, Parallel will show you the error message, but it will still delete the ones that do exist. You can do a bunch of extra filtering with `comm` to only attempt to delete those files which do exist, but there's no need in this case.
#1: Initial revision
For each file named `foo.xyz`, you want to delete `foo.xyz.part`. It doesn't matter if `foo.xyz.part` exists, you can just attempt it and skip errors. You can get a list of all files with `find` etc. But you don't want the ones with `.part`, so you use grep to take them out: `find | grep -v '\.part$'`. `$` means end of string and `\.` is because otherwise `.` means any character in regex. You can then attempt to [delete each one](https://linux.codidact.com/posts/288310#answer-288311): `find | grep -v '\.part$' | parallel rm {}` If the file doesn't exist, Parallel will show you the error message, but it will still delete the ones that do exist. You can do a bunch of extra filtering with `comm`, but there's no need.