Linux 압축 하기/압축 풀기


Tape Archive

tar은 Tape Archive 의 약자로, 옛날부터 Tape 드라이브를 백업하기 위해 사용했다고 한다. tarball 이라고 불리기도 한다고 한다.

tar은 압축을 옵션으로 줄 수 있는데, gzip 으로 압축을 하면 tar.gz 파일이, bzip2로 압축하면 tar.bz2 가 생성된다.

tar command의 (사실은 상당히 많은 옵션을 가지고 있지만) 기본적인 옵션은 아래와 같다.

c : Create a new .tar file

v : Verbosely show the pregress

f : File name

x : Extract

t : List content

z : for gzip

j : for bzip2


간단 사용예

tar 압축 하기

$ tar -cvf <output_file_name>.tar <input_folder>

tar 압축 풀기

$ tar -xvf <input_file_name>.tar 

tar.gz 압축 하기

$ tar -zcvf <output_file_name>.tar.gz <input_folder>

tar.gz 압축 풀기

$ tar -zxvf <input_file_name>.tar.gz 

tar.bz2 압축 하기

$ tar -jcvf <output_file_name>.tar.bz2 <input_folder>

tar.bz2 압축 풀기

$ tar -jxvf <input_file_name>.tar.bz2 


보다 자세한 내용은, https://www.tecmint.com/18-tar-command-examples-in-linux/ 참조

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

scp  (0) 2018.05.29
Systemd Service  (0) 2018.05.04
Linux HDD mount  (0) 2018.04.06
HandBrakeCLI  (0) 2018.04.06
Linux sed  (0) 2018.02.05

리눅스에서 새 하드디스크를 마운트 하고 자 하는 경우


우선 fdisk 를 통해 새 하드디스크의 device number?(sda | sdb | sdc ...)를 확인해야한다.

$ sudo fdisk -l


확인한 device number(예시 sdc)를 가지고 fdisk 를 통해 파티션을 설정한다.

$ sudo fdisk /dev/sdX

Command (m for help): n

Partition type

p    primary (0 primary, 0 extended, 4 free)

e    extended (container for logical partitions)

Select (default p): 

Partition number (1-4, default 1):

First sector (2048-41943039, default 2048):

Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039):


Created a new partition 1 of type 'Linux' and of size 20 GiB.


Command (m for help): w

The partition table has been altered.

Calling ioctl() to re-read partition table.

Syncing disks.


파티션 설정이 끝나면, 포멧을 해야한다.

일반적으로 리눅스에서는 ext4 포멧을 사용한다.

$ sudo mkfs.ext4 /dev/sdc


이제 하드디스크가 준비가 완료 된 것이다.

다음은, 해당 하드디스크를 디렉토리 어딘가에 마운트 해야한다.

$ sudo mkdir /mnt

$ sudo mount /dev/sdc /mnt


그러나, 위와 같은 방법으로 마운트를 하면 매번 컴퓨터를 켤 때 마다 새로 마운트를 해줘야 한다.

컴퓨터가 부팅 될 때 자동으로 마운트는 /etc/fstab을 참조하여 하는데,

/etc/fstab에 해당 HDD를 추가하면 된다.

fstab에 HDD 정보를 UUID를 바탕으로 적어주기 때문에 이를 위해서는 우선, HDD의 UUID를 확인해아 한다.

$ sudo blkid

UUID를 확인하여 클립보드로 복사해 둔후

vi editor로 etc/fstab을 수정한다.

$ sudo vi /etc/fstab

fstab에 추가하는 형식은 아래와 같다.

<file system> <mount point> <type> <options> <dump> <pass>

UUID=5aa86733-92d5-4060-9086-d026d9409e7b /mnt ext4

이때, options, dump, pass는 입력하지 않아도 기본적으로 동작하는데는 문제없다.


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

Systemd Service  (0) 2018.05.04
Linux tar, gz, bz2  (0) 2018.04.25
HandBrakeCLI  (0) 2018.04.06
Linux sed  (0) 2018.02.05
Linux find  (0) 2018.02.04

Linux에서 동영상 인코더로 많이 사용하는 HandBrake

Command Line 명령어로 HandBrake를 사용하기


옵션이 많아 따지기 귀찮으면

간단하게 preset을 사용하면 된다.

