Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

71%
+3 −0
Q&A Is this a robust way to distinguish explicitly installed packages from those pulled in as dependencies?

When exploring the commands from this answer to my previous question, I found that the ist of packages includes a lot that were automatically installed due to dependencies. Obviously I'm interested...

1 answer  ·  posted 3y ago by celtschk‭  ·  last activity 3y ago by Peter Taylor‭

#1: Initial revision by user avatar celtschk‭ · 2021-05-22T12:32:55Z (over 3 years ago)
Is this a robust way to distinguish explicitly installed packages from those pulled in as dependencies?
When exploring the commands from [this answer to my previous question,][1] I found that the ist of packages includes a lot that were automatically installed due to dependencies. Obviously I'm interested only in those packages that I explicitly requested (the others would be pulled in automatically again, if needed).

Since I didn't figure out a way to explicitly query whether a package was installed explicitly or as dependency, I figured the best way would be to determine whether a package depends on another installed package.

This information turns out to be available with `apt-cache rdepends --installed $packagename` but I still need to extract the information I need from the output.

Unfortunately the line "Reverse Depends:" is always output, even if there are no reverse dependencies. However I noticed that the dependency lines all start with a space, while the others don't. Therefore my idea is to use the following:
```
apt-cache rdepends --installed $packagename | grep -q "^ "
```
If there are no dependencies, the exit status of grep will be 1, otherwise it will be 0.

My question now is: Is this a robust way to test for this? If not, what are better ways to achieve what I want?


 [1]: https://linux.codidact.com/posts/281848#answer-281850