GaGe

Linux 02 본문

SISS (2017-2018)/리눅스

Linux 02

Sorrel 2018. 3. 2. 15:33

<hint0>

문제1.file1의 단어 수, 라인 수, 문자 수를 구하기


문제2. 1) file2의 내용을 줄(행)마다 번호붙여 출력
   2) file2에서 ab가 속한 줄 출력 (대소문자 구분)


문제3. 1) 학번, 이름 text.txt파일에 저장
   2) 이번학기에 공부하고 싶은 분야(시스템해킹vs웹해킹) text.txt파일에 저장
 *학번,이름이 저장된 text.txt파일에 내용 덧붙일 것
 *지에디트 사용금지. 터미널에서 작업할 것


문제4. 1) 숫자를 입력받아 팩토리얼을 구하는 factorial.c파일을 만들고 코드제출 - 이거를 리눅스로 코드 짜기 ( C로 일단 짜놓음)
 *vi, 지에디트 작업 상관 X
   2) factorial.c파일을 컴파일하여 임의의 수 넣고 결과확인하기

 

 

<hint1>

Linux (/?l?n?ks/ (About this sound listen) LIN-?ks)[9][10] is a family of free and open-source software operating systems built around the Linux kernel. Typically, Linux is packaged in a form known as a Linux distribution (or distro for short) for both desktop and server use. The defining component of a Linux distribution is the Linux kernel,[11] an operating system kernel first released on September 17, 1991, by Linus Torvalds.[12][13][14]

Linux was originally developed for personal computers based on the Intel x86 architecture, but has since been ported to more platforms than any other operating system.[15] Because of the dominance of the Linux kernel-based Android OS on smartphones, Linux has the largest installed base of all general-purpose operating systems.[16] Linux is also the leading operating system on servers and other big iron systems such as mainframe computers, and the only OS used on TOP500 supercomputers (since November 2017, having before gradually eliminated all competitors).[17][18] It is used by around 2.3% of desktop computers.[19][20] The Chromebook, which runs the Linux kernel-based Chrome OS, dominates the US K?12 education market and represents nearly 20% of the sub-$300 notebook sales in the US.[21] Linux also runs on embedded systems?devices whose operating system is typically built into the firmware and is highly tailored to the system. This includes TiVo and similar DVR devices, network routers, facility automation controls, televisions,[22][23] video game consoles and smartwatches.[24] Many smartphones and tablet computers run Android and other Linux derivatives.[25]

The development of Linux is one of the most prominent examples of free and open-source software collaboration. The underlying source code may be used, modified and distributed?commercially or non-commercially?by anyone under the terms of its respective licenses, such as the GNU General Public License.

Some of the most popular and mainstream Linux distributions[26][27][28] are Arch Linux, CentOS, Debian, Fedora, Gentoo Linux, Linux Mint, Mageia, openSUSE and Ubuntu, together with commercial distributions such as Red Hat Enterprise Linux and SUSE Linux Enterprise Server. Distributions include the Linux kernel, supporting utilities and libraries, many of which are provided by the GNU Project, and usually a large amount of application software to fulfil the distribution's intended use. Desktop Linux distributions include a windowing system, such as X11, Mir or a Wayland implementation, and an accompanying desktop environment such as GNOME or KDE Plasma; some distributions may also include a less resource-intensive desktop, such as LXDE or Xfce. Distributions intended to run on servers may omit all graphical environments from the standard install, and instead include other software to set up and operate a solution stack such as LAMP. Because Linux is freely redistributable, anyone may create a distribution for any intended use. Many Linux distributions use the word "Linux" in their name. The Free Software Foundation uses the name "GNU/Linux" to refer to the operating system family, as well as specific distributions, to emphasize that most Linux distributions are not just the Linux kernel, and that they have in common not only the kernel, but also numerous utilities and libraries, a large proportion of which are from the GNU project. This has led to some controversy.[29][30]

 

 

<hint2>

a
ab
aBc
Abcd
ABCDEF
abcdeFg
aBcDefGh
abababcdef
abCdEfGHijk
ab/cd/ef/gh/i

 

<문제풀이 프로세스>

이번 문제는 각각 개별적이기 때문에 프로세스가 필요 없다.

 

 

 

<문제 풀이>

 

 

 

일단 힌트 파일들을 열기 편하게 tmp 안에  file 폴더를 만들어 몰아 넣었다.

 

 

 

 

cd /tmp

cd file

cat file1.txt

 

명령어들을 차례로 이용하여

file 텍스트 파일들이 잘 있나 확인해보았다.

잘 있는 것 같다.

 

 

<문제1>

 

 

 

wc -w file1.txt

명령어로 단어수를 세었다.

 

wc -l file1.txt

명령어로 라인수를 세었다.

 

wc -m file1.txt

 명령어로 문자수를 세었다.

 

 

<문제 2-1>

 

 

 

cat -n file2.txt

명령어로 문자열에 번호를 붙여줬다.

 

 

 

 

<문제 2-2>

 

 

 

grep -r 'ab' ./file2.txt로

file2.txt에만 ab라는 단어를 찾는 방법을 했더니 성공!

 

 

 

<문제 3-1>

 

 

 

cat > test.txt

이걸로 학번 + 이름의 내용이 담긴 텍스트 파일을 생성했다.

 

cat >> test.txt

이걸로 기존 test.txt 에 있던 내용에 덧붙여서 내용을 추가했다.

 

 

 

<문제 4-1>

 

 

 

vi factorial.c

라고 치면 factorial.c 파일이 생성되는 동시에 작성이 가능하다.

 

 

 

 

코드를 짠다.

 

 

 

다 짜면 ESC를 누르고 관리모드로 들어간 다음 :wq를 치면 저장이 되고 vi를 빠져나온다.

(:wq!) 이 명령어는 저장 및 강종이다.

 

 

 

 

잘 작성이 되었는지 cat factorial.c로 켜봤다. 잘 된 듯하다.

 

 

 

gcc factorial.c 로 컴파일 하는데 오류가 떴다.

구글링 해봤더니 main 앞에 int가 빠져 오류가 난 것 같다.

 

 

 

 

vi로 다시 편집 모드로 들어가 준 다음, int 를 넣었다.

(관리모드는 ESC 를 누르면 되고 편집 모드는 i를 누르면 된다)

 

 

 

 

 

다시 gcc 로 컴파일 해주니 쥐도새도 모르게 조용히 컴파일을 시켜준다.

 

 

 

 

 

그렇게 컴파일이 되면 그 자리에 a.out  프로그램이 깔린다.

이게 실행 프로그램이다.

 

<문제 4-2>

 

 

그래서 a.out 프로그램을 열어주고

3을 넣어 3*2*1=6을 확인해주었다.

 

끝!

 

'SISS (2017-2018) > 리눅스' 카테고리의 다른 글

linux 04  (0) 2018.03.18
Linux 03  (0) 2018.03.14
Linux 01  (0) 2018.02.24
Comments