레이블이 FILE인 게시물을 표시합니다. 모든 게시물 표시
레이블이 FILE인 게시물을 표시합니다. 모든 게시물 표시

2017년 10월 9일 월요일

linux에서 read-only filesystem의 file 혹은 folder/directory 제거하기

문제: linux에서 read-only filesystem이기에 지워지지않는 파일/폴더를 지우자.

해결:
1. cat /proc/mounts 로 mount 상태 보기
   해당 disk가 read-only 인지 확인 /dev/~ /media/ID/USB vfat ro, ~~~

2. mount -o remount,rw /dev/~(위에서 밑줄친 부분) 을 이용하여 read-write로 remount 시킴.

3. 1번 다시해서 확인.

4. rm으로 삭제하기
   rm -r -f 폴더명

2017년 2월 6일 월요일

linux, ubuntu에서 shift delete 혹은 rm으로 삭제한 파일을 살리자.

문제: linux, ubuntu에서 shift delete 혹은 rm으로 삭제한 파일을 살려보자.

해결:
1. 삭제가 발생한 디스크의 사용을 일단 멈춘다.

2. 어느 디스크에서 삭제가 이루어졌는지 확인.
df -T 혹은 sudo fdisk -l
ex) /dev/sdb2

3. 삭제된 파일을 확인하고 inode를 메모
sudo ntfsundelete -f -s -S 85m-90m -m '*.caffemodel' /dev/sdb2
-s : scan
-f : 디스크를 남이 접근하더라도 강제로 사용
-S : 파일크기(byte)
- m : 파일의 이름
ex) 1, 2, 7, 8, 9

3. 복구한다. 복구된 위치는 ~(home directory)
sudo ntfsundelete -u -f -i 1,2,7-9 /dev/sdb2 -d ~
-u : undelete
-i : 복구를 원하는 inode, 콤마사이는 붙인다.
-d : 복구된 파일이 위치할 디렉토리(삭제가 발생한 디스크는 피한다).

4. 이렇게 복구된 경우 보통 root 소유이기에 소유자 권한을 바꿔준다.
sudo chown yochin:yochin 파일이름

끝.

2015년 12월 8일 화요일

python에서 폴더 내 파일 읽어오기 (리스트 형태), 폴더 생성하기

<출처: http://stackoverflow.com/questions/3207219/how-to-list-all-files-of-a-directory-in-python>
// 특정 폴더의 파일(확장자가 ext인)을 읽어오고 싶은 경우 => 파일의 이름과 확장자만 리턴함. 
import os
def list_files(path, ext):
    filelist = []
    for name in os.listdir(path):
        if os.path.isfile(os.path.join(path, name)):
            if name.endswith(ext):
                filelist.append(name)
    return filelist
// 특정 폴더 및 그 하위폴더의 파일(확장자가 ext인)까지 읽어오고 싶은 경우.=> 경로, 파일의 이름과 확장자 모두 리턴함.
import os
def list_files_subdir(destpath, ext):
    filelist = []
    for path, subdirs, files in os.walk(destpath):
        for filename in files:
            f = os.path.join(path, filename)
            if os.path.isfile(f):
                if filename.endswith(ext):
                    filelist.append(f)
    return filelist
filelist = list_files_subdir(strdirectory_fc, 'txt') 
// 특정 폴더 및 그 하위폴더의 파일(확장자가 ext인)까지 읽어오고 싶은 경우.=> 경로, 파일의 이름을 별도로 리턴함. 
import os 
def list_files_subdir(destpath, ext):
    fullpathlist = []    
    folderlist = []
    filelist = []

    for path, subdirs, files in os.walk(destpath):
        for filename in files:
            f = os.path.join(path, filename)
            if os.path.isfile(f):
                if filename.endswith(ext):
                    fullpathlist.append(f)
                    folderlist.append(path)
                    filelist.append(filename)
    return fullpathlist, folderlist, filelist
// 특정 폴더 생성하기
# 폴더가 존재하는지 확인 후, 없으면 생성함.
strdirectory_fc = 'directory_name'
 
if not os.path.exists(strdirectory_fc):
    os.makedirs(strdirectory_fc)






2015년 11월 17일 화요일

std::ifstream

C의 FILE과 비슷한 역할을 하는 C++클래스

파일읽기용 std::ifstream과 파일에 쓰기용인 std::ofstream이 있음.



사용예

// 파일열기
ifstream myin("c:/a.txt"); 혹은
ifstream myin;
myin.open("c:/a.txt", ios::in | ios::binary); 형태로 연다.

// 읽거나 쓰기
myin >> i >> end;
myout << i << endl;

// 파일닫기
myin.close();

<참조: http://ra2kstar.tistory.com/147>