ドットファイルも含むすべてのファイルを表示する。
test.txt
. .. .test test.txt
ファイルの詳細を表示する。
-rw-r--r-- 1 testuser testgroup 20 2月 27 22:44 test.txt
ファイルの詳細を古い順に表示する。
-rw-r--r-- 1 testuser testgroup 30 1月 25 12:24 test3.txt
-rw-r--r-- 1 testuser testgroup 20 2月 27 22:44 test.txt
-rw-r--r-- 1 testuser testgroup 25 3月 10 23:45 test2.txt
ディレクトリを階層的にファイルの詳細を表示する。
total 2
-rw-r--r-- 1 testuser testgroup 20 2月 27 22:44 test.txt
-rw-r--r-- 1 testuser testgroup 14 3月 15 21:30 test2.txt
drwxr-xr-x 1 testuser testgroup 0 3月 15 21:37 testdir2
testdir/testdir2:
total 1
-rw-r--r-- 1 testuser testgroup 33 3月 15 21:37 test3.txt
標準出力を上書きでリダイレクトする。
bbbb
aaaa
標準出力を追加書きでリダイレクトする。
bbbb
bbbb
aaaa
画面、ファイルの両方に出力する。
cccc
cccc
ファイルの上書きを禁止する。
test.txt
test.txt: File exists.
batをcatに訂正して実行する。
bat: Command not found.
cat test.txt
aaaa
直前のコマンドを再実行する。
aaaa
cat test.txt
aaaa
ヒストリ番号を指定して再実行する。
…
77 22:26 cd testdir
78 22:26 cat test.txt
79 22:26 history
cat test.txt
aaaa
コマンドの一部を指定して再実行する。
…
77 22:26 cd testdir
78 22:26 cat test.txt
79 22:26 history
cat test.txt
aaaa
キーボードで入力した「yamada」を表示する。
#!/bin/csh
echo -n "Enter your name > "
set name = $<
echo "Your name is " $name
Enter your name >
Your name is yamada
test.txtというファイルが存在する場合は「exist」と表示するシェル
#!/bin/csh
if ( -e test.txt ) then
echo "exist"
endif
exist
「ファイル名_日付」というファイル名でバックアップを作成する。
test.txt
cp -p test.txt test.txt_20110310
test.txt test.txt_20110310
「aaa」「bbb」「ccc」ディレクトリを階層的に作成する。
test.txt
bbb
aaa/bbb
ccc
aaa/bbb/ccc
【これがオススメ】
以下のamazonリンクから購入すると齋藤緒のページ作りパワーが劇的にアップします。
「dir2009」「dir2010」「dir2011」ディレクトリを作成する。
test.txt
test.txt dir2009/ dir2010/ dir2011/
「-ppp.txt」という名前のファイルを削除する。
※ rmコマンドだけでは実行時にオプション付きと判断されてエラーとなる。
-ppp.txt test.txt
rm: illegal option 'p'
usage: rm [-dfiPRr] file ...
test.txt
「ls test」の後にCTRL+Dを入力し、「test」に続くファイル名、ディレクトリ名の候補を表示する。
test1.txt test2.txt testdir/
back.cshをバックグラウンドで実行する。
back.csh
#!/bin/csh
set i = 0
while (1)
sleep 2
echo $i > test.log
@ i = $i + 1
end
[1] 475
back.csh test.log
バックグラウンド実行したback.cshのジョブ番号を調べ、一時停止する。
[1] + Running csh back.csh
[1] + Suspended (signal) csh back.csh
一時停止したback.cshのジョブを再開する。
[1] + Suspended (signal) csh back.csh
[1] csh back.csh &
[1] + Running csh back.csh
バックグラウンド実行したback.cshのジョブ番号を調べ、終了する。
[1] + Running csh back.csh
[1] Terminated csh back.csh
back.cshのジョブをログアウト後もバックグラウンドで実行させる。
[1] 585
カレントディレクトリ配下で、ファイルサイズが0のファイルを検索して削除する。
#/bin/csh
foreach file ( `find .` )
if ( -f $file && -z $file ) then
rm -i $file
endif
end
total 2
-rw-r--r-- 1 testuser testgroup 93 3月 20 16:05 test.csh
-rw-r--r-- 1 testuser testgroup 6 3月 20 16:13 test.txt
drwxr-xr-x 1 testuser testgroup 0 3月 20 16:13 testdir
./testdir:
total 0
-rw-r--r-- 1 testuser testgroup 0 3月 20 16:13 kara.txt
remove ./testdir/kara.txt ?
total 2
-rw-r--r-- 1 testuser testgroup 93 3月 20 16:05 test.csh
-rw-r--r-- 1 testuser testgroup 6 3月 20 16:13 test.txt
drwxr-xr-x 1 testuser testgroup 0 3月 20 16:13 testdir
./testdir:
ファイル名「test.txt」を検索して削除する。
total 0
drwxr-xr-x 1 testuser testgroup 0 3月 20 16:24 testdir
./testdir:
total 1
-rw-r--r-- 1 testuser testgroup 14 3月 20 16:24 test.txt
remove ./testdir/test.txt ?
total 0
drwxr-xr-x 1 testuser testgroup 0 3月 20 16:24 testdir
./testdir:
カレントディレクトリ配下のファイルをすべて削除する。(サブディレクトリのファイルも含む)
total 1
-rw-r--r-- 1 testuser testgroup 7 3月 20 16:32 test.txt
drwxr-xr-x 1 testuser testgroup 0 3月 20 16:35 testdir
./testdir:
total 1
-rw-r--r-- 1 testuser testgroup 9 3月 20 16:31 test2.txt
remove ./test.txt ?
remove ./testdir/test2.txt ?
total 0
drwxr-xr-x 1 testuser testgroup 0 3月 20 16:35 testdir
./testdir:
「/home/testuser/dir1」と「/home/testuser/dir2」を素早く移動する。
/home/testuser/dir1
~/testuser/dir2 ~/testuser/dir1
/home/testuser/dir2
~/testuser/dir1 ~/testuser/dir2
/home/testuser/dir1
~/testuser/dir2 ~/testuser/dir1
/home/testuser/dir2
引数で与えられた数字を8桁の文字幅でゼロ埋めし、表示する。
#!/bin/csh
set number = `printf "%08d" $1`
echo $number
00000012
他のシェルにあるgetoptsのようなシェルコマンドがCシェルには無いので、switch-case文でゴリ実装する。
#!/bin/csh
while ($#argv != 0)
switch ($1)
case -l:
ls -l
breaksw
case -a:
ls -a
breaksw
endsw
shift
end
. .. .env test.txt
「YYYY/MM/DD hh:mm:ss」形式でシステム年月日時分秒を表示する。
#!/bin/csh
echo `date +"%Y/%m/%d %H:%M:%S"`
2011/03/20 18:50:48
「/home/testuser/test.txt」からファイル名の箇所のみを表示する。
#!/bin/csh
set file = $1:t
echo $file
test.txt
【これがオススメ】
以下のamazonリンクから購入すると齋藤緒のページ作りパワーが劇的にアップします。