Useful CLI tools (bash) for Arch Linux administration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
652 B

6 years ago
  1. #!/bin/bash
  2. ###########################################################
  3. # Delete current temporary files
  4. #All tmp files currently being used
  5. TMP_USED=$(lsof +D /tmp/ | awk '{print $9," "}' | sort -u | tail -n+3 | sed 's/[ \t]*$//')
  6. #All tmp files
  7. TMP_ALL=$(find /tmp/ -type s -print -o -type f -print | sort -u | sed 's/[ \t]*$//')
  8. #Get all tmp files/symlinks/etc which are not being used at the moment
  9. # Exclude /tmp/.X11-unix/X0 from the list
  10. #
  11. TMP_NOTUSED=$(comm -23 <(echo "$TMP_ALL") <(echo "$TMP_USED") | sed 's/\/tmp\/.X11-unix\/X0//g; /^\s*$/d')
  12. echo "$TMP_NOTUSED" | while read line; do echo "Deleting file $line" && sudo rm $line ; done