-l
This commit is contained in:
parent
5f65b19cc6
commit
03884289e3
1 changed files with 14 additions and 4 deletions
18
ls.rb
18
ls.rb
|
@ -26,6 +26,7 @@ def list_filenames
|
||||||
end
|
end
|
||||||
|
|
||||||
def ownerinfo(filenames)
|
def ownerinfo(filenames)
|
||||||
|
file_blocks(filenames)
|
||||||
filenames.each do |file|
|
filenames.each do |file|
|
||||||
file_stat = File::Stat.new(file)
|
file_stat = File::Stat.new(file)
|
||||||
file_type(file_stat)
|
file_type(file_stat)
|
||||||
|
@ -40,11 +41,11 @@ def ownerinfo(filenames)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def symbolic(file)
|
def symbolic(filenames)
|
||||||
if File.lstat(file).symlink?
|
if File.lstat(filenames).symlink?
|
||||||
print " #{file} -> #{File.readlink(file)}"
|
print " #{filenames} -> #{File.readlink(filenames)}"
|
||||||
else
|
else
|
||||||
print " #{file}"
|
print " #{filenames}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -71,6 +72,8 @@ def file_type(file_stat)
|
||||||
print 'd'
|
print 'd'
|
||||||
when 'characterSpecial'
|
when 'characterSpecial'
|
||||||
print 'c'
|
print 'c'
|
||||||
|
when 'blockSpecial'
|
||||||
|
print 'b'
|
||||||
when 'fifo'
|
when 'fifo'
|
||||||
print 'p'
|
print 'p'
|
||||||
when 'link'
|
when 'link'
|
||||||
|
@ -88,6 +91,13 @@ def timestamp(file_stat)
|
||||||
print file_stat.mtime.strftime('%_m %_d %H:%M')
|
print file_stat.mtime.strftime('%_m %_d %H:%M')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def file_blocks(filenames)
|
||||||
|
blocks = filenames.map do |file|
|
||||||
|
File::Stat.new(file).blocks
|
||||||
|
end
|
||||||
|
puts "total #{blocks.sum}"
|
||||||
|
end
|
||||||
|
|
||||||
def slice_filenames(listed_filenames)
|
def slice_filenames(listed_filenames)
|
||||||
columns_size = listed_filenames.size.ceildiv(COLUMNS)
|
columns_size = listed_filenames.size.ceildiv(COLUMNS)
|
||||||
listed_filenames.each_slice(columns_size).to_a
|
listed_filenames.each_slice(columns_size).to_a
|
||||||
|
|
Loading…
Reference in a new issue