티스토리 뷰

Research (연구 관련)

리눅스 scp, find

홍돌 2019. 4. 19. 23:16

nohup scp
scp할 때 서버의 password를 써야하기 때문에 그냥 nohup을 쓰면 안된다. 
http://charmyin.github.io/scp/2014/10/07/run-scp-in-background/ 

$ nohup scp file_to_copy user@server:/path/to/copy/the/file > nohup.out 2>&1

#Then press ctrl + z which will temporarily suspend the command, then enter the command:

$ bg

그러면 백그라운드에서 command를 실행한다.
(업데이트) 많은 파일을 할 때만 그런건지 모르겠는데, 중간에 옮기다 멈추는 현상이 있다. 여기의 screen을 이용하길 추천한다.

...더보기

Create a Screen Session and Detach It

GNU Screen can be used to create a remote terminal session, which can be detached and continue to run on the server after you log out of the session. You can then log back into the server at a later date and reattach to the session.

  1. Log into the remote server over ssh.
  2. Start a screen session, screen -D -R <session_name>.
  3. Begin scp transfer as usual.
  4. Detach the screen session with Ctrl+A then d.
  5. Terminate the ssh session (exit)

To reattach to the session:

  1. Log into the remote server over ssh.
  2. Reattach to the screen session, screen -D -R <session_name>

 

copy only new files with "scp"
https://unix.stackexchange.com/questions/105140/how-to-copy-only-new-files-using-scp-command/205018

sudo find /files/ -type f -exec chmod a-w {} \;

scp -r username@server.com:/file/location/* /files

# after finishing copy
sudo chmod a+w -R /files

파일 쓰기 권한을 바꿔서 scp가 기존 파일들은 덮어쓰지않고 skip하게 한다.
그런데 내가 지금 복사 해놓은 파일 양이 워낙 커서 첫번째 권한바꾸기가 시간이 엄청걸린다. 
처음에는 그냥 chmod a-w -R *로 했는데, 내가 복사하는 위치가 dir/subdir/files 구조다보니 subdir의 쓰기권한도 못쓰게 해버려서 안됐다. file만 찾아서 바꿔줘야함. 
rsync 커맨드도 있는데 잘 안된다. 더해보면 알겠지만 일단 익숙한 scp로~

 

find 옵션. -type, -exec
http://mwultong.blogspot.com/2007/06/unix-find.html

find / -name 'et*' -type d

directory: d, file: f
-exec: execute folloing command

 

Delete files with Regex 
https://superuser.com/questions/392872/delete-files-with-regular-expression

ls | grep -P "^A.*[0-9]{2}$" | xargs -d"\n" rm

친절한 설명

grep은 현재 active process를 찾을 때도 이용한다

$ ps -ef # 현재 실행중인 모든 process 출력
$ ps aux | grep 'sshd' # ''의 command로 돌아가는 process 출력. 어떤 user가 명령했는지 알 수 있음

https://www.cyberciti.biz/faq/linux-find-process-name/ 

 

scp multiple files or multiple directories

{a,b}를 활용하면 된다.

scp {foo,bar}.txt your_username@remotehost.edu:~

https://stackoverflow.com/a/21691584/8584068

 

scp와 regex를 결합해 사용하는 방법

없다. 
https://unix.stackexchange.com/questions/67055/how-to-scp-with-regular-expressions/67101 에서 된다고 하는데, 잘 안된다.
다만 * 같은 메타문자는 활용도가 높게 쓸 수 있다.
굳이 위의 링크에서처럼 ""를 쓰지말고,  dir/subdir/files 구조의 파일들을 로컬에서 서버로 옮기고 싶을 때 dir/subdir의 substring*만 해도 원하는 파일들이 복사된다. 

무슨 말이냐하면, subdir에 regex를 써서 하위파일들을 디렉토리 구조를 유지하면서 옮기고 싶을 때

$ scp server_id@sever_ip:/some_dir/s_11_act_0*/* . # 현재 디렉토리도 some_dir/s_~/files 구조다

above code doesn't work but instead, below code will do.
It will not copy files like /some_dir/files, but like /some_dir/s_~/files as I intended.

$ scp server_id@sever_ip:/some_dir/s_11_act_0* . # 현재 디렉토리도 some_dir/s_~/files 구조다

'Research (연구 관련)' 카테고리의 다른 글

2D 이미지와 퓨리에 변환  (1) 2019.04.23
리눅스 make subdirectories  (0) 2019.04.22
Bilateral Filter / Guidance Filter  (0) 2019.04.18
Affine Transform (아핀 변환)  (0) 2019.04.18
Procrustes Analysis  (0) 2019.04.13
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함