How to Use the 'pm' Command on Android Devices (with Examples)
- Android
- December 17, 2024
The ‘pm’ command is a powerful tool utilized within the Android Debug Bridge (ADB) to manage applications installed on an Android device. This command provides the ability to list, examine, and control various aspects of apps. It is particularly helpful for developers, IT professionals, and advanced users who need to manage applications on Android devices through a command-line interface. Below, we explore various use cases of the ‘pm’ command with examples to demonstrate its utility and versatility.
Use case 1: List All Installed Apps
Code:
pm list packages
Motivation:
Listing all installed apps on an Android device can be incredibly useful for those wanting a comprehensive overview of the applications that are running on a device. This is particularly valuable for developers who need to understand what apps are available, for IT administrators auditing devices for compliance, or for a user curious about what their device holds.
Explanation:
pm
: This refers to the package manager tool.list
: This sub-command is used to initiate a listing action.packages
: This argument specifies that the listing should target installed application packages.
Example Output:
package:com.android.chrome
package:com.whatsapp
package:com.facebook.katana
package:com.google.android.youtube
In this output, each line represents an installed application on the device prefixed by the word “package:” followed by the package identifier for the app.
Use case 2: List All Installed System Apps
Code:
pm list packages -s
Motivation:
Listing all installed system apps can be crucial for anyone scrutinizing the pre-installed software that comes with Android devices. System apps are those that are considered essential by the device manufacturer and Android itself, typically responsible for core functions of the device. IT administrators and developers might want to ensure that only necessary system apps are installed, particularly in environments where security or device performance is a concern.
Explanation:
-s
: This option filters the output to only include system apps. System apps are usually installed in the device’s system partition and are critical for basic functionality.
Example Output:
package:com.android.systemui
package:com.android.settings
package:com.android.phone
package:com.android.contacts
Each output line describes a system app that ships with Android devices, central to the OS’s functioning.
Use case 3: List All Installed 3rd-Party Apps
Code:
pm list packages -3
Motivation:
Identifying all installed third-party apps is helpful for those who want to manage apps that did not come pre-installed on the device. Whether it’s freeing up device space, evaluating potential security concerns, or deciding which apps to keep or uninstall, analyzing third-party apps is an essential task.
Explanation:
-3
: This argument filters the output to only include third-party apps. These are apps that the user has installed, separate from the system and core Android applications.
Example Output:
package:com.spotify.music
package:com.netflix.mediaclient
package:com.dropbox.android
package:com.skype.raider
Here we see third-party applications that have been added by the end user after purchasing the device.
Use case 4: List Apps Matching Specific Keywords
Code:
pm list packages keyword1 keyword2 ...
Motivation:
The ability to search for apps using specific keywords is beneficial when trying to locate a group of applications that share common characteristics or when troubleshooting specific apps. This can be useful for developers testing parts of apps or for users managing their installations efficiently.
Explanation:
keyword1
,keyword2
, etc.: These are placeholders for the user-defined keywords. The command returns only those apps whose package names include the specified keywords.
Example Output (for keywords ‘google’, ‘chrome’):
package:com.google.android.gms
package:com.google.android.googlequicksearchbox
package:com.android.chrome
The output highlights apps that relate specifically to “google” and “chrome”, making it easier to manage or audit these apps.
Use case 5: Display a Path of the APK of a Specific App
Code:
pm path app
Motivation:
Knowing the APK path of an application is instrumental for developers and power users who want to perform manual operations on the APK file, such as backups, transfers, or direct modifications. These paths are necessary for any low-level interactions with the application package.
Explanation:
app
: This is the actual package name or identifier of the app whose APK path you wish to find.
Example Output:
package:/data/app/com.example.myapp-1/base.apk
The result shows the full path to the APK file for the specified app package, which is typically stored in the /data/app
directory for most user-installed apps.
Conclusion:
The ‘pm’ command in Android is a versatile tool that offers valuable insights and control over the apps installed on a device. Whether listing all apps, filtering system or third-party apps, searching with specific keywords, or locating APK paths, the ‘pm’ command is essential for anyone looking to manage their Android device effectively. By becoming proficient with these use cases, users can diagnose issues, enhance security, and optimize the app ecosystem on their devices.