$ HandBrakeCLI --input <input_file> --output <output_file> --preset 'Devices/Apple 540p30 Surround'


preset list는

$ HandBrakeCLI --preset-list

로 확인하자


위의 Apple preset이 너무 느려서... 내가 사용하는 옵션은

$ HandBrakeCLI --input <input_file> --output <output_file> --encoder x264 --encoder-preset ultrafast  --rate 30 --width 640 --height 360


자세한 옵션은 help 옵션으로 확인하자.

$ HandBrakeCLI --help


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

Linux tar, gz, bz2  (0) 2018.04.25
Linux HDD mount  (0) 2018.04.06
Linux sed  (0) 2018.02.05
Linux find  (0) 2018.02.04
Ubuntu sources.list generation  (0) 2017.09.06

NAS 등 다른 컴퓨터의 하드디스크를 네트워크 드라이브로 연결하고 싶은데,

sftp만 사용중이라면,


sftp-net-drive 를 사용해서 네트워크 드라이브로 설정하면 된다.

개인의 경우 nsoftware에서 간단하게 메일만 입력하면 무료로 다운받아 사용할 수 있다.


다운받은 SFTPNetDrive.exe를 실행하여 설치를 한 후

원격 하드디스크를 네트워크 드라이브로 설정하면 된다.

UI가 좋아서 설정방법은 어렵지 않다.


SFTP Net Drive를 실행하여


New Profile 로 연결할 원격 하드디스크의 기본적인 정보를 입력한다.(이름/IP주소)

※포트포워딩 등으로 인해 sftp의 포트가 22가 아닌경우 ip_addrss:port_number 방식으로 ip주소를 입력하면 문제없이 동작한다.


Username과 Password를 입력한 후 Connect 버튼을 누르면 연결이 된다.

이때 Drive Letter도 지정할 수 있다.


필요에 따라,

 Advanced Option - Protocol tab에서 UTF-8 인코딩을 설정할 수 있다.(한글이 깨져서 나오는 경우)

 Advanced Option - Drive tab에서 Root folder를 지정할 수 있다.


장시간 연결 시 연결이 끊기는 문제가 있는 듯 하긴하다...

'Programming > OrangePi' 카테고리의 다른 글

OrangePi Plus 2 + SATA  (0) 2017.10.02
OrangePi 에 Telegram Bot 구축하기  (0) 2017.09.16
OrangePi Fan on GPIO  (0) 2017.09.15
U+ 공유기 포트포워딩 문제  (0) 2017.09.09
OrangePi Plus 2 Ubuntu 설치  (0) 2017.06.17

Bash script 에서 case 는 아래와 같은 형태를 가진다.

case variable in

case1)

statement1;;

case2)

statement2;;

*)

statement_default;;

esac


'Programming > Bash Script' 카테고리의 다른 글

Bash script argument parsing with getopts  (0) 2020.01.23
Bash script for statement  (0) 2018.05.21
Bash Script Variable Split by Space  (0) 2018.02.04
Bash Script Echo  (0) 2018.02.04
Bash Script String  (0) 2017.07.04

Linux 사용시 파일 내부의 특정 표현을 수정하고자 하는 경우 sed 명령어를 활용할 수 있다.


sed 의 기본적인 형태는 아래와 같다.

sed <options> <address> <commands> <filename>

<options>

-n : suppress automatic printing (sed는 Matching 되는 Line 외에도 모든 Line 을 기본적으로 printing 하는데, line number 를 출력하고자 하는 경우(command =) 또는, Matching 되는 line 만 출력하고자 하는 경우(command /p)에는 -n option을 활용하면 된다.)

<address>

number : Match only the line number

/regular_expression/ : Match lines matching the regular_expression

addr1,addr2 : Match lines from addr1 to addr 2

addr,+N : Match addr and the following N lines

addr,~N : Match lines from addr to N*addr

<commands>

= : print the line number

/p : print the line

s/regular_expression/replacement : replace 


다만, 순전히 내 기준에서 가장 많이 사용하는 sed의 형태는 아래와 같다.

sed s/<regular_expression>/<replace>/g <file>

여기서 /g는 vim에서 replace 할 때의 /g 와 마찬가지로, 여러 개가 매칭 되는 경우 여러번 실행하도록 하는 옵션


sed 는 <file> 로 부터 <regular_expression> 을 찾아 <replace> 로 치환하여, 표준 출력을 해준다.

