echo
適当なことを表示できます。
echo hello
# hello
# 環境変数の中を見たり
echo $HOME
# /Users/hogeless
ファイルの中身をじっくり見る。デフォルトだと監視モード(追加データがきた時に即表示)で立ち上がります。
less +F -N log.txt
# 1 foo
# 2 bar
# 3 baz
# :監視モード時にctrl+cを押すことでファイルを読むモードになります。vimのようなキーバインドが効くので、例えばggと入力するとファイルの一番から内容を見ることができます。
j1行下にk1行上に
監視モードに戻りたくなったら再度F(shift+f)を入力します。
qで終わります。
pwd
現在いるディレクトリを表示
pwd
# /Users/hogemkdir
ディレクトリを作る。以下はfoo/ディレクトリを作りその中にさらにbar/ディレクトリを作っています。
mkdir -p foo/barcd
ディレクトリ移動に使います。
..は1つ上のディレクトリを~は$HOMEディレクトリを/から始めると一番トップ(ルートディレクトリ)
をそれぞれ指します。
pwd
# /Users/hoge
cd foo/bar
pwd
# /Users/hoge/foo/bar
cd ../..
pwd
# /Users/hoge
cd ~/foo
pwd
# /Users/hoge/foo
cd /Users
pwd
# /Usersls
現在のディレクトリにあるディレクトリやファイルを一覧する。頭がdから始まるものがディレクトリです。
ls -al
# total 0
# drwxr-xr-x 4 nju33 staff 128 Feb 5 21:30 .
# drwxr-xr-x 109 nju33 staff 3488 Feb 5 21:30 ..
# -rw-r--r-- 1 nju33 staff 0 Feb 5 21:30 index.js
# drwxr-xr-x 2 nju33 staff 64 Feb 5 21:30 node_modulescp
ファイルやディレクトリをコピーします。
ls -al
# total 0
# drwxr-xr-x 2 nju33 staff 64 Feb 5 21:30 foo
cp -r foo bar
ls -al
# total 0
# drwxr-xr-x 2 nju33 staff 64 Feb 5 21:30 foo
# drwxr-xr-x 2 nju33 staff 64 Feb 5 21:31 barmv
ファイルやディレクトリを移動します。
ls -al
# total 0
# drwxr-xr-x 2 nju33 staff 64 Feb 5 21:30 foo
mv foo bar
ls -al
# total 0
# drwxr-xr-x 2 nju33 staff 64 Feb 5 21:30 barrm
ファイルやディレクトリを削除します。
ls -al
# drwxr-xr-x 4 nju33 staff 128 Feb 5 21:30 .
# drwxr-xr-x 109 nju33 staff 3488 Feb 5 21:30 ..
# -rw-r--r-- 1 nju33 staff 0 Feb 5 21:30 index.js
# drwxr-xr-x 2 nju33 staff 64 Feb 5 21:30 node_modules
rm index.js
# ディレクトリ削除には -r が必要
rm -r node_modules
ls -al
# drwxr-xr-x 4 nju33 staff 128 Feb 5 21:30 .
# drwxr-xr-x 109 nju33 staff 3488 Feb 5 21:30 ..grep
絞り込み。
ls -al
# total 0
# drwxr-xr-x 3 nju33 staff 96 Feb 5 21:41 .
# drwxr-xr-x 109 nju33 staff 3488 Feb 5 21:30 ..
# -rw-r--r-- 1 nju33 staff 0 Feb 5 21:30 index.js
ls -al | grep index.js
ls -al
# -rw-r--r-- 1 nju33 staff 0 Feb 5 21:30 index.jscat
ファイルの中身を標準出力に出す。
cat index.js
# function hello() {
# console.log(123);
# }
cat index.js | grep console.log
# console.log(123);zip ファイルを作る
-rの後に生成したい zip ファイル名が来るので注意。
zip -r name.zip ../dir-namezip ファイルを展開する
指定した ZIP ファイルを展開します。-d <dest-dir>オプションを使うと展開先のディレクトリを<dest-dir>にできます。
unzip name.zip
unzip name.zip -d foo # foo/ に展開pbcopy
使えるのは、 Mac だけです。標準入力できた内容をクリップボードにコピーします。
echo hello | pbcopy
# 上のあとペーストすると
hello