Ubuntu – Apt-get install: is there a command to work on a batch of packages


I notice that whenever I use the command sudo apt-get -y autoremove quite a number of packages that I need is on the list to be removed.

After going through some of the posts on this forum, I have the impression that the command removes packages that have been automatically installed. To prevent autoremoval of a package, I will have to mark it as

sudo apt-get install <package-name>

Suppose I have 120 packages earmarked for autoremoval.

How do I mark them as manually installed with a single command?

Best Answer

Store all the packages which are ready for autoremoval in a text file and then run apt-mark manual command on those packages to mark it as manually installed.

for i in $(cat ~/Desktop/package.txt); do sudo apt-mark manual $i ; done

~/Desktop/package.txt - Contains the package names which are going to set as manually installed.