Well it’s really very simple with this one line:
grep -RoPish "ppa.launchpad.net/[^/]+/[^/ ]+" /etc/apt |
sort -u | sed -r 's/\.[^/]+\//:/'
And that will pump out a nice list of
It took several iterations to get that command down to something that short (it was much longer originally) but the legibility of it has suffered so I’m going to take some time to explain what it’s doing, in a hope to inspire and improve your Bash-Fu:
Search files in /etc/apt/
-o (only output what you match)
-P (using Perl regex syntax)
-i (ignoring case)
-s (suppress any error messages)
-h (don't output the filename before the matched output)
Sort that and weed out any duplicates (the -u means unique)
Then replace the first . to the first / with a :
If you want to back that up to a file, stick
> ~/ppa-backup.txt on the end of the command and the output will be forced into that file.
Restoring from a backup
If you want to reapply your PPAs to another install of Ubuntu --be that a fresh installation or just another computer-- you can just run:
<~/ppa-backup.txt xargs -I % sudo add-apt-repository %
And this translates out as:
Pipe the content of ~/ppa-backup.txt to xargs
-I % (substitute any mention of % with the current output)
Run add-apt-repository as root, using the substitution from %
I hope you learned something new about Bash reading this article. I certainly did writing it. Perhaps you can improve on it! I was considering using
gawk but that’s not installed by default.