코랩, 서버 등으로 작업할 때 유용한 리눅스 명령어 정리
pwd
/home/..
cd /home
pwd
/home
cd ..
pwd
/
ls
testfile1 testfile2 testfile3
cp testfile1 testfile_cp
ls
testdir/ testfile testfile_cp
cp -r testdir testdir_cp
ls
testdir/ testdir_cp/ testfile testfile_cp
ls
testdir/ testfile
mv testfile testfile_mv
ls
testdir/ testfile_mv
mv testfile_mv testdir/
ls
testdir/
ls testdir/
testfile
mkdir testdir
ls
testdir/ testfile
ls
testdir/ testfile1 testfile2
rm -f testfile1
ls
testdir/ testfile2
rm -rf testdir/
ls
testfile2
touch testfile2
ls
file1 file2 file3
cat file1
1
cat file2
2
cat file3
3
cat file1 file2 > file1_2
$ ls
file1 file1_2 file2 file3
cat file1_2
1
2
cat file1 >> file2
cat file2
2
1
cat > file4
hello
world
(작성이 끝나면 ctrl +d 로 파일 저장)
cat file4
hello
world
ls
dir1/ dir3/ file1 file3 picture1.jpg picture3.jpg
dir2/ dir4/ file2 file4 picture2.jpg picture4.jpg
find ./ -name 'file1'
./file1
find ./ -name "*.jpg"
./picture1.jpg
./picture2.jpg
./picture3.jpg
./picture4.jpg
find [검색경로] -name [파일명]
find ./ -name "*.jpg" -exec rm {} \;
ls
dir1/ dir2/ dir3/ dir4/ file1 file2 file3 file4
find ./ -type d
./
./dir1
./dir2
./dir3
./dir4
find ./ -type f
./file1
./file2
./file3
./file4
find ./ -type f | wc -l
4
find ./ -name "*.txt" -exec sed -i 's/hi/hello/g' {} \;
sed -i 's/hi/hello/g' testfile1.txt
unzip compressed.zip
현재 폴더에 압축 해제
unzip -l compressed.zip
압축 해제하지 않고 압축 파일 내 목록 출력
unzip compressed.zip -d /path/to/put
특정 폴더에 압축 해제
for i in *.zip; do unzip $i -d /path/to/put;done
여러 파일 압축 해제
zip
unzip
파일과 폴더를 하나의 파일로 묶어주는 archiving utility (압축 x)
tar -cvf target.tar file1 file2 dir1 dir2
단순 아카이빙
tar -cvzf target.tar.gz file1 file2 dir1 dir2
아카이빙 후 gzip으로 압축
tar -cvJf target.tar.xz file1 file2 dir1 dir2
아카이빙 후 xz로 압축
tar -xvf target.tar
현재 폴더에 아카이빙 풀기
tar -zxvf target.tar.gz
압출된 tar 파일 해제
압축 방식에 따라 -j(bzip2), -J(xz), -z(gzip) 옵션 추가
tar -Jxvf target.tar.xz -C /opt
해제 디렉토리를 지정하는 xz