Last active
December 20, 2015 07:09
-
-
Save VanTanev/6091505 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# List all opened files using only the /proc fs. | |
main() { | |
pids | file_descriptor_folder | xargs ls -l | remove_ls_total_lines | remove_ls_file_attributes | remove_non_files | less | |
} | |
pids() { | |
# we try all pids from 1 to the pid max and echo out the valid ones | |
for P in $(seq 1 $(cat /proc/sys/kernel/pid_max)); do | |
[ -d "/proc/$P" ] || continue | |
echo $P | |
done | |
} | |
file_descriptor_folder() { | |
# we build the folder name for the file descriptors for each pid | |
sed -r 's/(.*)/\/proc\/\1\/fd/' | |
} | |
remove_ls_total_lines() { | |
# remove file count from ls' result | |
grep -v 'total' | |
} | |
remove_ls_file_attributes() { | |
# remove information about the link attributes and leave only the dereferenced link path | |
sed -r 's/^.*->/->/' | |
} | |
remove_non_files() { | |
# remove everything that is not an actual file - stuff like sockets and so on | |
grep -v -e '-> \w' | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment