While browsing the internet for Ubuntu articles, I came across this command:
sudo dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
The author said that this is a single line command which will delete all the previous versions of Linux, leaving only the current one!
I'm actually looking for such a command, but I'm not so sure on how safe this is. I'd like to know:
- Whether it is safe to execute this command?
- How does this command work? i.e. explanation of small parts of such a big command
- If this command serves some different purpose, then what would be the correct command to achieve what the author claims it to do?
I become very confused and frustrated when I try to infer out all by myself. How does this command work for it contains numerous
^ characters which are hard to Google for.
I am looking for a step by step translation & explanation for this command which I was unable to find across the internet!