コマンドプロンプト操作

コマンドプロンプト操作(1)





コマンドプロンプトの起動と終了
最初に覚えるコマンド
ディレクトリ構造とパス
各種コマンドの練習
Cコンパイルとプログラムの実行
今日のポイント
コマンドプロンプトに慣れよう
コマンドプロンプトの起動と終了
起動(マウス)




[スタート] を<クリック>
[すべてのプログラム(P)]
[Microsoft Visual Studio 2005]
[Visual C++コマンドプロンプト] を<クリック>
終了(キーボード)

「exit」 と入力して <Enter>
コマンドプロンプトはCUI
(Character-based User
Interface)でコマンドを実行
終了(マウス)

x ボタンを<クリック>
右上の [x]
練習:実際にコマンドプロンプトを起動して終了せよ。
コマンドプロンプトのショートカットを
デスクトップに作成

[スタート]を<クリック>

[すべてのプログラム(P)]

[Microsoft Visual Studio 2005]

[Visual C++コマンドプロンプト] を <右クリック>

[送る(N)]

[デスクトップ (ショートカットを作成)] を<クリック>
最初に覚えるコマンド

dir (directory)
ディレクトリ中のファイル一覧表示

cd または chdir (change directory)
ディレクトリの変更
(親ディレクトリは 「..」,現在地は 「.」 )

<ドライブ文字>:
ドライブ(A:~Z:)の変更

help
各コマンドのヘルプ情報の表示
HELPの練習

help を実行せよ
Z:\>help<Enter>

コマンドプロンプトでは、大文字と
小文字は区別されないことに注意
help dir または dir /? を実行し、/s,/x など
のオプション指定時の動作が書いてある箇所
を確認せよ
Z:\>help dir<Enter>
Z:\>dir /?<Enter>

help cd または cd /? を実行せよ
Z:\>help cd<Enter>
Z:\>cd /?<Enter>
ディレクトリ構成とパス
dir /x で表示

ディレクトリ=フォルダ

8文字より長い名前には短い別名がつけられる。

