Quicky script, adapt as you see fit:
#!/usr/bin/env bash
find /project/ -name '*.pdf' -print0 | while read -d $'\0' i; do
if [ ! -e "${i/%.pdf/-project.zip}" ]; then
echo "${i/%.pdf/-project.zip} doesn't exist!"
fi
done
exit 0
-d $'\0'
sets the delimiter for read
to nullbyte, while -print0
is the equivalent for find
, so this should be bulletproof against files with spaces and newlines in their names (obviously irrelevant in this case, but useful to know in general). ${i/%.pdf/-project.zip}
replaces the .pdf
at the end of the variable $i
with -project.zip
. Other than that, this is all standard shell scripting stuff.
If you wanted to shorten it even more, you could also use
[ -e "${i/%.pdf/-project.zip}" ] || echo "${i/%.pdf/-project.zip} doesn't exist!"
...instead of the if
statement. I think that if
is easier to work with if you're using more than a single, short line (you can get around this by using a function, but at that point you aren't getting any psace saving vs. using the if
).
Assuming you have bash 4+ (you probably do; you can check with bash --version
), you can use the globstar option instead of find
:
#!/usr/bin/env bash
shopt -s globstar
for f in /project/**/*.pdf; do
if [ ! -e "${f/%.pdf/-project.zip}" ]; then
echo "${f/%.pdf/-project.zip} doesn't exist!"
fi
done
exit 0
This has the advantage of being pure bash, so it should be faster (only noticeably so with at least hundreds of files, though).
Is it a single folder
/project/
, or are subdirectories involved? – Daniel Beck – 2013-05-24T19:13:41.083subdirectories included.. – FlyingCat – 2013-05-24T19:15:28.037
is
test.pdf
andtest-project.zip
(and so on) always in the same directory? – evilsoup – 2013-05-24T19:20:55.330yes they are all in the same dir – FlyingCat – 2013-05-24T19:21:23.217