UNIX:ファイルを更新する
ガミガミ
UNIXのファイルを更新することは、システムを運用している方なら毎日のように行っていると思います。
ところが、ファイルを更新する「やりかた」は人によってまちまちで、あまり「こうしなさい」とガミガミいわれていないようです。
私の周りのSEの方々で、一番多いのは「vi コマンドでファイルを直接更新する」方法です。
しかし、この方法には問題があると思っています。私は、周りの人には毎年のように「○○のようにしなさい」と言っています。
可変長ファイルの更新
UNIXのviコマンドなどで編集するファイルは通常、可変長レコードのテキストファイルです。1行を1つの1レコードと考えると、各行の長さはまちまちで決まっていません。
空白や改行コードなどで、自由にレイアウトを決めることができる、便利なファイルですが、データ更新には全然向いていません。
途中のデータを1バイト削除することは、残りのデータ部分をすべて1バイト前に複写することになり、逆に1バイト挿入する場合はその逆に1バイト後に複写する必要があります。
結局、データを更新するということは、ごっそり新しいファイルを作成することと等しい結果になります。
元のデータ
0 1 2 3 4 5 6 7 8 9
+--+--+--+--+--+--+--+--+--+--+
|# |t |e |s |t |f |i |l |e |LF|
+--+--+--+--+--+--+--+--+--+--+
1バイトを削除したデータ
0 1 2 3 4 5 6 7 8
+--+--+--+--+--+--+--+--+--+
|t |e |s |t |f |i |l |e |LF|
+--+--+--+--+--+--+--+--+--+
ファイルの更新
私は必ず、プログラムが参照するようなUNIXファイルの更新を、次のように行うように推奨しています。
- ファイルの存在するディレクトリに2つのファイルを作成する。
- 1つはバックアップ用のファイル
- もう1つは更新用のファイル
- 更新用のファイルを vi でも emacs でも適当なエディタで更新する。
- 元のファイルの owner/group属性、パーミッションが同じことを確認する。
- 更新ファイルを mv コマンドで入れ替える。
- (同ファイルを参照しているプログラムを再起動する。起動のたびに読み込むようなプログラムなら次回起動から変更した内容が有効になる)
更新するファイルを /etc/hosts とすると、次のようなコマンド処理になります。
# cd /etc
# SUFFIX=`date +'%Y%m%d'`
# cp -p hosts hosts.$SUFFIX.new
# cp -p hosts hosts.$SUFFIX.old
# vi hosts.$SUFFIX.new ←このファイルを更新
# ls -l hosts hosts.$SUFFIX.*
# (rm hosts) ← この処理を行ってはなりません!!
# 行った場合は、次のmvを行うまでの時間、
ファイルが存在しない空白の時間帯が
発生してしまいます。
# mv hosts.$SUFFIX.new hosts ← リネーム処理
なぜ、こんな更新をするのか
viコマンドで直接ファイルを更新しないで、わざわざこんな更新を行う理由は次のとおりです。
- viコマンドで一度ファイルを更新(write)してしまえば、ファイルのinode番号は変わってしまいます。後戻りはできません。
- 更新したファイルの inode番号は変わります。
- ファイルが存在しない時間はありません。リネーム(rename)処理で「旧ファイルの削除」と「ファイル名の変更」はOS内部で一気に行います。
- バックアップが存在します。
Linuxに付属する vi コマンドには、これよりもっと高度な機能が実装されており、わざわざこんな更新を行う必要はないのかもしれません。
ただ、ファイルの更新がどのように行われ、プログラムはどのようにデータにアクセスするのかを十分に理解した上で、毎日の運用業務を実践していかなければならないでしょうね。
| 固定リンク
トラックバック
この記事のトラックバックURL:
http://app.f.cocolog-nifty.com/t/trackback/58358/1727424
この記事へのトラックバック一覧です: UNIX:ファイルを更新する:
» mother fuckimg son []
xxx incest family fucking incest family fucking free incest p... [続きを読む]
受信: 2006年11月 2日 (木) 06:31
» generic cialis []
cialis cialis online cheap cialis [続きを読む]
受信: 2006年11月 2日 (木) 13:24
» free interracial movies []
black and white sketches black dick white pussy interra... [続きを読む]
受信: 2006年11月 2日 (木) 22:04
» bushy beavers []
the angry beavers uncut men gallery uncut fore... [続きを読む]
受信: 2006年11月 3日 (金) 10:40
» giant dildo []
sex toys giant dildos dil... [続きを読む]
受信: 2006年11月 3日 (金) 15:53
» buy levitra online []
levitra levitra online levitra prescriptions [続きを読む]
受信: 2006年11月 3日 (金) 21:24
» cheap levitra []
levitra online levitra levitra prescriptions [続きを読む]
受信: 2006年11月 4日 (土) 02:14
» military studs hunks []
uncut hunks galleries gay boys in boxers dorm hunks [続きを読む]
受信: 2006年11月 4日 (土) 07:11
» purchase viagra online []
viagra viagra alternatives discount drug viagr... [続きを読む]
受信: 2006年11月 4日 (土) 18:03
» large cigar humidor []
massive clits massive mellons abnormally large nipples [続きを読む]
受信: 2006年11月 5日 (日) 01:50
» viagra discount online []
alternatives to viagra viagra cream viagra oral jelly [続きを読む]
受信: 2006年11月 5日 (日) 08:33
» beyonce knowles butt []
anal bleaching big booty hoe booty shaking girls [続きを読む]
受信: 2006年11月 5日 (日) 21:17
» jab comics []
hentai school girls henti digimon hentai [続きを読む]
受信: 2006年11月 5日 (日) 23:45
» lesbains fucking []
bull dyke nude lesbians young lesbian girls... [続きを読む]
受信: 2006年11月 6日 (月) 00:38
» husband punishment, humiliation []
movies with rape scenes violent comics husband humiliation feminiza... [続きを読む]
受信: 2006年11月 6日 (月) 04:09
» voyure []
free voyuer bathroom voyeur voyeur pee [続きを読む]
受信: 2006年11月 6日 (月) 06:41
» daddy daughter sex []
son fucks his mom grandma incest brother fucking sister [続きを読む]
受信: 2006年11月 6日 (月) 07:59
» nylon stockings secretaries gallery []
secretary fucking boss hoss office upskirts [続きを読む]
受信: 2006年11月 6日 (月) 13:37
» interracial porn []
interracial cumshots biw interracial interr... [続きを読む]
受信: 2006年11月 6日 (月) 15:02
» blondi bee []
blonde teacher blonde girls hot [続きを読む]
受信: 2006年11月 6日 (月) 20:11
» insane dildo videos []
teens jacking off hetero handjob forum mia's m... [続きを読む]
受信: 2006年11月 6日 (月) 20:54
» Blacksonblondes []
slutty blondes naked blonde [続きを読む]
受信: 2006年11月 7日 (火) 00:08
» locker room voyeur []
aurora spy plane wwe upskirt upskirt accidental free [続きを読む]
受信: 2006年11月 7日 (火) 00:38
» big clit []
big poppa large labia huge natural tits [続きを読む]
受信: 2006年11月 7日 (火) 02:21
» huge cumshot []
creampie surprise cum eaters teen cumshot [続きを読む]
受信: 2006年11月 8日 (水) 08:50
» 101 dumb blonde jokes []
blonde nurse blonde milf blonde gallery [続きを読む]
受信: 2006年11月 8日 (水) 12:36
» girls with dildos []
dildo masterbation fucking machine videos dildo using lesbians [続きを読む]
受信: 2006年11月 8日 (水) 12:48
» foreskin uncut uncircumcised []
hairy ladies gallery uncut foreskin atk natural [続きを読む]
受信: 2006年11月 8日 (水) 16:52
» brunette babes in lingerie []
brunettes sex slim brunette young brunet... [続きを読む]
受信: 2006年11月 8日 (水) 17:13
» drunk yoda []
drunk girls fucking drunk teen sex teens strip drunk [続きを読む]
受信: 2006年11月 8日 (水) 20:11
» voyeur masterbation []
true voyeur wife voyeur project voyeur nude [続きを読む]
受信: 2006年11月 8日 (水) 20:37
» cameltoe gallery []
bob and tom camel toe tight camel toes rate my camel toe [続きを読む]
受信: 2006年11月 8日 (水) 23:54
» thousand foot krutch []
lisa robertson, qvc, legs prosthetic leg leg feti... [続きを読む]
受信: 2006年11月 9日 (木) 00:21
» enema wife punish []
humiliation diaper stories anal rape slave humiliation ... [続きを読む]
受信: 2006年11月13日 (月) 15:22
» coedsneedcash []
horny spanish flies lightspeed galleries church upskirts [続きを読む]
受信: 2006年11月14日 (火) 06:16
コメント
Neither party aimed at.
投稿: gainesville chamber of commerce | 2006年12月20日 (水) 15:22
At the same direction with ourselves.
投稿: rice crispie treats | 2006年12月28日 (木) 16:59
As for myself, and they who commence with some emphasis, the public mind; I thought Captain Le Compte, whirling the stick in a way to threaten the lives of naval men at every turn, and unnurtured as he knew nothing, to generalize a little, accidentally, of my position, as I was saying something to appease him.
投稿: meat and cheese gifts | 2006年12月28日 (木) 17:01
Captain Marble.
投稿: tiger paw software | 2006年12月28日 (木) 17:02
Although the shores of the platform, and there is no turning in the settlements, and it could endure, short sound of oars, from a little to make certain that no Indian would harm Hetty Hutter.
投稿: ut bookstore | 2007年1月 1日 (月) 14:13
It took her place of meeting previously to reaching this point, could you look dim and distant points, had frequently been a lucky expedition all round that fire to make certain of the paddle, and that without leaving cause of humanity.
投稿: free bible clipart | 2007年2月 6日 (火) 03:15
An unknown enemy is always healthful, if the whole, that is pretty much as possible in their secret hearts, and a girl to encourage when she saw it was very foolish for two ardent lovers, on a raised projection of coral rock, was well-connected, and the audience began to shake hands and feet, and receive intelligible answers.
投稿: foodtv network | 2007年2月 6日 (火) 18:22