The process_name.sh
script, located in the utils
folder, is designed to identify the process names and their corresponding PIDs that are accessing files within a specified directory. This is particularly useful for enhancing the clean.sh
script by helping you determine the correct process names for new paths added to the DEF_PATHS_TO_CLEAN
array. By identifying the processes that are actively using specific directories, you can accurately configure clean.sh
to manage cache and temporary files for a wider range of applications.
- Identifies processes accessing files in a specified directory.
- Can use a default directory or a user-provided directory.
- Outputs the PID and command name of the processes.
Go to the script location folder (42cleaner/utils by default).
- If a path is provided as an argument, the script will use that directory.
- If no path is provided, the script will use the default directory specified within the script.
-
To use the default directory:
./process_name.sh
-
To specify a custom directory directly using the command:
./process_name.sh /path/to/custom/directory
- Running applications:
- To successfully identify an specific process name, the application which process name you want to know, must be running. If the application is closed, the script is unlikely to find any processes accessing the specified directory.
Choosing the right directory to monitor significantly impacts the likelihood of correctly identifying the process name. Here's why:
Application Paths:
- Good Path (high chance of success):
$HOME/.config/Code/
or$HOME/snap/slack/
- This paths include the main configuration directory for the application, which is more likely to be accessed by the main process of the application.
- Bad Path (low chance of success):
$HOME/.config/Code/Shared Dictionary/cache
or$HOME/snap/slack/149/.config/Slack/Cache
- This are more specific subdirectories, often used for temporary cache files. The main application process may not frequently access these files directly.
To improve the chances of successfully identifying process names for applications, use paths such as these, depending on their directory locations (.config | .var/app | snap):
-
Code:
- .config:
$HOME/.config/Code/
- snap:
$HOME/snap/code/
- .config:
-
Google Chrome:
- .config:
$HOME/.config/google-chrome/
- .var/app:
$HOME/.var/app/com.google.Chrome/
- .config:
-
Firefox:
- .config:
$HOME/.mozilla/firefox/
- snap:
$HOME/snap/firefox/
- .config:
-
Brave Browser:
- .config:
$HOME/.config/BraveSoftware/Brave-Browser/
- .config:
-
Discord:
- .config:
$HOME/.config/discord/
- .config:
-
Spotify:
- .config:
$HOME/.config/spotify/
- snap:
$HOME/snap/spotify/
- .config:
-
VLC Media Player:
- .config:
$HOME/.config/vlc/
- .var/app:
$HOME/.var/app/org.videolan.VLC/
- .config:
-
Gnome Terminal:
- .config:
$HOME/.config/gnome-terminal/
- .config:
-
JetBrains:
- .config:
$HOME/.config/JetBrains/
- .config:
-
Zoom:
- .config:
$HOME/.config/zoom/
- snap:
$HOME/snap/zoom/
- .config:
-
Skype for Linux:
- .config:
$HOME/.config/skypeforlinux/
- .config:
-
Slack:
- .config:
$HOME/.config/Slack/
- snap:
$HOME/snap/slack/
- .config:
-
Telegram Desktop:
- .config:
$HOME/.config/TelegramDesktop/
- .config:
-
Microsoft Teams:
- .config:
$HOME/.config/teams/
- .config:
-
Obsidian:
- snap:
$HOME/snap/obsidian/
- snap:
-
GitKraken:
- snap:
$HOME/snap/gitkraken/
- snap:
-
Chromium:
- snap:
$HOME/snap/chromium/
- snap:
-
GIMP:
- .var/app:
$HOME/.var/app/org.gimp.GIMP/
- .var/app:
-
LibreOffice:
- .var/app:
$HOME/.var/app/org.libreoffice.LibreOffice/
- .var/app:
-
FileZilla:
- .var/app:
$HOME/.var/app/org.filezillaproject.Filezilla/
- .var/app:
# 1. Default Directory: Sets a default directory to use.
directory="$HOME/.config/VSCodium/"
# 2. Custom Directory: Allows for a custom directory to be specified as an argument.
if [ $# -gt 0 ]; then
directory="$1"
fi
# 3. Iterating Over Processes: Iterates over all PIDs in the `/proc` directory.
for pid in $(ls /proc | grep -E '^[0-9]+$'); do
# 4. Checking File Descriptors: Checks if any file descriptor of the process points to the specified directory.
if ls /proc/$pid/fd 2>/dev/null | xargs -I {} readlink -f /proc/$pid/fd/{} 2>/dev/null | grep -q "$directory"; then
# 5. Retrieving Command Name: Retrieves the command name of the process.
cmd=$(ps -p $pid -o comm=)
# 6. Printing the Results: Prints the PID and command name.
echo "$pid $cmd"
fi
done
The process_name.sh
script is a useful tool for identifying processes accessing a specific directory. By choosing the appropriate paths and ensuring the target application is running, users can maximize the effectiveness of this script. Use broader application paths rather than specific cache directories to increase the chances of accurately identifying the process names.