Skip to content

Linux リテラシ - 第1回 演習問題 解答

This content is not available in your language yet.

:問題(1):コンソール画面を開き、その時のカレントディレクトリをpwdを用いて確認せよ。

[user@localhost ~]$ pwd
/home/user

:問題(2):ルートディレクトリへcdを用いて移動せよ。また、そこにどのようなファイルがあるかlsを用いて確認せよ。

[user@localhost ~]$ cd /
[user@localhost /]$ pwd
/
[user@localhost /]$ ls
bin dev home lib media mnt proc sbin srv tmp var
boot etc initrd lost+found misc opt root selinux sys usr

:問題(3):ホームディレクトリへ移動せよ。

[user@localhost /]$ cd ~
[user@localhost ~]$ pwd
/home/user

:問題(4):再度ルートディレクトリへ移動せよ。ただし、このときには相対パスを用いること。

[user@localhost ~]$ cd ../..
[user@localhost /]$ pwd
/

:問題(5):ホームディレクトリにどのようなファイルがあるか確認せよ。

[user@localhost /]$ cd ~
[user@localhost ~]$ ls
[user@localhost ~]$ ls -a
. .bash_logout .bashrc .emacs .kde .zshrc
.. .bash_profile .canna .gtkrc .xemacs

:問題(6):lsに-alオプションを指定して、ドットファイルまで含めてどの様なファイルがあるか確認せよ。

[user@localhost ~]$ ls -al
合計 52
drwx------ 4 user user 4096 5月 25 09:58 .
drwxr-xr-x 7 root root 4096 5月 25 09:58 ..
-rw-r--r-- 1 user user 302 5月 25 09:58 .bash_logout
-rw-r--r-- 1 user user 191 5月 25 09:58 .bash_profile
-rw-r--r-- 1 user user 124 5月 25 09:58 .bashrc
-rw-r--r-- 1 user user 5542 5月 25 09:58 .canna
-rw-r--r-- 1 user user 438 5月 25 09:58 .emacs
-rw-r--r-- 1 user user 120 5月 25 09:58 .gtkrc
drwxr-xr-x 3 user user 4096 5月 25 09:58 .kde
drwxr-xr-x 2 user user 4096 5月 25 09:58 .xemacs
-rw-r--r-- 1 user user 658 5月 25 09:58 .zshrc

:問題(7):今後の作業を行うためにホームディレクトリにLiteracyというディレクトリをmkdirを用いて作成せよ。また、実行後にディレクトリが本当に出来たかどうか確認せよ。

[user@localhost ~]$ mkdir Literacy
[user@localhost ~]$ ls
Literacy

:問題(8):~/Literacyディレクトリに移動したあとにwgetを用いてURLにある演習用のファイルをダウロードし、unzipを用いて解凍せよ。

[user@localhost ~]$ cd Literacy/
[user@localhost Literacy]$ wget http://rat.cis.k.hosei.ac.jp/data/lili.zip
--10:03:21-- http://rat.cis.k.hosei.ac.jp/data/lili.zip
=> `lili.zip'
rat.cis.k.hosei.ac.jp をDNSに問いあわせています... 133.25.90.36
rat.cis.k.hosei.ac.jp[133.25.90.36]:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 8,039 [application/zip]
100%[====================================>] 8,039 --.--K/s
10:03:21 (53.99 MB/s) - `lili.zip' saved [8,039/8,039]
[user@localhost Literacy]$ ls
lili.zip
[user@localhost Literacy]$ unzip lili.zip
Archive: lili.zip
inflating: LinuxLiteracy01.tar.gz
[user@localhost Literacy]$ ls
LinuxLiteracy01.tar.gz lili.zip

:問題(9):解凍した結果作成されたLinuxLiteracy.tar.gzをtarを用いて解凍せよ。

[user@localhost Literacy]$ tar -zxf LinuxLiteracy01.tar.gz
[user@localhost Literacy]$ ls
LinuxLiteracy01.tar.gz drill_2 drill_4 drill_6 drill_8 gpl2.txt lili.zip
drill_1 drill_3 drill_5 drill_7 drill_9 hello

tarのオプションは解凍時に-zx(v)f、圧縮時に-c(v)fを指定します。
:問題(10):「ls -F ~/Literacy」というコマンドを実行し何が行われるか確認せよ。-Fオプションを付けないで実行したときと何が違うだろうか。実際に比較したあとに、manを使ってオプションの意味を調べて結果と照らし合わせよ。

