Terminal.appからyuji.devにログインする
ssh yuji@yuji.dev password: [yuji@localhost ~]$
ログアウトする
$ exit
$ passwd
現在のディレクトリを表示
pwd
ディレクトリを変更(移動)する
cd
トップディレクトリへ移動する
cd /
ホームディレクトリへ移動する
cd ~
一つ上のディレクトリへ移動
cd ..
二つ上のディレクトリへ移動
cd ../..
ディレクトリの中身をみる
ls
ディレクトリの中身の詳細をみる
ls -l
隠しファイルも表示する
ls -a
※複数のオプションを組み合わせることも可能
ls -l drwxr-xr-x 20 root root 4096 Dec 19 00:20 var
パーミションを「rwxr-xr-x」に変更する
$ chmod 755
ディレクトリ「test1」を作成
$ mkdir test1
ディレクトリ「test1」を削除
$ rmdir test1
「test」ディレクトリおよび「test.txt」ファイルを作成
$ mkdir test $ vi test.txt
「test.txt」のコピー「text2.txt」を作成
$ cp test.txt test2.txt
ディレクトリ「test」配下にコピー「test3.txt」を作成
$ cp test.txt test/test3.txt
「test3.txt」を削除
$ rm test3.txt
一つ上の階層の「test2.txt」を削除
$ rm ../test.txt
「text.txt」を「test」配下へ移動
$ mv test.txt test/
「text.txt」の名前を「text2.txt」に変更
$ mv test.txt test2.txt
「test2.txt」ファイルの中身を全て表示する
cat test2.txt
ファイルの中身を順を追って表示する
more test2.txt less test2.txt
最初の10行を表示する (オプションで行数を指定可)
head test2.txt
最後の10行を表示する (オプションで行数を指定可)
tail test2.txt
拡張子が「.txt」のファイルを全て削除
$ rm *.txt
「test6.text」というファイルを削除
$ rm test6.te?t
カレントディレクトリから「test_」を含むファイルを検索
$ find . -name "test_*" -type f
カレントディレクトリから「test_」を含むディレクトリを検索
$ find . -name "test_*" -type d
使い方は「grep -[option] [文字列] [対象ファイル]」
「111」という文字列を含むファイルを検索
$ grep 111 *
「111」という文字列がマッチした回数をカウントする
$ grep -c 111 *
配下のディレクトリも含めて全て検索
$ grep -r 111 *
「111」且つ「222」という文字列を含むファイルを検索
$ grep 111 * | grep 222
$ history
$ !255
$ !!
$ !gr
$ !gr:p
manコマンドでgrepのマニュアルを見る
man grep
※スペースキーでスクロール「q」で終了
ディレクトリ構造を表示する
$ tree
(サーバの)時間を表示する
$ date
カレンダーを表示する
$ cal
2030年のカレンダーを表示する
$ cal -y 2030
「test1.txt」ファイルの行数を表示する
$ wc test1.txt $ wc -l test1.txt
$ cd $HOME $ vim .bashrc alias ls = 'ls -G'
$ cd $HOME $ vim .bash_profile source .bashrc
$ source .bash_profile
chr(13) : CR (キャリッジリターン) : MacOS ver.9まで chr(10) : LF (ラインフィード) : UNIX系システム chr(13)||chr(10) : CRLF : Windows系
#正規表現 \r : CR (キャリッジリターン) \n : LF (ラインフィード) \r\n : CRLF