空白を含む場合は引用符(")でくくる必要あり。

パス = <ドライブ>\<ディレクトリ>\…
例

Z:\VISUAL~1 = "Z:\Visual Studio 2005"
デスクトップ
[-] マイ コンピュータ
[-] 'fs\home\students'のt082900 (Z:)
[+] Visual Studio 2005
エクスプローラでの
ツリー構造記述
GUIでのパス名表示の設定







「 マイ ドキュメント」 を開く
メニューバーの [ツール (T)] を<クリック>
[ フォルダ オプション(O)...] を<クリック>
[表示]タブを選択
「アドレス バーにファイルのパス名を表示する」 が
<チェック>されていることを確認
「タイトル バーにファイルのパス名を表示する」 が
<チェック>されていることを確認
[ OK ] ボタンを<クリック>
有用なコマンドとワイルドカード

tree (ディレクトリ構造の表示)

md / mkdir (make directory: ディレクトリの作成)

copy (ファイルのコピー)


del (delete: ファイルの削除)
ren (rename: ファイル名の変更)

more (ページごとの表示)

* (任意の文字列)

? (任意の一文字)
「del *.*」はディレクトリ内全ファイル一括削除
「del ???.?」は<3文字>.<1文字>の形の名前の全ファイル削除
ディレクトリ移動、一覧表示の練習(1)

ソースファイルのある場所に移動
Z:\>cd nyumon1
Z:\
Z:\nyumon1>cd hello
nyumon1\
hello\
または
Debug\

hello.obj
Z:\>cd nyumon1\hello
hello.exe
一覧表示
...
hello.c
Z:\nyumon1\hello>dir
グループ・名前順
...
...
Z:\nyumon1\hello>dir /ogn
ワイド版
Z:\nyumon1\hello>dir /w
ワイド版(列方向)
Z:\nyumon1\hello>dir /d
Z:\nyumon1\hello>dir /ogn /s
サブディレクトリ、グループ・名前順
ディレクトリ名が日本語や空白を含む場合は、それらを含まない名前に直しておく。
プログラムの実行

実行ファイルのある場所に移動
Z:\nyumon1\hello>cd Debug

実行
開発環境で作成し
た実行ファイルは
Debugフォルダ内
Z:\nyumon1\hello\Debug>hello
あるいは
Z:\nyumon1\hello\Debug>hello.exe
練習:今まで作成した
他のプログラムもコマ
ンドプロンプト上で実
行してみよ
Z:\
nyumon1\
hello\
Debug\
hello.exe
...
ディレクトリ移動、一覧表示の練習(2)




親ディレクトリに移動
親
Z:\nyumon1\hello\Debug>cd ..
Z:\nyumon1\hello>cd ..
Z:\
nyumon1\
ツリー構造表示
現在地
hello\
Z:\nyumon1>tree .
Debug\
hello.exe
Z:\nyumon1>tree hello
hello.obj
ツリー構造表示(ページごと)
...
hello.c
Z:\nyumon1>tree . | more
一覧表示(サブディレクトリ・ページごと)
Z:\nyumon1>dir /ogn /s /p
縦棒は <Shift>+<\>
Z:\nyumon1>dir /ogn /s /d /p
「パイプ」は次回にくわしく説明
ディレクトリ作成、ファイルコピーの練習

nyumon2, nyumon2\hello の作成 (すでにある人は省略)
Z:\nyumon1>cd ..
親
Z:\
nyumon1\
hello\
Z:\>md nyumon2
hello.c
...
Z:\>md nyumon2\hello

nyumon2\
hello\
hello.c のコピー
hello.c
Z:\>copy nyumon1\hello\hello.c nyumon2\hello

確認
Z:\>cd nyumon2
Z:\nyumon2>dir /s
同じファイル名でよ
いときは省略可
サブディレクトリ
ファイルコピー、削除、名前変更

ファイルの別名コピー
Z:\nyumon2>cd hello
Z:\
nyumon2\
hello\
hello.c
tmp.c
Z:\nyumon2\hello>copy hello.c tmp.c
Z:\nyumon2\hello>dir

hello.c の削除
Z:\nyumon2\hello>del hello.c
Z:\
hello\
Z:\nyumon2\hello>dir

nyumon2\
tmp.c
tmp.c の名前変更
Z:\nyuomn2\hello>ren tmp.c hello.c
Z:\nyumon2\hello>dir
Z:\
nyumon2\
hello\
hello.c
Cコンパイルとプログラムの実行

CLコマンド(compile and link)
Z:\nyumon2\hello>cl hello.c

実行ファイル確認
Z:\nyumon2\hello>dir

Z:\
nyumon2\
hello\
hello.c
hello.obj
hello.exe
実行
Z:\nyumon2\hello>hello
...
...
さらに詳しく知りたい人は以下を参照のこと
http://www.ced.is.utsunomiya-u.ac.jp/lecture/2006/common/vs2005/
command_prompt.php
「作業フォルダ」の設定

デスクトップの「Visual C++コマンドプロンプト」
の ショートカットを <右クリック>

[プロパティ(R)] を<クリック>
一番下
「Visual C++コマンドプロンプトのプロパティ」 ウィンドウ

[ショートカット] タブを選択

[作業フォルダ(S):] 欄に起動時のデフォルトパス名
(例えば 「Z:\nyumon2」)を記入

[ OK ] ボタンを<クリック>
「簡易編集モード」の設定

上部のタイトルバー
[ Visual C++ コマンドプロンプト] を <右クリック>

[プロパティ(P)] を<クリック>
一番下
「 “Visual C++ コマンドプロンプト”のプロパティ」 ウィンドウ

「オプション」 タブを選択

「編集オプション」 欄の
□簡易編集モード(Q) を<チェック>
コマンドプロンプトの参考サイト

コマンドプロンプトに興味がわいた人は
下記サイトも参照
http://cmd-pro.com/
http://www.confrage.com/dos/
http://ykr414.com/dos/
http://pcweb.mycom.co.jp/special/2002/xpcommand/
今日のポイント
コマンドプロンプトに慣れよう