본문 바로가기

Ubuntu

Linux에서 파일명 일괄변경 방법

YADE에서 MPI해석을 실행하는 경우 VTKRecorder로 생성되는 파일명이 PARAVIEW에서 인식하기 어려운 형태로 만들어 진다.

예를들어, 노드 3개를 이용하여 해석을 시행하는 경우, 아래와 같이 "노드번호_싸이클No"의 순서로 파일명이 작성된다.

 

3d-vtk-spheres_0_0.vtu
3d-vtk-spheres_0_500.vtu
3d-vtk-spheres_0_1000.vtu

3d-vtk-spheres_1_0.vtu
3d-vtk-spheres_1_500.vtu
3d-vtk-spheres_1_1000.vtu

3d-vtk-spheres_2_0.vtu
3d-vtk-spheres_2_500.vtu
3d-vtk-spheres_2_1000.vtu

 

그러나, PARAVIEW에서 Group Data로 vtu파일이 인식되기 위해서는 "싸이클No_노드번호"의 순서로 아래와 같이 파일이 생성되어야 한다.

 

3d-vtk-spheres_0_0.vtu
3d-vtk-spheres_500_0.vtu
3d-vtk-spheres_1000_0.vtu

 

파일명을 한번에 바꾸어 주려면 rename 명령을 쓰면 된다고 한다. 우선, rename을 설치

sudo apt install rename

그 다음, 아래와 같이 명령어를 써주면 된다.

 

rename 's/(\d+)_(\d+)/$2_$1/' *

원리는? ChatGPT가 그렇게 하란다.

 

This command uses the rename command and a regular expression to replace the position of the two numbers in the filename.

Explanation of the command:

  • rename is the command used to rename files in Linux.
s/(\d+)_(\d+)/$2_$1/

 

is a regular expression that matches two groups of digits separated by an underscore and then swaps the position of those two groups. The $1 and $2 in the replacement string swap the positions of the two groups of digits.

 

 

'Ubuntu' 카테고리의 다른 글

Dependency 문제 해결  (0) 2023.05.09
Package 확인방법  (0) 2023.04.24
우분투 듀얼부팅시 시간세팅 문제  (0) 2023.01.16
Ubuntu 꼬인경우  (0) 2022.12.21
패키지 의존성 관리  (0) 2022.12.19