<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>コマンド &#8211; スグブログ</title>
	<atom:link href="https://sugublog.org/tag/%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89/feed/" rel="self" type="application/rss+xml" />
	<link>https://sugublog.org</link>
	<description>ブログ運営について発信中</description>
	<lastBuildDate>Sun, 02 Jun 2024 06:06:24 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://sugublog.org/wp-content/uploads/2021/07/icon_20210703-min-150x150.png</url>
	<title>コマンド &#8211; スグブログ</title>
	<link>https://sugublog.org</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>【Linux】viの便利なコマンドで超効率化を行う！</title>
		<link>https://sugublog.org/linux-vi-command/</link>
					<comments>https://sugublog.org/linux-vi-command/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[suguru]]></dc:creator>
		<pubDate>Fri, 26 Apr 2024 15:01:00 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[サーバ]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[vi]]></category>
		<category><![CDATA[コマンド]]></category>
		<guid isPermaLink="false">https://sugublog.org/?p=6617</guid>

					<description><![CDATA[<p><img src="https://sugublog.org/wp-content/uploads/2021/11/script_1114-1024x683.jpg" class="webfeedsFeaturedVisual" /></p>Linuxのviのコマンドで便利なものをご紹介します。 viエディタで設定ファイルの編集など、ひとつひとつきちんと修正しているけど何か時間がかかってしまう。 面倒くさいやり方になっている気がするけど、どう効率化すればわか [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><img src="https://sugublog.org/wp-content/uploads/2021/11/script_1114-1024x683.jpg" class="webfeedsFeaturedVisual" /></p>
<p><strong><span class="swl-inline-color has-swl-deep-01-color">Linuxのviのコマンド</span></strong>で便利なものをご紹介します。</p>



<p>viエディタで設定ファイルの編集など、ひとつひとつきちんと修正しているけど何か時間がかかってしまう。</p>



<p>面倒くさいやり方になっている気がするけど、どう効率化すればわからない</p>



<p>そういった疑問をもっているエンジニアの為に、<strong><span class="swl-inline-color has-swl-deep-01-color">Linuxのviで便利なコマンド</span></strong>を現役エンジニアの筆者がまとめます。</p>


<div class="p-blogParts post_content" data-partsID="5908">
<p>筆者はWindowsサーバーやLinuxサーバーの運用構築を11年間以上おこなってきました。その経験を元に知識を公開していきます！</p>
</div>

<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="blue"><div class="c-balloon__icon -square"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://sugublog.org/wp-content/uploads/2021/03/dog004-150x150.jpeg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/03/dog004-150x150.jpeg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">Linuxサーバーエンジニア</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>この記事を読んでviのコマンドをものにすれば、viエディタの作業効率が上がります。</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle ads" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-9330904718533231" data-ad-slot="6086594686"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<h2 class="wp-block-heading">Linuxのviエディタのコマンド</h2>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="632" src="https://sugublog.org/wp-content/uploads/2021/11/programing_1122-3-1024x632.jpg" alt="コマンド" class="wp-image-4560" srcset="https://sugublog.org/wp-content/uploads/2021/11/programing_1122-3-1024x632.jpg 1024w, https://sugublog.org/wp-content/uploads/2021/11/programing_1122-3-300x185.jpg 300w, https://sugublog.org/wp-content/uploads/2021/11/programing_1122-3-768x474.jpg 768w, https://sugublog.org/wp-content/uploads/2021/11/programing_1122-3.jpg 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p>Linuxのviエディタのコマンドを要件別にまとめます。</p>



<div class="swell-block-capbox cap_box is-style-onborder_ttl"><div class="cap_box_ttl"><span>Linuxのviエディタのコマンドの種類</span></div><div class="cap_box_content">
<ul class="wp-block-list">
<li>編集系viコマンド</li>



<li>移動系viコマンド</li>



<li>保存系viコマンド</li>



<li>編集モード移行コマンド</li>



<li>viエディタ設定コマンド</li>
</ul>
</div></div>



<p>それではご紹介します。</p>



<p class="is-style-icon_info">注意：Linuxのviエディタでは編集モードとコマンドモードがあり、編集モードの時はEscを押してコマンドモードに変更してください。</p>



<h2 class="wp-block-heading">編集系viコマンド</h2>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="536" src="https://sugublog.org/wp-content/uploads/2021/11/Server_20211109-16-1024x536.jpg" alt="コマンド" class="wp-image-4423" srcset="https://sugublog.org/wp-content/uploads/2021/11/Server_20211109-16-1024x536.jpg 1024w, https://sugublog.org/wp-content/uploads/2021/11/Server_20211109-16-300x157.jpg 300w, https://sugublog.org/wp-content/uploads/2021/11/Server_20211109-16-768x402.jpg 768w, https://sugublog.org/wp-content/uploads/2021/11/Server_20211109-16.jpg 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p><span class="swl-bg-color has-swl-deep-01-background-color">編集する時</span>に使えるviコマンドをまとめます。</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>コマンド</th><th>効果</th></tr></thead><tbody><tr><td>dd</td><td>1行まとめて消去</td></tr><tr><td>yy</td><td>1行まとめてコピー</td></tr><tr><td>p</td><td>ペースト</td></tr><tr><td>:%d</td><td>全て消去</td></tr><tr><td>u</td><td>編集の取り消し</td></tr><tr><td>.</td><td>最後の編集の繰り返しの動作</td></tr><tr><td>~</td><td>カーソルの文字を大文字⇔小文字に変更</td></tr></tbody></table><figcaption class="wp-element-caption">編集する時に使えるviコマンド一覧表</figcaption></figure>



<p>行のコピペは最も使用するので覚えて下さい。</p>



<p>編集の取り消ししたい場合はCtrl+zしてしまいがちですが、Linuxではviエディタ終了してしまいます。編集の取り消しはコマンドモードでuを押しましょう！</p>



<h2 class="wp-block-heading">移動系viコマンド</h2>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="597" src="https://sugublog.org/wp-content/uploads/2021/07/code007-1024x597.jpg" alt="移動" class="wp-image-3587"/><figcaption class="wp-element-caption">Business Creative Startup Idea Mobile App Concept. Social Media Network Technology Online Research Application. Vector Illustration.</figcaption></figure>
</div>


<p><span class="swl-bg-color has-swl-deep-02-background-color">移動する時</span>に使えるviコマンドをまとめます。</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>コマンド</th><th>効果</th></tr></thead><tbody><tr><td>G</td><td>一番最後の行に移動</td></tr><tr><td>1G</td><td>一番最初の行に移動</td></tr><tr><td>nG</td><td>n行目に移動</td></tr><tr><td>0</td><td>選択している行の一番先頭へ移動</td></tr><tr><td>$</td><td>選択している行の一番末尾へ移動</td></tr><tr><td>Ctrl＋f</td><td>画面を下に向けて1ページスクロール</td></tr><tr><td>Ctrl＋b</td><td>画面を上に向けて1ページスクロール</td></tr></tbody></table><figcaption class="wp-element-caption">移動する時に使えるviコマンド一覧表</figcaption></figure>



<p>一番下にカーソルを持っていく事は多いのではないでしょうか？コマンドで移動しましょう！</p>



<p>一番下だけでなく一番上や行数指定して移動も可能です。</p>



<p>カーソルの先頭や末尾にも移動できます。</p>



<p><span class="swl-bg-color has-swl-deep-03-background-color">検索して対象の文字列に移動するviコマンド</span>をまとめます。</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>コマンド</th><th>効果</th></tr></thead><tbody><tr><td>/検索文字列</td><td>カーソルから下に向かって検索</td></tr><tr><td>?検索文字列</td><td>カーソルから上に向かって検索</td></tr><tr><td>n</td><td>検索した後、更に次の文字列へ移動</td></tr><tr><td>N</td><td>検索した後、更に前の文字列へ移動</td></tr></tbody></table><figcaption class="wp-element-caption">検索して対象の文字列に移動するviコマンド一覧表</figcaption></figure>



<p class="is-style-icon_pen">Linuxのviエディタで文字列を検索する時の詳細な説明は、以下の記事を参考にしてください。</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/07/analytics-5-300x200.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/linux-vi-how-to-search/">【Linux】viで検索する方法！繰り返し検索するやり方も教えます！</a>
						<span class="p-blogCard__excerpt">Linuxサーバーのviエディタで文字列を検索したい時があると思います。 文字列が多いLinuxでは検索が早いけど、コマンドを良く忘れます。 なのでここでviの検索について&#8230;</span>					</div>
				</div>
			</div>
		</div>


<h2 class="wp-block-heading">保存系viコマンド</h2>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="665" src="https://sugublog.org/wp-content/uploads/2021/11/HDD_1107-7-1024x665.jpg" alt="ハードディスク" class="wp-image-4367" srcset="https://sugublog.org/wp-content/uploads/2021/11/HDD_1107-7-1024x665.jpg 1024w, https://sugublog.org/wp-content/uploads/2021/11/HDD_1107-7-300x195.jpg 300w, https://sugublog.org/wp-content/uploads/2021/11/HDD_1107-7-768x499.jpg 768w, https://sugublog.org/wp-content/uploads/2021/11/HDD_1107-7.jpg 1198w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p><span class="swl-bg-color has-swl-deep-04-background-color">保存する時</span>に使えるviコマンドをまとめます。</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>コマンド</th><th>効果</th></tr></thead><tbody><tr><td>:q!</td><td>保存せずにviエディタ終了</td></tr><tr><td>:wq</td><td>保存してviエディタ終了</td></tr><tr><td>:w</td><td>保存</td></tr><tr><td>:w ファイル名</td><td>指定したファイル名で別名保存</td></tr><tr><td>:wq ファイル名</td><td>指定したファイル名で別名保存してviエディタ終了</td></tr><tr><td>:e!</td><td>編集を破棄して再読み込み</td></tr><tr><td>:! コマンド</td><td>編集中にコマンド実行</td></tr></tbody></table><figcaption class="wp-element-caption">保存する時に使えるviコマンド一覧表</figcaption></figure>



<p>保存して終了や破棄して終了は基本中の基本ですので、是非覚えましょう！</p>



<p class="is-style-icon_book">viエディタを終了する時のやり方の詳細は、以下の記事を参照下さい。</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/06/rocket0627-300x200.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/linux-vi-how-to-quit/">【Linux】viで終了のやり方！保存して終了や保存しないで保存の方法</a>
						<span class="p-blogCard__excerpt">Linuxを使用していて、viエディタの終了のやり方が分からなくなる時があります。 そんな時の為にviの終了のやり方を、現役エンジニアの筆者がまとめます。 保存して終了&#8230;</span>					</div>
				</div>
			</div>
		</div>


<p>別名で保存も出来ます。</p>



<p class="is-style-big_icon_check">編集を破棄して読み込みはよく使用するので、覚えると効率化できます。</p>



<h2 class="wp-block-heading">編集モード移行コマンド</h2>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="782" src="https://sugublog.org/wp-content/uploads/2021/12/PC教室20211216-8-1024x782.jpg" alt="編集" class="wp-image-4802" srcset="https://sugublog.org/wp-content/uploads/2021/12/PC教室20211216-8-1024x782.jpg 1024w, https://sugublog.org/wp-content/uploads/2021/12/PC教室20211216-8-300x229.jpg 300w, https://sugublog.org/wp-content/uploads/2021/12/PC教室20211216-8-768x586.jpg 768w, https://sugublog.org/wp-content/uploads/2021/12/PC教室20211216-8.jpg 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p><span class="swl-bg-color has-swl-main-background-color">コマンドモードから編集モードへ移行して編集する時</span>のviコマンドをまとめます。</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>コマンド</th><th>効果</th></tr></thead><tbody><tr><td>i</td><td>カーソルの前から編集可能になる</td></tr><tr><td>I</td><td>カーソルの先頭から編集可能になる</td></tr><tr><td>a</td><td>カーソルの後から編集可能になる</td></tr><tr><td>A</td><td>カーソルの末尾から編集可能になる</td></tr><tr><td>o</td><td>カーソルの下に行を挿入して編集可能になる</td></tr><tr><td>O</td><td>カーソルの上に行を挿入して編集可能になる</td></tr></tbody></table><figcaption class="wp-element-caption">編集モードへ移行する時のviコマンド一覧表</figcaption></figure>



<p>行を挿入して編集可能にする事で効率化できますね。</p>



<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-9330904718533231"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block"
     data-ad-format="autorelaxed"
     data-ad-client="ca-pub-9330904718533231"
     data-ad-slot="8455594968"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<h2 class="wp-block-heading">viエディタ設定コマンド</h2>


<div class="wp-block-image is-style-border">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="745" src="https://sugublog.org/wp-content/uploads/2021/04/blog1-17-min-1024x745.jpeg" alt="設定" class="wp-image-2811"/></figure>
</div>


<p><span class="swl-inline-color has-swl-deep-01-color"><strong>viエディタの設定を行えるコマンド</strong></span>をまとめます。</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>コマンド</th><th>効果</th></tr></thead><tbody><tr><td>:set number</td><td>ファイルの行数を表示する</td></tr><tr><td>:set nonumber</td><td>ファイルの行数表示を解除する</td></tr><tr><td>:set list</td><td>行末などの表示されない文字も表示する</td></tr><tr><td>:set nolist</td><td>行末などの表示されない文字表示を解除する</td></tr></tbody></table><figcaption class="wp-element-caption">編集モードへ移行する時のviコマンド一覧表</figcaption></figure>



<p>行数を表示して指定した行に移動などもできますね。「:set number」を実行して行数を表示して「nG」でn行目にカーソル移動できます。</p>


<div class="swell-block-balloon"><div class="c-balloon -bln-right" data-col="blue"><div class="c-balloon__icon -square"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://sugublog.org/wp-content/uploads/2021/02/mine_white_002-e1624111291945.png" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/02/mine_white_002-e1624111291945.png" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">管理人</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>Linuxのviエディタのコマンドについて説明しました。</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<p class="is-style-icon_book">viエディタの使い方については以下の記事を参照してください。</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/06/search-min-1-e1623599919108-300x180.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/linux-vi-how-to-use/">【Linux】viの使い方！必須のコマンドから作業効率出来るコマンドまで</a>
						<span class="p-blogCard__excerpt">今回はLinuxサーバーのviエディタの使い方です Linuxsサーバーを使用していて、通常使用するテキストエディタはviエディタです。 しかしviエディタは癖が強く使いにくい&#8230;</span>					</div>
				</div>
			</div>
		</div>]]></content:encoded>
					
					<wfw:commentRss>https://sugublog.org/linux-vi-command/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【Linux】CentOSでコマンドでファイル作成する方法｜エラー対処法あり</title>
		<link>https://sugublog.org/linux-centos-file-create-command/</link>
					<comments>https://sugublog.org/linux-centos-file-create-command/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[suguru]]></dc:creator>
		<pubDate>Tue, 23 Apr 2024 14:17:51 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[サーバ]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[コマンド]]></category>
		<category><![CDATA[ファイル作成]]></category>
		<guid isPermaLink="false">https://sugublog.org/?p=6588</guid>

					<description><![CDATA[<p><img src="https://sugublog.org/wp-content/uploads/2021/08/DB0804-3-1024x717.jpg" class="webfeedsFeaturedVisual" /></p>という事で今回はLinuxサーバーでテキストファイル作成する時のコマンドを教えます。 また普通では作成できないファイル名の作成も挑戦します。 LinuxサーバーのCentOSコマンドでファイル作成する方法 Linuxサー [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><img src="https://sugublog.org/wp-content/uploads/2021/08/DB0804-3-1024x717.jpg" class="webfeedsFeaturedVisual" /></p><div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="red"><div class="c-balloon__icon -square"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://sugublog.org/wp-content/uploads/2021/02/cropped-dog003-150x150.png" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/02/cropped-dog003-150x150.png" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">LinuxのCentOSコマンドでファイル作成したい人</span></div><div class="c-balloon__body -thinking -border-on"><div class="c-balloon__text">
<p>Linuxでテキストファイル作成したいです。</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>

<div class="swell-block-balloon"><div class="c-balloon -bln-right" data-col="blue"><div class="c-balloon__icon -square"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://sugublog.org/wp-content/uploads/2021/02/mine_white_001.png" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/02/mine_white_001.png" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">管理人</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>Linuxサーバーでファイル作成するのは基本ですね。コマンドでテキストファイル作成のやり方を教えますよ。</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<p>という事で今回は<strong><span class="swl-inline-color has-swl-deep-01-color"><span class="swl-marker mark_orange">Linuxサーバーでテキストファイル作成する時のコマンド</span></span></strong>を教えます。</p>



<p class="is-style-icon_info">また普通では作成できないファイル名の作成も挑戦します。</p>


<div class="p-blogParts post_content" data-partsID="5908">
<p>筆者はWindowsサーバーやLinuxサーバーの運用構築を11年間以上おこなってきました。その経験を元に知識を公開していきます！</p>
</div>


<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle ads" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-9330904718533231" data-ad-slot="6086594686"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<h2 class="wp-block-heading">LinuxサーバーのCentOSコマンドでファイル作成する方法</h2>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="682" src="https://sugublog.org/wp-content/uploads/2021/11/DB_1114-5-1024x682.jpg" alt="ファイル作成" class="wp-image-4502" srcset="https://sugublog.org/wp-content/uploads/2021/11/DB_1114-5-1024x682.jpg 1024w, https://sugublog.org/wp-content/uploads/2021/11/DB_1114-5-300x200.jpg 300w, https://sugublog.org/wp-content/uploads/2021/11/DB_1114-5-768x511.jpg 768w, https://sugublog.org/wp-content/uploads/2021/11/DB_1114-5.jpg 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p>Linuxサーバーで<strong><span class="swl-inline-color has-swl-deep-01-color">ファイルを作成</span></strong>するには以下のコマンドでよく行います。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>touch ファイル名</code></pre></div>



<p>CentOSコマンドではこれでファイルを作成する事が可能です。</p>



<h3 class="wp-block-heading">ファイル作成するtouchコマンドのオプション</h3>



<p><strong><span class="swl-inline-color has-swl-deep-03-color">ファイル作成するtouchコマンドのオプション</span></strong>をまとめておきます。</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>touchのオプション</th><th>効果</th></tr></thead><tbody><tr><td>-a</td><td>アクセス日時を変更する</td></tr><tr><td>-m</td><td>更新日時を変更する</td></tr><tr><td>-t タイムスタンプ</td><td>タイムスタンプを変更する</td></tr></tbody></table><figcaption class="wp-element-caption">touchコマンドのオプション</figcaption></figure>



<h2 class="wp-block-heading">実践：CentOSコマンドでファイル作成する方法</h2>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="683" src="https://sugublog.org/wp-content/uploads/2021/11/programing_shool1121-1-1024x683.jpg" alt="training" class="wp-image-4541" srcset="https://sugublog.org/wp-content/uploads/2021/11/programing_shool1121-1-1024x683.jpg 1024w, https://sugublog.org/wp-content/uploads/2021/11/programing_shool1121-1-300x200.jpg 300w, https://sugublog.org/wp-content/uploads/2021/11/programing_shool1121-1-768x512.jpg 768w, https://sugublog.org/wp-content/uploads/2021/11/programing_shool1121-1.jpg 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p>では実際にLinuxサーバーのCentOSコマンドでファイル作成してみます。</p>



<p>「file1.txt」のテキストファイルを作成してみます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>touch file1.txt</code></pre></div>



<p class="has-border -border01">これで「ls」コマンドで確認すると、結果は作成されています。</p>



<h2 class="wp-block-heading">CentOSコマンドでファイル作成で失敗する時の回避策</h2>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="683" src="https://sugublog.org/wp-content/uploads/2021/06/shutterstock_1433996435-min-1024x683.jpg" alt="エラー" class="wp-image-2885"/></figure>
</div>


<p>では今度は「-file1.txt」というテキストファイルをコマンドで作成してみます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>touch -file1.txt</code></pre></div>


<div class="wp-block-image is-style-desktop">
<figure class="aligncenter size-full"><img decoding="async" width="518" height="80" src="https://sugublog.org/wp-content/uploads/2024/04/1_ファイル作成エラー.png" alt="ファイル作成エラー" class="wp-image-6591" srcset="https://sugublog.org/wp-content/uploads/2024/04/1_ファイル作成エラー.png 518w, https://sugublog.org/wp-content/uploads/2024/04/1_ファイル作成エラー-300x46.png 300w" sizes="(max-width: 518px) 100vw, 518px" /></figure>
</div>


<p class="is-style-big_icon_batsu">結果はエラーが出てしまいました。</p>



<h3 class="wp-block-heading">エラーが出るファイルを作成する方法</h3>



<p><strong><span class="swl-inline-color has-swl-deep-01-color">エラーが出るファイルを作成する方法</span></strong>をまとめます。</p>



<div class="swell-block-capbox cap_box is-style-onborder_ttl"><div class="cap_box_ttl"><span>エラーが出るファイルを作成する方法２選</span></div><div class="cap_box_content">
<ul class="wp-block-list">
<li>&#8211;オプションを使う</li>



<li>./をつける</li>
</ul>
</div></div>



<h3 class="wp-block-heading">&#8211;オプションを使いファイル作成する</h3>



<p>Linuxで「&#8211;」はその後にオプションが来ませんという意味です。</p>



<p>つまりファイル名の「-file1.txt」がオプションとして解釈されているという事です。</p>



<p class="is-style-icon_announce">では&#8211;オプションを使用した、このコマンドでファイル作成してみます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>touch -- -file1.txt</code></pre></div>


<div class="wp-block-image is-style-desktop">
<figure class="aligncenter size-full"><img decoding="async" width="722" height="77" src="https://sugublog.org/wp-content/uploads/2024/04/2_-でファイル作成成功.png" alt="ファイル作成成功" class="wp-image-6592" srcset="https://sugublog.org/wp-content/uploads/2024/04/2_-でファイル作成成功.png 722w, https://sugublog.org/wp-content/uploads/2024/04/2_-でファイル作成成功-300x32.png 300w" sizes="(max-width: 722px) 100vw, 722px" /></figure>
</div>


<p class="has-border -border01">エラーが出ずファイル作成できました。</p>



<h3 class="wp-block-heading">./をつけてファイル作成する</h3>



<p>Linuxで「./」はその階層という意味です。先程はファイル名の初めが「-」だったためにオプションと解釈された事が原因でした。</p>



<p>今回はファイル名の先頭を「-」にしないように「./」をつけています。</p>



<p class="is-style-icon_announce">では「./」を使用した、このコマンドでファイル作成してみます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>touch ./-file1.txt</code></pre></div>


<div class="wp-block-image is-style-desktop">
<figure class="aligncenter size-full"><img decoding="async" width="688" height="78" src="https://sugublog.org/wp-content/uploads/2024/04/3_その他のやり方でファイル作成成功.png" alt="ファイル作成成功" class="wp-image-6593" srcset="https://sugublog.org/wp-content/uploads/2024/04/3_その他のやり方でファイル作成成功.png 688w, https://sugublog.org/wp-content/uploads/2024/04/3_その他のやり方でファイル作成成功-300x34.png 300w" sizes="(max-width: 688px) 100vw, 688px" /></figure>
</div>


<p class="has-border -border01">エラーが出ずテキストファイル作成できました。</p>



<p class="is-style-icon_pen">ファイル削除できない時も同じ事象の可能性があります。以下の記事で紹介しています。</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/06/nayami111-4-300x200.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/linux-cannot-delete-file/">【Linux】CentOSでファイル削除ができない時の原因と対処法</a>
						<span class="p-blogCard__excerpt">Linuxサーバでファイルが削除できない時はないでしょうか？ そういった時の対処法を、現役エンジニアの筆者が教えます。 わかりやすいように実例で図を用いて説明します&#8230;</span>					</div>
				</div>
			</div>
		</div>


<h2 class="wp-block-heading">Linuxでその他の作成に関するコマンドの記事</h2>



<p>Linuxサーバーでディレクトリ作成コマンドについて</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/08/DB0804-1-300x225.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/linux-create-directory-folder-with-mkdir/">【Linux】mkdirコマンドでディレクトリを作成する方法やオプションご紹介</a>
						<span class="p-blogCard__excerpt">Linuxサーバーでディレクトリ（フォルダ）を作成するコマンドをお伝えします。 複数のディレクトリ（フォルダ）を一括で作成する方法や階層のディレクトリ（フォルダ）&#8230;</span>					</div>
				</div>
			</div>
		</div>


<p>Linuxサーバーでユーザー作成について</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/11/running_1128-3-300x225.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/linux-useradd/">【Linux初心者向け】ユーザー作成の方法とオプション一覧</a>
						<span class="p-blogCard__excerpt">Linuxサーバーでユーザーの作成方法をまとめます。 Linuxサーバーを運用していてroot権限で操作する事はセキュリティ上よくありません。ログインするエンジニアのユーザ&#8230;</span>					</div>
				</div>
			</div>
		</div>


<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-9330904718533231"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block"
     data-ad-format="autorelaxed"
     data-ad-client="ca-pub-9330904718533231"
     data-ad-slot="8455594968"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<h2 class="wp-block-heading">まとめ：【Linux】CentOSでコマンドでファイル作成する方法</h2>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="768" src="https://sugublog.org/wp-content/uploads/2021/08/DB0804-1-1024x768.jpg" alt="ファイル" class="wp-image-3840" srcset="https://sugublog.org/wp-content/uploads/2021/08/DB0804-1-1024x768.jpg 1024w, https://sugublog.org/wp-content/uploads/2021/08/DB0804-1-300x225.jpg 300w, https://sugublog.org/wp-content/uploads/2021/08/DB0804-1-768x576.jpg 768w, https://sugublog.org/wp-content/uploads/2021/08/DB0804-1.jpg 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p class="has-border -border02">Linuxサーバーでファイルを作成するコマンドはtouchです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>touch ファイル名</code></pre></div>



<p>ファイル名の先頭に「-」がつくファイル名はオプションと解釈されて作成できない</p>



<p>その時の回避方法は以下にまとめています。</p>



<div class="swell-block-capbox cap_box is-style-onborder_ttl"><div class="cap_box_ttl"><span>ファイル名の先頭に「-」がつくファイルを作成する方法２選</span></div><div class="cap_box_content">
<ul class="wp-block-list">
<li>&#8211;オプションを使う</li>



<li>./をつける</li>
</ul>
</div></div>


<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="blue"><div class="c-balloon__icon -square"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://sugublog.org/wp-content/uploads/2021/03/dog004-150x150.jpeg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/03/dog004-150x150.jpeg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">機嫌のいいワンコ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>LinuxのCentOSコマンドでファイル作成できました！</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>]]></content:encoded>
					
					<wfw:commentRss>https://sugublog.org/linux-centos-file-create-command/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
