Ruby/File Directory/chmod
Материал из Wiki.crossplatform.ru
(Различия между версиями)
ViGOur (Обсуждение | вклад) м (1 версия: Импорт выборки материалов по Ruby) |
Текущая версия на 17:57, 13 сентября 2010
Содержание |
Change file mode to 0644
file = File.new( "books.txt", "w" ).chmod( 0644 ) system "ls -l books.txt" File.delete( "books.txt" )
Change mode and use system command to check
file = File.new( "books.txt", "w" ).chmod( 0755 ) system "ls -l books.txt"
Changing File Modes and Owner
To change the mode (permissions or access list) of a file, use the chmod method with a mask file = File.new( "books.txt", "w" ) file.chmod( 0755 )
Changing the Permissions on a File
class File U_R = 0400 U_W = 0200 U_X = 0100 G_R = 0040 G_W = 0020 G_X = 0010 O_R = 0004 O_W = 0002 O_X = 0001 A_R = 0444 A_W = 0222 A_X = 0111 end open("my_file", "w") {} File.chmod(File::U_R | File::U_W | File::G_R | File::O_R, "my_file") File.chmod(File::A_R | File::U_W, "my_file") File.chmod(0644, "my_file") # Bitmap: 110001001
Give everyone access to everything
class File U_R = 0400 U_W = 0200 U_X = 0100 G_R = 0040 G_W = 0020 G_X = 0010 O_R = 0004 O_W = 0002 O_X = 0001 A_R = 0444 A_W = 0222 A_X = 0111 end new_permission = File.lstat("my_file").mode | File::A_R | File::A_W | File::A_X File.chmod(new_permission, "my_file")
Masks for chmod
Mask Description 0700 rwx mask for owner 0400 r for owner 0200 w for owner 0100 x for owner 0070 rwx mask for group 0040 r for group 0020 w for group 0010 x for group 0007 rwx mask for other 0004 r for other 0002 w for other 0001 x for other 4000 Set user ID on execution 2000 Set group ID on execution 1000 Save swapped text, even after use
Take away the world"s read access.
class File U_R = 0400 U_W = 0200 U_X = 0100 G_R = 0040 G_W = 0020 G_X = 0010 O_R = 0004 O_W = 0002 O_X = 0001 A_R = 0444 A_W = 0222 A_X = 0111 end new_permission = File.lstat("my_file").mode ^ File::O_R File.chmod(new_permission, "my_file")
Take away the world"s write and execute access
class File U_R = 0400 U_W = 0200 U_X = 0100 G_R = 0040 G_W = 0020 G_X = 0010 O_R = 0004 O_W = 0002 O_X = 0001 A_R = 0444 A_W = 0222 A_X = 0111 end new_permission = File.lstat("my_file").mode ^ (File::O_W | File::O_X) File.chmod(new_permission, "my_file")