[Ubuntu] Word Count

OS/Linux 2017. 1. 19. 15:47

Ubuntu 환경의 쉘에서 특정 word를 count하거나 특정 파일의 라인수를 카운트하는 wc 명령에 대해 알아보자.


$ wc --help

Usage: wc [OPTION]... [FILE]... or: wc [OPTION]... --files0-from=F Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified. A word is a non-zero-length sequence of characters delimited by white space. With no FILE, or when FILE is -, read standard input. The options below may be used to select which counts are printed, always in the following order: newline, word, character, byte, maximum line length. -c, --bytes print the byte counts -m, --chars print the character counts -l, --lines print the newline counts --files0-from=F read input from the files specified by NUL-terminated names in file F; If F is - then read names from standard input -L, --max-line-length print the maximum display width -w, --words print the word counts --help display this help and exit --version output version information and exit GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Full documentation at: <http://www.gnu.org/software/coreutils/wc> or available locally via: info '(coreutils) wc invocation'

wc 명령은 다음과 같이 여러가지로 이용가능하다.
  • 특정 파일의 라인수 카운트

$ wc -l test.md

42 test.md
  • 특정 문자 카운트

    $ cat test.md | grep config | wc -l

    4 $ cat /proc/cpuinfo | grep processor | wc -l 8


    'OS > Linux' 카테고리의 다른 글

    [Ubuntu] sudo 권한 등록  (0) 2017.08.09
    [Ubuntu] hostname 변경  (0) 2017.01.19
    [Ubuntu] Memory 확인  (0) 2017.01.19
    [Ubuntu] Filesystem 용량 확인  (0) 2017.01.19
    [Ubuntu] 커널버전 및 Ubuntu 버전 확인  (0) 2017.01.18
    Posted by leechwin
    ,

    [Ubuntu] Memory 확인

    OS/Linux 2017. 1. 19. 11:59

    Ubuntu 환경에서 현재 메모리 사용량을 free 명령을 통해 알 수 있다.

    $ free -h

    total used free shared buff/cache available Mem: 7.8G 2.3G 3.6G 161M 1.9G 5.0G Swap: 46G 472K 46G



    $ free --help

    Usage: free [options] Options: -b, --bytes show output in bytes -k, --kilo show output in kilobytes -m, --mega show output in megabytes -g, --giga show output in gigabytes --tera show output in terabytes -h, --human show human-readable output --si use powers of 1000 not 1024 -l, --lohi show detailed low and high memory statistics -t, --total show total for RAM + swap -s N, --seconds N repeat printing every N seconds -c N, --count N repeat printing N times, then exit -w, --wide wide output --help display this help and exit -V, --version output version information and exit



    'OS > Linux' 카테고리의 다른 글

    [Ubuntu] hostname 변경  (0) 2017.01.19
    [Ubuntu] Word Count  (0) 2017.01.19
    [Ubuntu] Filesystem 용량 확인  (0) 2017.01.19
    [Ubuntu] 커널버전 및 Ubuntu 버전 확인  (0) 2017.01.18
    [Ubuntu] deb 파일 설치가 잘 안되는 경우  (0) 2017.01.05
    Posted by leechwin
    ,

    Ubuntu 환경에서 현재 Filesystem 사용량을 df 명령을 통해 알 수 있다.

    아래의 예제로는 현재 159G의 용량을 사용가능하다.

    $ df -h

    Filesystem Size Used Avail Use% Mounted on udev 3.9G 0 3.9G 0% /dev tmpfs 794M 9.7M 785M 2% /run /dev/sda2 184G 16G 159G 10% / tmpfs 3.9G 86M 3.8G 3% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup tmpfs 794M 48K 794M 1% /run/user/1000

    $ df --help

    Usage: df [OPTION]... [FILE]... Show information about the file system on which each FILE resides, or all file systems by default. Mandatory arguments to long options are mandatory for short options too. -a, --all include pseudo, duplicate, inaccessible file systems -B, --block-size=SIZE scale sizes by SIZE before printing them; e.g., '-BM' prints sizes in units of 1,048,576 bytes; see SIZE format below -h, --human-readable print sizes in powers of 1024 (e.g., 1023M) -H, --si print sizes in powers of 1000 (e.g., 1.1G) -i, --inodes list inode information instead of block usage -k like --block-size=1K -l, --local limit listing to local file systems --no-sync do not invoke sync before getting usage info (default) --output[=FIELD_LIST] use the output format defined by FIELD_LIST, or print all fields if FIELD_LIST is omitted. -P, --portability use the POSIX output format --sync invoke sync before getting usage info --total elide all entries insignificant to available space, and produce a grand total -t, --type=TYPE limit listing to file systems of type TYPE -T, --print-type print file system type -x, --exclude-type=TYPE limit listing to file systems not of type TYPE -v (ignored) --help display this help and exit --version output version information and exit Display values are in units of the first available SIZE from --block-size, and the DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables. Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set). The SIZE argument is an integer and optional unit (example: 10K is 10*1024). Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000). FIELD_LIST is a comma-separated list of columns to be included. Valid field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent', 'size', 'used', 'avail', 'pcent', 'file' and 'target' (see info page). GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Full documentation at: <http://www.gnu.org/software/coreutils/df> or available locally via: info '(coreutils) df invocation'


    'OS > Linux' 카테고리의 다른 글

    [Ubuntu] Word Count  (0) 2017.01.19
    [Ubuntu] Memory 확인  (0) 2017.01.19
    [Ubuntu] 커널버전 및 Ubuntu 버전 확인  (0) 2017.01.18
    [Ubuntu] deb 파일 설치가 잘 안되는 경우  (0) 2017.01.05
    [Jenkins] Jenkins 업데이트  (0) 2016.01.19
    Posted by leechwin
    ,

    Ubuntu 환경에서 커널버전 및 Ubuntu 버전을 확인하는 법에 대해 알아보자.


    커널버전 알아보기

      $ uname -a Linux leechwin-linux 4.4.0-59-generic #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux $ cat /proc/version Linux version 4.4.0-59-generic (buildd@lgw01-11) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) ) #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 2017

    Ubuntu 버전확인하기

      $ cat /etc/issue Ubuntu 16.04.1 LTS \n \l $ cat /etc/*release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=16.04 DISTRIB_CODENAME=xenial DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS" NAME="Ubuntu" VERSION="16.04.1 LTS (Xenial Xerus)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 16.04.1 LTS" VERSION_ID="16.04" HOME_URL="http://www.ubuntu.com/" SUPPORT_URL="http://help.ubuntu.com/" BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" VERSION_CODENAME=xenial UBUNTU_CODENAME=xenial $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.1 LTS Release: 16.04 Codename: xenial

    참고로 /etc/issue 파일은 내부에서 콘솔 로그인시 출력해주는 메시지이다.

    Posted by leechwin
    ,

    Ubuntu 16.04이상에서 다운받은 deb 패키지 파일이 더블클릭으로 설치가 잘 안되는 경우가 있다.

    이때 다음과 같은 방법으로 해결이 가능하다.


    1.GDebi 패키지 설치

      • $ sudo apt-get install gdebi

      • open GDebi and click File -> Open and navigate to the downloaded DEB file.


    2. Command line에서 다음과 같이 수행

      • $ sudo dpkg -i downloaded.deb $ sudo apt-get -f install


    Reference: http://askubuntu.com/questions/760638/problem-with-deb-packages-on-ubuntu-16-04

    Posted by leechwin
    ,

    Jenkins 의 버전을 업데이트 하고 싶을때 수동으로 war 파일만 다운받아 교체하고 싶은경우 다음과 같이 진행한다.

    • 구동중인 Jenkins 중지
      • $ service jenkins stop

    • war 파일을 다운받아 다음 경로에 복사
      • $ sudo mv jenkins.war /usr/share/jenkins

    • Jenkins 재가동
      • $ service jenkins start

    이후 업데이트된 버전의 Jenkins 가 반영되어 가동된다.

    Posted by leechwin
    ,

    Ubuntu 에서 SSD 카드 사용하려고 할때 가끔 Unable to mount.. 로 시작하는 에러가 발생하면서 SD 카드를 인식 못하는 경우가 있다.

    원인은 SSD카드가 Windows 환경에서 포멧되어 사용중인 파일시스템을 리눅스에서 인지를 못하는 문제이다.

    이 문제를 해결하려면 리눅스에 해당 파일 시스템을 인식 할 수 있는 모듈을 다음과 같이 설치하면 해결이 된다.

    • sudo apt-get install exfat-fuse

    위의 모듈이 성공적으로 설치되면 SD 카드가 정상적으로 인식된다.

    Reference: http://askubuntu.com/questions/664765/unable-to-mount-128gb-micro-sdxc-storage-card



    Posted by leechwin
    ,

    Jenkins Plugin 개발시에 빌드 패키징을 위한 maven 설치 방법


    Ubuntu

    • Java가 설치되어 있고 JAVA_HOME 환경변수 설정이 되어 있어야 한다.
      •  export JAVA_HOME=/path/your/jdk
         export PATH=$JAVA_HOME/bin:$PATH

    • apt-get 을 통하여 설치
      • sudo apt-get install maven2
    • ~/.m2/settings.xml 파일을 수정하거나 없다면 새로생성 (윈도우는 %USERPROFILE%\.m2\settings.xml)
      • <settings>

          <pluginGroups>

            <pluginGroup>org.jenkins-ci.tools</pluginGroup>

          </pluginGroups>


          <profiles>

            <!-- Give access to Jenkins plugins -->

            <profile>

              <id>jenkins</id>

              <activation>

                <activeByDefault>true</activeByDefault> <!-- change this to false, if you don't like to have it on per default -->

              </activation>

              <repositories>

                <repository>

                  <id>repo.jenkins-ci.org</id>

                  <url>http://repo.jenkins-ci.org/public/</url>

                </repository>

              </repositories>

              <pluginRepositories>

                <pluginRepository>

                  <id>repo.jenkins-ci.org</id>

                  <url>http://repo.jenkins-ci.org/public/</url>

                </pluginRepository>

              </pluginRepositories>

            </profile>

          </profiles>

          <mirrors>

            <mirror>

              <id>repo.jenkins-ci.org</id>

              <url>http://repo.jenkins-ci.org/public/</url>

              <mirrorOf>m.g.o-public</mirrorOf>

            </mirror>

          </mirrors>

          <!-- 프록시 설정 -->

          <proxies>

            <proxy>

              <id>optional2</id>

              <active>true</active>

              <protocol>https</protocol>

              <host>[Proxy URL]</host>

              <port>[Port]</port> 

            </proxy>

          </proxies>

        </settings> 

    • 다음 명령을 통하여 필요한 패키지를 설치
      • $ mvn -U org.jenkins-ci.tools:maven-hpi-plugin:create
    • Jenkins Plugin 개발 경로에서 패키징 실행
      • $ mvn package


    Reference: https://wiki.jenkins-ci.org/display/JENKINS/Plugin+tutorial

    Posted by leechwin
    ,

    Ubuntu 를 새로 설치하고 apt-get 등의 작업을 할때 Bad header line 이라는 에러와 함께 패키지 정보를 가져오지 못하고 에러가 발생하는 경우가 있다.

    이때에는 apt-get clean 이후 apt-get update 등을 수행해도 제대로 동작하지 않는다.

    이를 해결하기 위해서는 다음과 같이 수행한다.

    • Update Manger > Settings... > Ubuntu Software > Download from > Main Server
    • 아래의 명령으로 source list를 삭제한 후 새로 update를 수행
      • sudo rm -rf /var/lib/apt/lists/* && sudo apt-get update

    위의 순서대로 수행하면 apt-get update 가 에러없이 수행된다.


    만약 사내등에서 Proxy 를 쓰고 있다면 다음과 같이 proxy 설정을 해주어야 한다.

    • /etc/apt/apt.conf 파일에 해당 프록시 주소를 설정한다.
      • Acquire::http::Proxy "http://111.111.111.111:8080/"; Acquire::https::Proxy "https://111.111.111.111:8080/";

    • 이후 apt-get clean 과 apt-get update 를 수행한다.


    Reference: http://askubuntu.com/questions/162782/apt-get-update-bad-header-line-on-all-udpates

    Posted by leechwin
    ,

    Bash Strict Mode

    OS/Linux 2016. 1. 3. 20:09

    Bash Shell Script 작성시 다음과 같이 시작하면 안전한 스크립트를 작성 할 수 있다.

    #!/bin/bash
    set -euo pipefail
    IFS=$'\n\t'
    
    • set -e 옵션
      • 첫번째 에러에서 스크립트를 취소(0이 아닌 상태로 종료하는명령어)하는 옵션
      • 스크립트 에러시 정상종료상태인 0을 리턴받아 다음 스크립트가 진행된다면 마지막 스크립트까지 진행되는 경우 원하지 않는 결과가 수행될 수 있다.
    • set -u 옵션
      • 정의 안 된 변수 사용시 에러 메세지 출력후 강제 종료하는 옵션
    • set -o pipefail 옵션
      • pipeline으로 실행된 경우 에러발생시 에러코드 및 메시지를 전달하는 옵션

    Reference


    Posted by leechwin
    ,