⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 01 - checking your access to a file.rb

📁 O Reilly Ruby Cookbook source code
💻 RB
字号:
File.readable?('/bin/ls')                # => trueFile.readable?('/etc/passwd-')           # => falsefilename = 'test_file'File.open(filename, 'w') {}File.writable?(filename)                 # => trueFile.writable?('/bin/ls')                # => falseFile.executable?('/bin/ls')              # => trueFile.executable?(filename)               # => false#---File.owned? 'test_file'                  # => trueFile.grpowned? 'test_file'               # => trueFile.owned? '/bin/ls'                    # => false#---File.lstat('test_file').mode & 0777       # Keep only the permission bits.# => 420                                  # That is, 0644 octal.#---def what_can_i_do?  sys = Process::Sys	  puts "UID=#{sys.getuid}, GID=#{sys.getgid}"  puts "Effective UID=#{sys.geteuid}, Effective GID=#{sys.getegid}"  file = '/bin/ls'  can_do = [:readable?, :writable?, :executable?].inject([]) do |arr, method|    arr << method if File.send(method, file); arr  end  puts "To you, #{file} is: #{can_do.join(', ')}"end#---what_can_i_do?# UID=0, GID=0# Effective UID=0, Effective GID=0# To you, /bin/ls is: readable?, writable?, executable?Process.uid = 1000what_can_i_do?# UID=0, GID=0# Effective UID=1000, Effective GID=0# To you, /bin/ls is: readable?, executable?#---

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -