Linux

|

CommandsOptionsDescriptione.g.
                                                 File Commands
ls 현재 directory의 파일 목록
-a감춰진 파일까지 모두 표시
-lls를 더 자세히
-al감춰진 파일 더 자세히
-alS감춰진 파일 더 자세히, 파일 크기를 기준으로 sort
pwd 현재 경로
mkdir[이름]현재 directory 하위에 새 directory 만들기
touch[이름]비어 있는 파일 만들기touch  test.txt
rm[파일 이름]파일 삭제rm  test.txt
-r [디렉토리 이름]디렉토리 삭제rm -r testdirectory
cpA BA를 B에 복사cp  test.txt  ./test2
mvA BA를 B에 옮기기mv  ./test/test.txt ./test2
(./test에 있는 test.txt를 ./test2로 옮김
A B이름 바꾸기도 가능mv  ./test2/test.txt  ./test2/test2.txt
(test.txt를 test2.txt로 바꿈)
cat[파일 이름]파일 내용 보기cat  test.txt
tail-n [번호]마지막에서 n번째 줄까지 출력tail -n 2 test.txt
test.txt파일에서2번째 라인까지 출력
-f추가 될 때마다 출력tail -f date.log
date.log에 추가되는 걸 출력해라
head-n [번호]n번째 줄까지 출력
more[파일 이름]텍스트 파일 보기more test.txt
less[파일 이름]텍스트 파일 보기(more보다 화면 이동이 자유로움)less test.txt
                                                 Directory Traverse
cd[directory]directory 변경
..부모 디렉토리로
~home directory
                                                 Process Related
ps 프로세스 확인하기
aux더 자세히 확인하기ps aux | grep apache
(프로세스 중에 'apache'들어 간 거를 찾아서 자세히 확인하겠다.)
top 프로세스 정보(작업 관리자)
htop top을 좀 더 잘 보여 줌
kill%[jobs 번호]실행 중인 작업 종료kill %2
kill -9 %2
                                                         Search
grep 일반적으로 다른 명령어와 함께 쓰이며, 특정 문자열을 찾을 때 사용ps aux | grep python
locate[찾을 거]mlocate라는 (이름만 담겨 있는)데이터베이스에서 찾음locate *.log
이 컴퓨터에 확장자가 .log인 파일을 다 찾아라
find 실제 파일들 뒤져서 찾음
.현재 directory부터 찾는다
/root directory부터 찾는다
~home directory부터
                                                       System Info
date[--option]시스템 날짜 관련 명령어date -s 06:14:00 (시스템 시간을 6시 14분 00초로 설정)
jobs 실행 중인 작업 표시
free 메모리 사용량 확인
whereis[command]실행 파일이 어디 있는지 찾아 줌whereis ls
man[command]설명 보기man ls
검색:'/'(ex)/sort)
--help 설명 보기ls  --help
                                                 System Management
cron service cron start(crontab 시작)
service cron stop(crontab 중지)status
service cron rastart(crontab 재시작)
특정 시간에 특정 작업을 하는 데몬을 Cron이라고 함.
예약 작업에서 많이 사용됨.(반복된 시간에 반복된 작업을 해야하는 작업)
crontab Cron이 언제 무엇을 하는지 특정 파일에 저장하는 것을 Crontab이라고 함.
즉, Cron이라는 데몬이 원하는 시간에 원하는 명령 또는 프로그램 을 수행하도록 명령 리스트를 만드는 것이 Crontab이다.
crontab -e(crontab edit)
crontab -l(crontab 작업 내용 확인)
crontab -ㄱ(crontab 작업 전체 삭제)
nohup no hang up. 세션을 끊지 말고 데몬 형태로 실행(명령어 뒤에 &를 붙이면 background로 실행)nohup ./run.sh & (back에서 돌리기)
ps -ef | grep run.sh (background에서 도는 거 확인)
nohup ./run.sh > run_log.log (로그파일 저장)
systemctl 서버 재가동 시 서비스 재실행하는 것에 많이 사용됨(https://priming.tistory.com/73)[https://priming.tistory.com/73]
                                                                 etc 
clear 명령창 깨끗하게
> Input Output Redirectionls -l > result.txt
원래 화면에 출력되어야 할 것의 방향을 돌려서 파일에 저장

Cron

정기적으로 해야할 작업을 처리할 때 사용

crontab -e에 작업을 등록하면 cron이 정기적으로 처리해 줌

m(분) h(시간) dom(일) mon(월) dow(요일) command(명령)

*/1 * * * * date » date.log => 1분에 한 번씩 date정보를 date.log에 저장

Package Manager

CommandsDescriptione.g.
apt-get updateapt라는 package manager server에 접속해서 최신 상태의 소프트웨어 목록을 다운 받음sudo apt-get update
apt-cache search [file]저장되어 있는 것(cache) 검색한다(search)(q누르면 나가짐)sudo apt-cache search htop
apt-get install [file]다운 받기sudo apt-get install htop
apt-get upgrade [file]설치된 파일 업그레이드sudo apt-get upgrade htop
sudo apt-get upgrade만 하면 다 업그레이드
apt-get remove [file]삭제sudo apt-get remove htop
  • update는 설치할 수 있는 목록을 최신상태로 유지하는 거
  • upgrade는 설치한 프로그램을 업그레이드 하는 거