이는 vim 에서 replace 하는 것과 비슷하다.

결과물이 표준 출력 되기 때문에, 아래와 같이 > 또는 >> 를 이용해 파일에 써줄 수 있다.

다만, 여기서 파일이 이름이 같은 경우 아무것도 써지지 않는다는 점을 유의하자.

sed s/<regular_expression/<replace>/g <input_file> > <output_file>


아래는 예시

sed s/^$//g test.txt > test.txt.tmp

mv test.txt.tmp test.txt

(test.txt 파일로 부터 공백인 행을 없애 test.txt.tmp 파일에 출력한다.)


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

Linux HDD mount  (0) 2018.04.06
HandBrakeCLI  (0) 2018.04.06
Linux find  (0) 2018.02.04
Ubuntu sources.list generation  (0) 2017.09.06
Ubuntu Redshift  (0) 2017.07.02

Bash Script 사용할 때,

shell 명령어에 대한 return을 받은 variable 이 space로 구분된 string 이라면,

아래와 같이 명령어를 배열처럼 구분하여 사용할 수 있다.

string_ex="I am your Father"

str_array=($string_ex)

echo ${str_array[0]} #I

echo ${str_array[1]} #am

echo ${str_array[2]} #you

echo ${str_array[3]} #Father


'Programming > Bash Script' 카테고리의 다른 글

Bash script for statement  (0) 2018.05.21
Bash Script case statement  (0) 2018.02.06
Bash Script Echo  (0) 2018.02.04
Bash Script String  (0) 2017.07.04
Bash Script If statement  (0) 2017.07.04

Linux system 에서 파일을 찾고자 할 떄,

find 함수를 사용하면 찾을 수 있다.


기본적인 사용법은 아래와 같다.

$ find <directory> -name <finding_file_name>


옵션으로 아래와 같이 사용 할 수 있다.

-type f : 파일

-type d : 폴더(directory)

-maxdepth 1 : find 는 기본적으로 하위 디렉토리까지 전부 검사 한다. maxdepth는 하위 몇 디렉토리 까지 검사할 것인지를 설정한다.

-and : 여러개의 조건에 대해 찾고자 할때 -and 옵션과 함께 조건을 추가할 수 있다.

-and ! : 해당 조건이 거짓인 경우에 대해 찾고자 할 때, -and ! 을 사용하면 된다.

-iname : 파일 이름의 대소문자를 고려하지 않고 검색한다.


아래는 예시

$ find . -type f -name 'abc*' -and ! -name 'abc'

(현재 디렉토리로 부터 abc로 시작하는 이름을 가진 파일 중에 파일 이름이 abc는 아닌 것을 찾는다.


xargs와 함께 사용하면, 

디렉토리에서 원하는 파일을 복사/삭제 하기 수월하다

예시

$ find . -type f -name 'abc*' -and ! -name 'abc' | xargs rm -f

(현재 디렉토리로 부터 abc로 시작하는 이름을 가진 파일 중에 파일 이름이 abc는 아닌 것을 찾아 삭제한다.

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

HandBrakeCLI  (0) 2018.04.06
Linux sed  (0) 2018.02.05
Ubuntu sources.list generation  (0) 2017.09.06
Ubuntu Redshift  (0) 2017.07.02
Linux timezone  (0) 2017.06.20

Bash Script echo 사용 시 줄바꿈을 하고 싶지 않다면,

-n

$ echo -n "hello "

$ echo "world"

hello world

'Programming > Bash Script' 카테고리의 다른 글

Bash Script case statement  (0) 2018.02.06
Bash Script Variable Split by Space  (0) 2018.02.04
Bash Script String  (0) 2017.07.04
Bash Script If statement  (0) 2017.07.04
Bash script argument  (0) 2017.06.20

Python 으로 tab/공백 으로 구분 된 파일 parsing 하여 array로 만들기


#input file open

file = open(file_name, "r")


#output array of table

table_data = []


#for every row

for line in file:

#split by white spaces(column)

tmp_array = line.strip().split(" ")


#remove NO value element

while tmp_array.count(""):

tmp_array.remove("")


table_data.append(tmp_array)


'Programming > Python' 카테고리의 다른 글

Python Apt-get  (1) 2018.08.03

+ Recent posts