[user@localhost Literacy]$ ls ~/Literacy/
LinuxLiteracy01.tar.gz drill_2 drill_4 drill_6 drill_8 gpl2.txt lili.zip
drill_1 drill_3 drill_5 drill_7 drill_9 hello
[user@localhost Literacy]$ ls -F ~/Literacy/
LinuxLiteracy01.tar.gz drill_3/ drill_6/ drill_9/ lili.zip
drill_1/ drill_4/ drill_7/ gpl2.txt
drill_2/ drill_5/ drill_8/ hello

lsの-Fオプションは、ファイルの種類によって末尾に記号を付加します。
drill_*はディレクトリなのでファイル名の後に’/‘が付加されています。
:問題(11):~/Literacy/helloの内容をcatを用いて表示せよ。

[user@localhost Literacy]$ cat hello
Hello! Linux world.

:問題(12):cpを用いてhelloをhello.bakという名前でコピーせよ。また、helloとhello.bakの内容が同じであることを確認せよ。

[user@localhost Literacy]$ cp hello hello.bak
[user@localhost Literacy]$ ls
LinuxLiteracy01.tar.gz drill_2 drill_4 drill_6 drill_8 gpl2.txt hello.bak
drill_1 drill_3 drill_5 drill_7 drill_9 hello lili.zip
[user@localhost Literacy]$ cat hello.bak
Hello! Linux world.

:問題(13):rmを用いてhelloを削除せよ。

[user@localhost Literacy]$ rm hello
[user@localhost Literacy]$ ls
LinuxLiteracy01.tar.gz drill_2 drill_4 drill_6 drill_8 gpl2.txt lili.zip
drill_1 drill_3 drill_5 drill_7 drill_9 hello.bak

:問題(14):mvを用いてhello.bakをhelloという名前に変更せよ。

[user@localhost Literacy]$ mv hello.bak hello
[user@localhost Literacy]$ ls
LinuxLiteracy01.tar.gz drill_2 drill_4 drill_6 drill_8 gpl2.txt lili.zip
drill_1 drill_3 drill_5 drill_7 drill_9 hello
[user@localhost Literacy]$ cat hello
Hello! Linux world.

:問題(15):~/Literacy/gpl2.txtの内容をcatを用いて確認せよ。また、headとtailを用いてファイルの先頭と末尾を表示せよ。

[user@localhost Literacy]$ cat gpl2.txt
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
---------------------------------------------------------------------------------/
[user@localhost Literacy]$ head gpl2.txt
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
---------------------------------------------------------------------------------/
[user@localhost Literacy]$ tail gpl2.txt
---------------------------------------------------------------------------------/
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice

:問題(16):gpl2.txtはサイズが大きくcatで見るのは不便であった。lessを用いての表示を試せ。

[user@localhost Literacy]$ less gpl2.txt
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
---------------------------------------------------------------------------------/

:問題(17):findを用いて~/Literacy以下からsampleという名前を持つファイルを見つけ出せ。

[user@localhost Literacy]$ find ~/Literacy/ -name sample
/home/user/Literacy/drill_4/drill_7/sample
/home/user/Literacy/drill_3/drill_2/sample

:問題(18):~/Literacy/drill_1をdrill_10という名前に変更(移動)せよ。

[user@localhost Literacy]$ mv drill_1 drill_10
[user@localhost Literacy]$ ls
LinuxLiteracy01.tar.gz drill_2 drill_4 drill_6 drill_8 gpl2.txt lili.zip
drill_10 drill_3 drill_5 drill_7 drill_9 hello

:問題(19):~/Literacy/drill_2をdrill_11という名前でコピーせよ。

[user@localhost Literacy]$ cp -r drill_2 drill_11
[user@localhost Literacy]$ ls
LinuxLiteracy01.tar.gz drill_11 drill_3 drill_5 drill_7 drill_9 hello
drill_10 drill_2 drill_4 drill_6 drill_8 gpl2.txt lili.zip

ディレクトリをコピーする場合は-rオプションを指定します。
:問題(20):~/Literacyを削除せよ。

[user@localhost ~]$ rm -r Literacy/

ディレクトリを削除する場合はオプション-rを指定します。