Linux Programming #3

박진우·2022년 8월 4일
0

Linux

목록 보기
3/7

💡 vi 에디터를 이용한 간단한 코딩

◽ 기본 치환 방법

  • 먼저 ex_sub.c 라는 c언어 파일을 cat명령어를 이용해서 작성한다.
#include <stdio.h>
#include <stdlib.h>

void csub(void) {
	int valueOne , valueTwo;
	
	valueOne = rand() % 10 + 1;
	valueTwo = rand() % 10 + 1;

	print("Max random value %d\n" , RAND_MAX );
	print("two generated Numbers %d , %d \n" , valueOne , valueTwo );
}

%s/print/printf/g 로 print를 printf 로 변경한다. (치환)




◽ c언어 컴파일

  • 먼저 ex_main.c라는 c언어 파일을 cat명령어를 이용해서 작성한다.
#include <stdio.h>
#include <time.h>
#include <stdlib.h>

void csub(void);

int main(int argc , char* argv[] ) {

	csub( );	

	return 0;
}


  • 그 다음 아래와 같은 명령어를 사용하여 분할 컴파일링크하고 실행을 한다.

    gcc –c ex_main.c
    gcc –c ex_sub.c
    gcc ex_main.o ex_sub.o –o ex_run.out
    ./ex_run.out

참고로 C언어로 작성한 프로그램을 컴파일하려면 CC 컴파일러가 필요하다. 리눅스의 C 컴파일러는 gcc이다.

행 파일의 이름을 지정하지 않았기 때문에 a.out으로 생성되고, ex_run.out이라는 실행 파일이 생긴걸 볼 수 있다.




◽ Java

  • 먼저 자바 프로그램( Example1.java )을 작성한다.
class Coord{
	private int pos_x;
	private int pos_y;

	public Coord( int pos_x , int pos_y) {
              this.pos_x = pos_x;
              this.pos_y = pos_y;
	}
	public int getPos_x() {
		return pos_x;
	}
	public int getPos_y() {
		return pos_y;
	}
	public void setPos_x(int a) {
		pos_x = a;
	}
	public void setPos_y(int a) {
		pos_y = a;
	}
	public void moveXY(int x,int y) {
		pos_x += x;
		pos_y += y;
	}
	public String toString(){
		return "coordinate X:" + pos_x + " Y:" + pos_y ;
	}
}

class Example1 {
	public static void main(String[] args) {
		Coord crd1 = new Coord(10,20);
		System.out.println( crd1.toString() );
                crd1.setPos_x(10);
                crd1.setPos_y(20);
		System.out.println( crd1.toString() );
		crd1.moveXY(20,30);
		System.out.println( crd1 );
		System.out.println("X:" + crd1.getPos_x() + " Y:" + crd1.getPos_y());
	}
}
  • 그 다음에 javac 를 이용해서 Example1.java를 컴파일 해주고 java를 이용해서 실행을 한다.




◽ Python

  • 먼저 hw5.py라는 이름의 파이썬 파일을 작성한다.
#python example

 x = int( input("enter the first number:") )
 y = int( input("enter the second number:") )
 
 sum = x + y
 avg = float(sum) / 2
 print("sum : "  , sum)
 print("average : " , avg)
 

python3 명령어를 이용해서 파이썬 파일을 실행한다




💡 관리자 명령어

◽ adduser

  • adduser 명령으로 student 계정을 생성한다.(관리자 명령어인 sudo를 사용)


◽ useradd

  • useradd 명령으로 guest 계정을 생성한다.


◽ usermod

  • usermod 명령으로 guest 계정의 쉘을 csh 로 변경한다.

◽ userdel

  • userdel 명령으로 홈디렉토리와 메일 디렉토리를 포함한 guest 계정을 삭제한다.


◽ groupadd

  • groupadd 명령으로 guest 그룹을 생성한다.


◽ groupmod

  • groupmod 명령으로 guest 그룹을 student 그룹으로 변경한다.


◽ useradd

  • useradd 명령으로 guest 계정을 student 그룹으로 지정해서 생성한다.

◽ w

  • w명령으로 전체 접속 사용자를 확인한다.


0개의 댓글