9/2 TIL

정민세·2022년 9월 2일
0

CLI (Command-Line Interface) 명령어

오늘은 CLI의 명령어에 대해서 배웠다.

pwd : print working directory의 약자로, 현재 위치하고 있는 경로를 표시해준다.
mkdir : make directories의 약자로, 해당 경로에 폴더를 만들어 준다. ex) mkdir helloWorld
li : list의 약자로 현재 위치하고 있는 곳의 폴더들을 리스트로 표시해준다.

  • ls -l : 파일의 포맷을 전부 표현
  • ls -a : 숨어있는 폴더나 파일을 포함한 모든 항목을 표현
  • ls -al or ls -la : 위 모든 것을 한 번에 표현
  • open . : 현재 위치한 경로를 폴더로 열어준다.
    cd : change directory의 약자로, 경로로 진입해준다. ex)cd helloWorld

  • cd ~ 을 하면 경로를 초기화 해준다.
  • touch : 파일을 생성해준다. ex) touch hello.txt
    cat : 파일을 터미널에서 실행시켜준다.ex) cat hello.txt
    sudo : 사용자 환경에서, 관리자 권한을 획득한다.
    rm : remove의 약자로, 파일을 삭제한다.(휴지통으로 가지 않음) ex) rm hello.txt(파일 삭제) , rm -rf hello (폴더삭제)
    mv : move의 약자로, 파일이나 폴더를 이동시킨다. ex)mv hello.txt hi (hello.txt를 hi 폴더로),
    mv hello.txt hi.txt (hello.txt를 hi.txt로 이름변경을 해준다.)
    cp : copy의 약자로 폴더나 파일을 복사할 때 사용한다.
    ex)cp helloWorld.txt hiComputer.txt (원본파일 이름 복사할 파일 이름)

    nvm : Node Version Manager

    node.js의 버전을 손쉽게 바꿀 수 있는 매니저

    npm : Node Package Manager

    필요한 모듈을 다운로드 할 수 있는 모듈 스토어
    node.js 생태계의 패키지 매니저다.

    모듈을 사용한 짝수 생성기

    const { range } = require('range'); // range 모듈을 불러옵니다
    
    function getListMultiplesOfTwo(upTo) {
      return range(2, upTo+2, 2);
      // 100을 입력 했을 때 100까지의 2의 배수를 출력한다.
    }
    
    module.exports = getListMultiplesOfTwo;

    CLI , node.js, nvm, npm, 모듈 모두 처음 사용해보는 것들이라 아직까지도 어렵고 적용하기가 너무 힘들었다. 앞으로 자주 쓰이겠지만 내가 적응을 할지 모르겠다.... 차근차근 손에 익히는 방법 밖에는 ... 시간이 약이다.

    배열(Array) []

    #method

    Array.isArray() : 인자가 Array 인지 판별

        Array.isArray([1, 2, 3]);  // true
        Array.isArray({foo: 123}); // false
        Array.isArray('foobar');   // false
        Array.isArray(undefined);  // false

    원본 배열을 수정하는 #method

    let arr = [1,2,3];

    Array pop() : 배열의 마지막 요소를 제거한 후 제거한 요소를 반환

    arr.pop();  // 3

    Array push() : 배열의 마지막에 새로운 요소를 추가한 후, 변경된 배열의 길이를 반환

    arr.push('number');  // 3
    console.log(arr);  //-> [1, 2, 'number']

    Array shift() : 배열의 첫 번째 요소를 제거한 후, 제거한 요소를 반환

    arr.shift();  // 1

    Array unshift() : 배열의 첫 번째 자리에 새로운 요소를 추가한 후, 변경된 배열의 길이를 반환

    arr.unshift("hi");  // 3
    console.log(arr);  //-> [ 1, 2, 'hi' ]

    Array splice() : 배열의 특정 위치에 배열 요소를 추가하거나 삭제하는데 사용. 리턴값은 삭제한 배열 요소. 삭제한 요소가 없더라도 빈 배열을 반환

    arr.splice(4,0,4,5,6); // arr = [1,2,3,4,5,6]
    arr.splice(3,3); // arr = [1,2,3]

    Array reverse() : 배열 요소의 순서를 뒤집어 반환

    arr.reverse(); // arr = [3, 2, 1]

    Array sort() : 배열 내부의 요소를 오름차순으로 정렬

    let arr = [11, 1, 115, 32, 12];
    arr.sort() // arr = [1, 11, 115, 12, 42]

    원본 배열을 수정하지 않고 새로운 배열로 반환하는 #method

    Array join(separator) : 배열의 각 요소를 구분할 문자열을 지정

    let arr = ['h','e','l','l','o'];
    console.log(arr.join()); // 'h,e,l,l,o'
    console.log(arr.join('')); // 'hello'
    console.log(arr.join('+ ')); // 'h+ e+ l+ l+ o"

    Array indexOf() : 문자열의 인덱스 찾기(정수 리턴)

    let arr = ['apple', 'banana', 'peach'];
    console.log(arr.indexOf('apple')); // 0
    console.log(arr.indexOf('peach')); // 2
    console.log(arr.indexOf('dog')); // -1

    Array includes() : 문자열 포함여부 확인(boolean 리턴)

    let num = [1, 2, 3];
    console.log(num.includes(2)); // true
    console.log(num.includes(4)); // false
    console.log(num.includes(3,3)); // false
    conosle.log(num.includes(3,-1)); // true 

    Array slice() : 배열 추출

    let num = [1, 2, 3, 4, 5];
    console.log(num.slice(0)); // [1, 2, 3, 4, 5]
    console.log(num.slice(2)); // [3, 4, 5]
    console.log(num.slice(2, 4)); // [3, 4]
    console.log(num.slice(-3,5)); // [3, 4, 5]

    Array toString() : 배열을 문자열로 반환

    let num = ['one', 2, 'three', 4, 5, 'six'];
    conosle.log(num.toString()); // 'one,2,three,4,5,six'
    profile
    하잇

    0개의 댓글