Linux学習ノート(二):ファイルディレクトリ管理とVIMエディタの使用
書類や目次管理は、最初は雑多な内容でしたが、勉強を終えてまとめると、実は筋道が通っていて難しくなく、よく使われる命令を熟練して身につければいいのです。Vimエディタについては、このエディタを使った後、windowsのnotepadは技術的な含有量がないような気がします。
まず、ファイルやディレクトリでよく使われるコマンドを簡単にまとめ、簡単な使い方は省略します。
ファイル操作コマンド:touch、file、which、find、cp、rm、mv、ln
ファイルコンテンツ操作コマンド:cat、more、less、head、tail、wc、grep
ディレクトリ操作コマンド:pwd、cd、ls、mkdir、du
アーカイブおよび圧縮コマンド:gzip、bzip 2、tar
コードのコピー/home/jzhou
[jzhou@localhost~]$mkdir dirtest=>ディレクトリの作成
[jzhou@localhost~]$cd dirtest=>このディレクトリに入ります[jzhou@localhostdirtest]$mkdir dirtest 1=>サブディレクトリの作成
[jzhou@localhostdirtest]$ls=>現在のディレクトリの内容のリスト
dirtest1 testfile
[jzhou@localhostdirtest]$echo hello linux>>testfile=>ファイルへのコンテンツの追加hello linux
[jzhou@localhostdirtest]$file testfile=>ファイルタイプの表示
testfile: ASCII text8.0K testfile
[jzhou@localhostdirtest]$wc testfile=>統計ファイル行数、文字数、文字数
2 12 testfile
[jzhou@localhostdirtest]$echo hahaha,I love Linux>>testfile=>追加内容
[jzhou@localhost dirtest]$ echo no,no ,I hate C plus plus >> testfile
[jzhou@localhost dirtest]$ echo OK,the end >> testfile
[jzhou@localhostdirtest]$cat testfile=>コンテンツの表示
hello linux
haha,I love Linux
no,no ,I hate C plus plus
OK,the end
[jzhou@localhostdirtest]$head-2 testfile=>ファイルの最初の2行の内容を表示
hello linux
haha,I love Linux
[jzhou@localhostdirtest]$tail-2 testfile=>ファイルの最後の2行の内容を表示
no,no ,I hate C plus plus
OK,the end
[jzhou@localhostdirtest]$cat testfile|grep「Linux」特定のキーワードを検索
haha,I love Linux
[jzhou@localhost dirtest]$
以上は一部のコマンドの簡単な使い方を示しただけで、多くのオプションが追加されていません。headとtailコマンドのデフォルトは、最初の10行と後の10行のレコードを表示します。duは、ディレクトリやファイルを表示するスペースで、通常は実際のサイズよりも大きく、通常は4の整数倍です。
moreとlessコマンドもファイルの内容を表示する方法ですが、lessはmoreに取って代わっています。moreのすべての機能lessが持っているので、lessは上へページをめくって見ることができます。moreはできません。catは直接ファイルの内容を画面に表示します。どれだけ長くても、ファイルが長い場合はlessコマンドを使用します。同じように、qキーを押して終了します。
コードのコピー
[jzhou@localhostdirtest]$cd dirtest 1=>さっき建てたサブディレクトリに入ります
[jzhou@localhostdirtest 1]$touch testfile 1=>サブディレクトリに新しいファイルを作成
[jzhou@localhost dirtest1]$ echo haha >> testfile1
[jzhou@localhost dirtest1]$ cd .. ==>前のディレクトリに戻る
[jzhou@localhost dirtest]$ ls
dirtest1 testfile
[jzhou@localhost dirtest]$ cp testfile ./dirtest 1/=>>ファイルtestfileをサブディレクトリdirtest 1にコピー
[jzhou@localhostdirtest]$cd dirtest 1/=>>サブディレクトリへ
[jzhou@localhostdirtest 1]$ls=>サブディレクトリの下にコピーしたファイルが1つ追加されていることを確認します。
testfile testfile1
[jzhou@localhost dirtest1]$ cd ..
[jzhou@localhost dirtest]$ ls
dirtest1 testfile
[jzhou@localhostdirtest]$rm-f testfile=>dirtestディレクトリのtestfileファイルの強制削除
[jzhou@localhostdirtest]$ls=>testfileファイルが削除されました
dirtest1
[jzhou@localhost dirtest]$ cd ./dirtest 1/=>>サブディレクトリへ
[jzhou@localhost dirtest1]$ mv testfile ./testfile=>ここで移動しようとしたターゲットディレクトリエラー
testfile testfile1
[jzhou@localhostdirtest 1]$pwd=>なので、絶対パスを使用するために現在のディレクトリを表示します。
/home/jzhou/dirtest/dirtest1
[jzhou@localhostdirtest 1]$mv testfile/home/jzhou/dirtest/=>testfileファイルをdirtestディレクトリに移動
[jzhou@localhost dirtest1]$ cd ..
[jzhou@localhostdirtest]$ls=>はい、testfileファイルは移動されました。
dirtest1 testfile
[jzhou@localhostdirtest]$ln-s testfile linkfile=>ソフトリンクの作成
[jzhou@localhostdirtest]$ls-l=>次のソフトリンクファイルの表示方法に注意
合計20
drwxrwxr-x 2 jzhou jzhou 4096 03-05 22:43 dirtest1
lrwxrwxrwx 1 jzhou jzhou 8 03-05 22:45 linkfile -> testfile
-rw-rw-r-- 1 jzhou jzhou 67 03-05 22:40 testfile
[jzhou@localhost dirtest]$
rmファイルがファイルとディレクトリに作用する唯一の違いは-rオプションがあるかどうかであり、ディレクトリを削除する際にディレクトリにファイルとディレクトリがネストされている可能性があるため、-rオプションが必要であり、cpとrmのフォーマットはすべてcp/rm元のファイルターゲットファイルである(ここのパスの問題に注意)
lnリンクファイル:ソフトリンクとハードリンクに分けられ、ソフトリンクはシンボルリンクとも呼ばれ、-sオプションがあります。ソフトリンクはwindowsのショートカットに相当し、元のファイルが破損するとショートカットは無効になり、ハードリンクは元のファイルのコピーに相当し、通常、ハードリンクは少ない。したがって、リンクファイルを作成する場合、通常は-sオプションを追加するとソフトリンクが作成されます。リンクファイルのファイルタイプビットは:lで、後続のノートファイル権限でこのビットが紹介されます。
[jzhou@localhost ~]$ cd dirtest/
[jzhou@localhost dirtest]$ ls
dirtest1 linkfile testfile
[jzhou@localhost dirtest]$ tar cf test.tar dirtest 1 testfile=>アーカイブディレクトリとファイル
[jzhou@localhostdirtest]$ls=>新しいアーカイブファイルtestが1つ増えました。tar
dirtest1 linkfile testfile test.tar
[jzhou@localhostdirtest]$rm-rf dirtest 1 testfile=>元のファイルを削除し、後でファイルがアーカイブされているかどうかを確認します。
[jzhou@localhost dirtest]$ ls
linkfile test.tar
/home/jzhou/dirtest
[jzhou@localhost dirtest]$ tar xf test.tar-C/home/jzhou/dirtest/==>アーカイブを解除しtestfileファイルを解放
[jzhou@localhost dirtest]$ ls
dirtest1 linkfile testfile test.tar
[jzhou@localhost dirtest]$ rm -f test.tar=>このアーカイブパッケージを削除すると、後でテストできます。
[jzhou@localhost dirtest]$ ls
dirtest1 linkfile testfile
[jzhou@localhostdirtest]$gzip-9 testfile=>このファイルをgz形式で圧縮
[jzhou@localhost dirtest]$ ls
dirtest1 linkfile testfile.gz=>これが圧縮後に自動的に生成されるファイル名です
[jzhou@localhost dirtest]$ gzip -d testfile.gz=>圧縮したばかりのパケットを解く
[jzhou@localhost dirtest]$ ls
dirtest 1 linkfile testfile=>ほら、testfileが解凍された