UNIXコマンド、シェルスクリプトのお勉強
- Unix Command
- vim
- link
- user, group
- permission
- command make
- pathを通す
- 管理者user
- chown
- text operation
- redirection,pipe
- ワイルドカード
- find,xargs
- ブレース展開
- shell
- ディレクトリ
- 参考
Unix Command
mkdir app{1..40}
clear
cd
rmdir
ls
cat text.txt : 全文表示
less text.txt
- /<検索したいワード>
mv
ctrl+r :直近のコマンドを探す
history : 履歴を呼び出す
!<historyで出たID> : 履歴のコマンドを実行
cd !$ : commadに渡した最後の文字を利用する
!pw : pwから始まる直近のコマンドを実行できる
man ls
mkdir --help
touch
vim
vi
command mode: esc key
保存->:w
抜ける->:q
編集モード: i
link
ln -s
unlink
user, group
cat /etc/passwd
cat /etc/group
groups
permission
rwxrw-r--
rwx : user
rw- : group
r-- : other
read,write,execute
chmod g+x
chmod go+x
chmod a-x
rwx : 4+2+1 = 7
rw- : 4+2+0 = 6
r-- : 4+0+0 = 4
chmod 764
command make
type cat
vi hi
#!/bin/bash echo "hi!"
chmod u+x hi
./hi
pathを通す
- echo $PATH
ここから探してコマンドを実行する
printenv
export PATH=/
:$PATH hi
which hi
管理者user
ls -l /var/log/message
cat !$
su -l : root userに切り替える
cat /var/log/messages
sudo cat /var/log/messages
chown
cp /var/log/messages .
sudo !!
cat messages
sudo chown
: messages cat messages
text operation
wc -l messages
head messages
head -n 3 messages
tail -n 3 messages
grep 'etc' messages
redirection,pipe
echo "date" > cmd.txt
cat cmd.txt
echo "free" >> cmd.txt
bash < cmd.txt
bash < cmd.txt > result.txt
cat result.txt
ワイルドカード
ls /etc/*.conf
ls /etc/c??.*
find,xargs
find /etc -name "http*"
sudo !!
find /etc -name "http*" -type f -exec wc -l {} +
find /etc -name "http*" -type f | xargs wc -l
ブレース展開
echo {a,b,c}
echo {1..10}
echo {1..10}{a..g}
make test && cd test
mkdir app{1..5}
touch app{1..5}/test{1..3}{.txt,.jpeg,.gif}
rm app{1..5}/test{1..3}{.jpeg,.gif}
shell
./hello a aa aaa
#!/bin/bash # comment # $1, $2, ... echo "hello $1" echo $0 # ./hello echo $# # 3 echo $@ # $* a aa aaa greeting="hello" #space入れちゃダメ! echo "hello world" echo 'hello world' echo "hello robot" echo "$greeting world" echo '$greeting world' #展開されない echo "${greeting}robot" echo "foo"; echo "bar"
ディレクトリ
bin:実行コマンド
etc:設定
home:各ユーザー
sbin:システム管理用のコマンド
usr:一般的なアプリケーション
var:システムのログファイル