I'm trying to remove some packages that I installed a long time ago but don't need any more, when I type dpkg --get-selection
I get a list of all the packages installed in my system, but I need to sort those packages, like this "the packages needed by the system all together", "packages that can be removed all together".
Is there any command that can sort them for me ??
No, there is no such things as "the packages needed by the system all together" since the system has no way to determine which packages are required. Because it is you who directs the requirement.
However, some packages might be installed together with other packages and if you removed those, the 'installed together' packages might not get removed. In this case, you can run this command to remove those unnecessary packages.
If you want to find packages that you don't use anymore, this should be done manually, since the system has no way to know if you still need them or not. Now for packages that were installed along something you needed, but you no longer needs and/or removed, you can try Anwar Shah answer or use deborphan:
This will generate a list of no longer needed dependencies that you can uninstall/remove.
You can also install synaptic which will provide you with more GUI information about installed and available packages. Run: