서버/Linux

[Linux] 우분투 리눅스 기본 명령어(ls, cd, rm cp, touch, mv, mkdir, rmdir, cat, head, tail, grep, Linux Redirection)

비전공개미 2022. 11. 2. 17:11
반응형
SMALL

ls

pwd  --  현재 디렉토리 확인

ls  --  현재 디렉토리 목록 확인

ls -l  --  현재 디렉토리 목록 자세히 확인

ls -al  --  현재 디렉토리 목록 자세히 확인(숨김파일 포함)

ls -al /home/user  --  /home/user 디렉토리 안에 있는 목록 자세히 확인(경로설정)

 

 

cd

cd  --  사용자의 홈 디렉토리로 바로이동

cd ~ user  --  사용자(user)의 홈 디렉토리로 이동

cd ..  --  상위 디렉토리로 이동

cd /home/user  --  /home/user 디렉토리로 바로이동(경로설정)

 

rm

rm -f test.txt  --  test.txt 파일을 바로 삭제

 

cp

cp test.txt test1.txt  --  test.txt파일을 text1.txt파일명으로 변경해서 복사

cp -r aaa bbb  --  aaa디렉토리를 bbb디렉토리명으로 변경해서 복사

 

touch

touch test.txt  --  test.txt파일이 없을 경우 빈 파일로 생성

 

mv

mv test.txt test1.txt  --  test.txt파일을 test1.txt로 파일명 변경

mv test.txt /home/user1  --  test.txt파일을 /home/user1 디렉토리로 이동

 

mkdir

mkdir test  --  test디렉토리를 생성

 

rmdir

rmdir test  --  test디렉토리를 삭제

 

cat

cat test.txt  --  test.txt파일의 내용을 출력한다

cat test.txt test1.txt  --  test.txt파일과 text1.txt파일을 다같이 출력한다

 

head

head /etc/passwd  --  passwd파일의 맨위 10줄만 출력온다

head -5 /etc/passwd  --  passwd파일의 맨위 5줄만 출력한다

 

tail

tail -5 /etc/passwd  --  passwd파일의 맨밑에서 5줄만 출력한다

 

grep

파일 안의 단어를 찾는다

ex) cat a.txt | grep 'test'

출력) testMessage

 

리눅스 리다이렉션(Linux Redirection)

ls -al > list.txt  --  ls -al의 결과를 list.txt파일에 저장한다

sort < list.txt  --  list.txt파일의 내용을 정렬해서 출력한다

sort < list.txt > list1.txt  --  list.txt의 정렬된 내용을 list1.txt파일로 저장한다

반응형
LIST