| View previous topic :: View next topic |
| Author |
Message |
Ashii n00b

Joined: 25 Jan 2012 Posts: 2
|
Posted: Wed Jan 25, 2012 8:48 pm Post subject: [Script] pdf-cache.sh - stores symlinks of your pdf in .pdf |
|
|
| Quote: | | http://pastebin.com/jW2XSP42 |
| Code: | #!/bin/bash
# creates
# ~/.pdf <-- your pdf symlinks are here
# ~/.pdfcache/cache <-- list of pdf files
# search_dir = <dir to scan for pdf>
# note; I made it delete the directory, before the scan, so it only stores one search
# TODO: for later version
# 21:24:10 <apus> perhaps it would be a good idea to skip hidden directories and files as well ... don't think they should be cached: \( ! -regex '.*/\..*' \)
search_dir=$HOME
echo "Looking for pdf in: $search_dir"
if [ -d ~/.pdfcache ] ; then
rm -Rf ~/.pdf
find $search_dir -iname "*.pdf" > ~/.pdfcache/cache
else
mkdir ~/.pdf
mkdir ~/.pdfcache
# ignores the directory .pdf under $HOME
find $search_dir -name ".pdf" -prune -o -type f -print | grep .pdf$
fi
mkdir ~/.pdf
while read -r line; do ln -s "$line" "/home/$USER/.pdf/${line##*/}"
done < $HOME/.pdfcache/cache
|
I was missing a bookshelf for all my pdf files, so I symlinked them all to ~/.pdf now its all pretty and sorted. |
|
| Back to top |
|
 |
Ashii n00b

Joined: 25 Jan 2012 Posts: 2
|
Posted: Wed Jan 25, 2012 8:57 pm Post subject: cleaned up version |
|
|
| Quote: | | http://pastebin.com/3ezWj4aX |
| Code: | #!/bin/bash
# creates ~/.pdf
# search_dir = <dir to scan for pdf>
# note: the symlinks in .pdf are removed at each run
search_dir="$HOME"
echo "Looking for pdf in: $search_dir"
if [[ ! -d "$HOME"/.pdf ]] ; then
if ! mkdir "$HOME"/.pdf; then
echo "Aborting. Couldn't create directory .pdf."
exit 1
fi
else
# clean up directory .pdf[/quote]
rm -rf "$HOME"/.pdf/*
fi
while IFS= read -rd '' line; do
ln -s "$line" "$HOME/.pdf/${line##*/}"
done < <(find "$search_dir" -regex '.*/\..*' -prune -o -type f -iname '*.pdf' -print0)
|
credit to apus |
|
| Back to top |
|
 |
frostschutz Advocate


Joined: 22 Feb 2005 Posts: 2194 Location: Germany
|
Posted: Wed Jan 25, 2012 9:01 pm Post subject: |
|
|
Interesting.
| Code: | mkdir ~/.pdf/
rm ~/.pdf/*
find ~ -type f -name "*.pdf" -print0 | xargs -0 -I {} -n 1 ln -bs {} ~/.pdf/ |
|
|
| Back to top |
|
 |
avx Veteran


Joined: 21 Jun 2004 Posts: 1831
|
Posted: Wed Jan 25, 2012 11:35 pm Post subject: |
|
|
| frostschutz wrote: | Interesting.
| Code: | mkdir ~/.pdf/
rm ~/.pdf/*
find ~ -type f -name "*.pdf" -print0 | xargs -0 -I {} -n 1 ln -bs {} ~/.pdf/ |
| Why xargs and not directly `find`'s "-exec"? _________________ Want to thank me for something? Send me a nice postcard(ask per pm for my address), thank you! |
|
| Back to top |
|
 |
frostschutz Advocate


Joined: 22 Feb 2005 Posts: 2194 Location: Germany
|
Posted: Thu Jan 26, 2012 6:56 pm Post subject: |
|
|
No reason. I just somehow got stuck on xargs because I don't always use find as a data source for filename lists.
Here's to without xargs:
| Code: | | find ~ -type f -name "*.pdf" -exec ln -bs {} ~/.pdf/ \; |
|
|
| Back to top |
|
 |
|