kunsu's archive
이곳은 그냥 나를 위한 개인적인 아카이브입니다 :)
Wednesday, March 6, 2019
python 리눅스 명령어 실행
bash에 익숙하다면 아래와 같이 linux 명령어를 python 내에서 바로 실행할 수 있다.
import os
import sys
os.system ('ls -al | grep "user")
만약 출력된 내용을 얻고자 한다면, subprocess를 이용하면 된다.
import subprocess
result = subprocess.check_output ('./program' , shell=True)
참고:
http://noplanlife.com/?p=949
python 파일 존재 확인하기
심플하게 아래와 같이 os.path를 import 하고 exists 함수를 이용하면 True or False로 결과를 리턴한다.
import os.path
os.path.exists(file_path)
Tuesday, March 5, 2019
grep 명령어를 이용해 파일 속 내용 찾기
일반적으로 grep 명령어를 이용해서 특정한 문자열을 찾을 수 있다. 예를 들면
> ps -ef | grep python
과 같이 특정 문자열이 포함된 라인만 출력을 할 때 주로 사용해왔으나, grep은 파일 안에 있는 내용을 직접적으로 찾을 수 있는 명령어이다.
> grep -r "aaa" ./*
현재 폴더의 모든 파일들 중에 aaa를 포함한 파일을 찾아준다.
참고: https://ngee.tistory.com/83
Thursday, February 28, 2019
리눅스 파일 라인으로 자르기 -- split
가끔 리스트 파일을 여러개로 나눌일이 있다. 전체 리스트를 여러개의 서브 리스트로 나눌때,
split라는 명령어를 쓰면 간단하게 나눌 수 있다.
split -d -a 3 -l 100 full_LOP.list list/list_
full_LOP.list를 100줄 단위로 list/list_XXX로 잘라준다.
참조:
https://bigsun84.tistory.com/310
Newer Posts
Older Posts
Home
Subscribe to:
Posts (Atom)