Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. compgen -c
  2.  
  3. compgen -a # will list all the aliases you could run.
  4. compgen -b # will list all the built-ins you could run.
  5. compgen -k # will list all the keywords you could run.
  6. compgen -A function # will list all the functions you could run.
  7. compgen -A function -abck # will list all the above in one go.
  8.  
  9. whence -pm '*'
  10.  
  11. print -rl -- $commands
  12.  
  13. print -rl -- ${(ko)commands}
  14.  
  15. IFS=':';for i in $PATH; do test -d "$i" && find "$i" -maxdepth 1 -executable -type f -exec basename {} ;; done
  16.  
  17. find ${PATH//:/ } -maxdepth 1 -executable
  18.  
  19. python -c 'import os;import sys;output = lambda(x) : sys.stdout.write(x + "n"); paths = os.environ["PATH"].split(":") ; listdir = lambda(p) : os.listdir(p) if os.path.isdir(p) else [ ] ; isfile = lambda(x) : True if os.path.isfile(os.path.join(x[0],x[1])) else False ; isexe = lambda(x) : True if os.access(os.path.join(x[0],x[1]), os.X_OK) else False ; map(output,[ os.path.join(p,f) for p in paths for f in listdir(p) if isfile((p,f)) and isexe((p,f)) ])'
  20.  
  21. import os
  22. import sys
  23.  
  24. # This is just to have a function to output something on the screen.
  25. # I'm using python 2.7 in which 'print' is not a function and cannot
  26. # be used in the 'map' function.
  27. output = lambda(x) : sys.stdout.write(x + "n")
  28.  
  29. # Get a list of the components in the PATH environment variable. Will
  30. # abort the program is PATH doesn't exist
  31. paths = os.environ["PATH"].split(":")
  32.  
  33. # os.listdir raises an error is something is not a path so I'm creating
  34. # a small function that only executes it if 'p' is a directory
  35. listdir = lambda(p) : os.listdir(p) if os.path.isdir(p) else [ ]
  36.  
  37. # Checks if the path specified by x[0] and x[1] is a file
  38. isfile = lambda(x) : True if os.path.isfile(os.path.join(x[0],x[1])) else False
  39.  
  40. # Checks if the path specified by x[0] and x[1] has the executable flag set
  41. isexe = lambda(x) : True if os.access(os.path.join(x[0],x[1]), os.X_OK) else False
  42.  
  43. # Here, I'm using a list comprehension to build a list of all executable files
  44. # in the PATH, and abusing the map function to write every name in the resulting
  45. # list to the screen.
  46. map(output, [ os.path.join(p,f) for p in paths for f in listdir(p) if isfile((p,f)) and isexe((p,f)) ])
  47.  
  48. { set -f; IFS=:; for d in $PATH; do set +f; [ -n "$d" ] || d=.; for f in "$d"/.[!.]* "$d"/..?* "$d"/*; do [ -f "$f" ] && [ -x "$f" ] && printf '%sn' "${x##*/}"; done; done; } | sort
  49.  
  50. { IFS=:; for d in $PATH; do for f in $d/*; do [ -f $f ] && [ -x $f ] && echo ${x##*/}; done; done; } | sort
  51.  
  52. { IFS=:; set -f; find -H $PATH -prune -type f -perm -100 -print; } | sed 's!.*/!!' | sort
  53.  
  54. { IFS=:; ls -H $PATH; } | sort
  55.  
  56. #!/usr/bin/env python
  57. import os
  58. from os.path import expanduser, isdir, join, pathsep
  59.  
  60. def list_executables():
  61. paths = os.environ["PATH"].split(pathsep)
  62. executables = []
  63. for path in filter(isdir, paths):
  64. for file_ in os.listdir(path):
  65. if os.access(join(path, file_), os.X_OK):
  66. executables.append(file_)
  67. return executables
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement