-l 完成
This commit is contained in:
parent
5d59e49fb1
commit
bb1374aca3
1 changed files with 11 additions and 7 deletions
18
ls.rb
18
ls.rb
|
@ -39,29 +39,33 @@ def list_filenames
|
||||||
filenames = params['a'] ? Dir.glob('*', File::FNM_DOTMATCH) : Dir.glob('*')
|
filenames = params['a'] ? Dir.glob('*', File::FNM_DOTMATCH) : Dir.glob('*')
|
||||||
filenames = filenames.reverse if params['r']
|
filenames = filenames.reverse if params['r']
|
||||||
if params['l']
|
if params['l']
|
||||||
ownerinfo(filenames)
|
output(filenames)
|
||||||
exit
|
exit
|
||||||
else
|
else
|
||||||
filenames
|
filenames
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def ownerinfo(filenames)
|
def output(filenames)
|
||||||
file_blocks(filenames)
|
file_blocks(filenames)
|
||||||
filenames.each do |file|
|
filenames.each do |file|
|
||||||
file_stat = File::Stat.new(file)
|
file_stat = File::Stat.new(file)
|
||||||
print " #{TYPES[file_stat.ftype]}"
|
print TYPES[file_stat.ftype]
|
||||||
permission(file_stat)
|
permission(file_stat)
|
||||||
print " #{file_stat.nlink}"
|
printer(file_stat, filenames)
|
||||||
print " #{Etc.getpwuid(file_stat.uid).name}"
|
|
||||||
print " #{Etc.getgrgid(file_stat.gid).name}"
|
|
||||||
print " #{file_stat.size}".rjust(file_size(filenames))
|
|
||||||
timestamp(file_stat)
|
timestamp(file_stat)
|
||||||
symbolic(file)
|
symbolic(file)
|
||||||
puts
|
puts
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def printer(file_stat, filenames)
|
||||||
|
print " #{file_stat.nlink}"
|
||||||
|
print " #{Etc.getpwuid(file_stat.uid).name}"
|
||||||
|
print " #{Etc.getgrgid(file_stat.gid).name}"
|
||||||
|
print " #{file_stat.size}".rjust(file_size(filenames))
|
||||||
|
end
|
||||||
|
|
||||||
def symbolic(filenames)
|
def symbolic(filenames)
|
||||||
if File.lstat(filenames).symlink?
|
if File.lstat(filenames).symlink?
|
||||||
print " #{filenames} -> #{File.readlink(filenames)}"
|
print " #{filenames} -> #{File.readlink(filenames)}"
|
||||||
|
|
Loading…
Reference in a new issue