- 파일 이름에 foobar 가 들어간 파일 찾기
find / -name "foobar" -print
- 특정 사용자(foobar) 소유의 파일을 찾기
find / -user foobar -print | more
- 최근 하루동안에 변경된 파일을 찾기
find / -ctime -1 -a -type f | xargs ls -l | more
- 오래된 파일(30일 이상 수정되지 않은 파일) 찾기
find / -mtime +30 -print | more
- 최근 30일안에 접근하지 않은 파일과 디렉터리를 별도의 파일로 만들기
find / ! ( -atime -30 -a ( -type d -o -type f ) ) | xargs ls -l > not_access.txt
- 하위 디렉터리로 내려가지 않고 현재 디렉터리에서만 검색하기
find . -prune ...
- 퍼미션이 777 인 파일 찾기
find / -perm 777 -print | xargs ls -l | more
- others 에게 쓰기(write) 권한이 있는 파일을 찾기
find / -perm -2 -print | xargs ls -l | more
- others 에게 쓰기(write) 권한이 있는 파일을 찾아 쓰기 권한을 없애기
find / -perm -2 -print | xargs chmod o-w
또는
find / -perm -2 -exec chmod o-w {} ; -print | xargs ls -l | more
- 사용자이름과 그룹이름이 없는 파일 찾기
find / ( -nouser -o -nogroup ) -print | more
- 빈 파일(크기가 0 인 파일) 찾기
find / -empty -print | more
또는
find / -size 0 -print | more
- 파일 크기가 100M 이상인 파일을 찾기
find / -size +102400k -print | xargs ls -hl
- 디렉터리만 찾기?
find . -type d ...
- root 권한으로 실행되는 파일 찾기
find / ( -user root -a -perm +4000 ) -print | xargs ls -l | more
- 다른 파일시스템은 검색하지 않기
find / -xdev ...
- 파일 이름에 공백이 들어간 파일 찾기
find / -name "* *" -print
- 숨겨진(hidden) 파일을 찾기
find / -name ".*" -print | more
- *.bak 파일을 찾아 지우기
find / -name "*.bak" -exec rm -rf {} ;
- *.bak 파일을 찾아 특정 디렉터리로 옮기기
mv `find . -name "*.bak"` /home/bak/
위의 /dev/sdb가 /mnt에 마운트 되어 있습니다..
그래서, 주로 사용하게 되는 /var에 마운트를 하게되면 자연스럽게 해결이 됩니다..
/# mkdir var-old /# rsync -avr /var/* /var-old/ /# rsync -avz /var/* /mnt/
그리고, /etc/fstab으 열어어 /mnt --> /var로 바꿔주면 됩니다.. ^^
흠.. 그리고 리부팅 하시면 됩니다..^^
우분투를 메인 OS로 사용하고 있는데, 가끔 윈도우도 필요하고, 클러스터링 구성하기 위해서 VirtualBox로 리눅스/윈도우를 사용하고 있는데.. USB 인식이 안되서 에이.. 하고 말았는데.. 매우 좋은 팁이네요..
자세한 내용은 http://simplism.kr/wordpress/?p=816 을 참고하세요..
apt-get은 패키지를 다운로딩하고 설치하기 위한 간편한 명령행 인터페이스 명령어 입니다.
가장 자주 사용되는 명령어는 update와 install 입니다.
명령어:
update - 새로운 패키지 목록을 검색
upgrade - 업그레이드를 수행
install - 새로운 패키지를 설치 (패키지는 libc6.deb 가 아닌 libc6 형태야 합니다.)
remove - 패키지 제거 <-- 완전하게 제거가 안 된다고 합니다.
autoremove - 사용하지 않는 모든 패키지들을 자동으로 제거 <-- 의존하고 있는 패키지도..
purge - 패키지와 설정 파일들을 제거
source - 소스를 다운로드
build-dep - 소스 패키지에 대한 빌드 의존성을 설정
dist-upgrade - 배포판 업그레이드, apt-get(8) 참조
dselect-upgrade - dselect 선택을 따름
clean - 다운로드한 압축 파일들을 제거
autoclean - 다운로드한 오래된 압축 파일들을 지움
check - 깨진 의존성이 없는 지 검토
옵션:
-h 이 도움말 텍스트.
-q 로깅할 수 있는 출력 - 진행상태가 표시되지 않음
-qq 출력을 하지 않음 (단, 오류는 출력됨)
-d 다운로드만 함 - 설치나 압축해제는 하지 않음
-s 실제 동작은 안 . 시뮬레이션을 수행하도록 함
-y 모든 질문에 대해 예로 대답하고, 물어보지 않음
-f 의존성이 깨진 시스템을 고치기 시도
-m 압축 파일들을 찾을 수 없을 때 계속해서 시도
-u 업그레이드된 패키지 목록을 보여줌
-b 패칭한 후에 소스 패키지를 빌드
-V 버전 번호를 보여줌
-c=? 이 설정 파일을 읽음
-o=? 다른 설정 옵션, 예. -o dir::cache=/tmp
Windows의 IIS에 배포를 위해서 xcopy 같은 명령어를 많이 사용하는데, 그런경우 copy가 되는 도중에 IIS가 읽어버리면 계속 cache miss 어쩌구 저쩌구 에러로그가 계속 쌓입니다. 그런 경우 해결책이 웹서버 리스타트 인데요.. iisreset 으로 리스타트를 합니다. 여러대의 서버에 배포를 하고 iis reset을 하기 위해서는 아래는 참고하시면 좋은 팁이 될듯 합니다.^^
윈도우에서 간혹 다량의 다른 위치에 복사를 한다든지, UNC경로로 다른 서버에 파일을 배포할 이슈가 있습니다.
그때 아래의 코드를 약간 수정해서 사용하시면 아주 쉽게 복사를 할 수 있습니다. ^^
@echo off
set date_var=%date%
set time_var=%time%
set from_file_name=C:\cmd-test\a\*.*
set to_file_base=C:\cmd-test\
set to_file_detail=\a\
set /a server_count=25
set result_file=copy_result.txt
Windows Server 2003에서 터미널 서비스를 사용하면 콘솔 세션(세션 0)에 연결하는 동시에 해당 세션에 대한 섀도
세션을 열 수 있습니다(다른 콘솔이 아닌 세션에서 연결하는 경우). 이 추가 기능을 사용하면 터미널 서비스를 실행하는
Windows Server 2003 기반 서버에 원격으로 로그온하고 실제 컴퓨터 콘솔 앞에 앉아 있는 것처럼 세션 0과 상호
작용할 수 있습니다. 또한 이 세션을 섀도잉할 수 있으므로 원격 사용자와 실제 콘솔에 있는 로컬 사용자가 동일한 세션을 보고
상호 작용할 수 있습니다.
콘솔 세션에 연결하는 방법
Windows Server 2003 기반 서버의 콘솔 세션에 연결할 때 다른 사용자가 해당 콘솔 세션에 로그온되어 있지 않아야
합니다. 콘솔에 로그온한 사용자가 없는 경우 마치 실제 콘솔을 사용하는 것처럼 로그온할 수 있습니다.
Windows Server 2003 기반 원격 컴퓨터에서 연결하려면 명령 프롬프트를 열고 다음 명령을 입력합니다.
mstsc -v:servername /F -console
여기서 mstsc는 원격 데스크톱 연결 실행 파일이고 -v는 연결할 서버를 나타내며 /F는 전체 화면 모드를 나타내고 -console은 콘솔 세션에 연결하는 명령입니다.
Windows Server 2003 기반 서버에서 원격 제어를 허용하도록 구성하려면 다음과 같이 하십시오.
1. 개요
cron(크론)은 원하는 시간에 명령(프로그램)을 시키기 위한 데몬이다.
서버는 늘 깨어있다는 것을 이용한 최대한의 활용법이 될 수 있다.
- 내가 새벽 3시에 서버에 특정 작업을 해줘야하는데 그 때 깨어있을 수 있는가?
- 또는 30분 간격으로 HDD의 사용량을 운영자에게 알리도록 해야한다면?
- 매월 초에 자료를 백업 받고 싶다면?
바로 이럴 때 cron은 최고의 해결책을 제시한다.
cron은 항상 지정한 시간이 되었는지 확인을 하여 해당 명령어을 실행하는 것이다.
시스템의 최적화의 기법은 일정 시간 단위로 최대한의 성능을 발휘하도록 도와주는 것이다. 즉, 주기적으로 운영 중에 만들어진
필요하지 않는 임시 파일을 정리하거나, 운영체제 운영에 필요한 데이터를 갱신하는 등의 작업을 통해 리눅스가 최적의 상태를 유지할
수 있게 할 수 있다.
2. cron 설정
1) crontab 파일 위치 및 조회
작업 설정 파일을 crontab 파일이라고 부르며, 이 파일의 위치는 OS별로 차이가 있다.
리눅스는 /var/spool/cron/ID, 솔라리스는 /var/spool/corn/crontabs/ID에 위치한다.
그럼 이 파일을 직접 수정해야 하는가? 그렇지 않다. crontab 명령을 통해 설정과 조회를 한다.
crontab 설정 파일을 새롭게 편집하고자 한다면 -e 옵션을 주고, 수정하기 전에 현재 등록된 내용을 보고자 한다면 -l 옵션을 사용하며, 등록된 내용을 삭제하려면 -d 옵션을 사용한다
설정 내용을 조회해 보자(-l 옵션).
$ crontab -l
no crontab for truefeel
설정한 적이 없어 아직 비어있다.
/etc/crontab 파일
- /etc/rc.d/init.d/crond 스크립트
- /var/spool/cron 디렉토리 내의 크론 설정 파일들
2) crontab 파일 형식
---------- ---------- ---------------------------------------------------
필 드 의 미 범 위
---------- ---------- ---------------------------------------------------
첫 번째 분 0-59
두 번째 시 0-23
세 번째 일 0-31
네 번째 월 1-12
다섯 번째 요일 0-7 (0 또는 7=일요일, 1=월, 2=화, ...)
여섯 번째 명령어 실행할 명령을 한줄로 쓴다.
---------- ---------- ---------------------------------------------------
- 모든 엔트리 필드는 공백으로 구분된다.
- 한 줄당 하나의 명령 (두줄로 나눠서 표시할 수 없음)
- # 으로 시작하는 줄은 실행하지 않는다.
설정을 해보자. (-e 옵션)
crontab -e을 하면 vi 에디터가 나온다(환경변수 EDITOR에 따라 다른 에디터를 사용할 수 있다).
$ crontab -e
# /home 디렉토리를 /BACKUP/home으로 백업해둠
#
# 30분, 새벽 4시와 낮 12시, 모든 일, 모든 월, 모든 요일
30 4,12 * * * /usr/bin/rsync -avxH --delete /home /BACKUP/home > /dev/null 2>&1
#
# 파일/디렉토리 퍼미션 설정
# 40분, 새벽 1시, 매주 일요일
40 1 * * 0 /root/bin/perm_set.sh > /dev/null 2>&1
위는 매일 4:30분과 12:30분에 rsync 명령을, 매주 일요일 1:40분에 perm_set.sh를 실행함을 의미한다.
3) 설정 예
시간 설정에서 몇가지 의미있는 것들을 알아보자.
- '*'표시는 해당 필드의 모든 시간을 의미한다.
- 3,5,7와 같이 콤마(,)로 구분하여 여러 시간대를 지정할 수 있다.
- 2-10와 같이 하이픈(-)으로 시간 범위도 지정할 수 있다.
- 2-10/3와 같이 하이픈(-)으로 시간 범위를 슬래쉬(/)로 시간 간격을 지정할 수 있다(2~10시까지 3시간 간격으로. 즉, 3, 6, 9시를 의미함).
원하는 시간 형 식
매주 토요일 새벽 2:20 20 2 * * 6 명령어
매일 오후 4,5,6시 0 4-6 * * * 명령어
매일 2시간 간격으로 5분대에 5 */2 * * * 명령어
매월 1일 새벽 1:15 15 1 1 * * 명령어
1,7월 1일 새벽 0:30 30 0 1 1,7 * 명령어
4) /etc/crontab 파일로 설정
매시 1회 자동실행하기 위한 시스템 크론 설정
01 * * * * root run-parts /etc/cron.hourly
- 매일 매시 01분마다 /etc/cron.hourly 디렉토리내에 존재하는 파일들을 실행
매일 1회 자동실행하기 위한 시스템 크론설정
02 4 * * * root run-parts /etc/cron.daily
- 매일 새벽 4시 02분마다 /etc/cron.daily 디렉토리내에 존재하는 파일들을 실행
매주 1회 자동실행하기 위한 시스템 크론설정
22 4 * * 0 root run-parts /etc/cron.weekly
- 매주 일요일 새벽 4시 22분마다 /etc/cron.weekly 디렉토리내에 존재하는 파일들을 실행
매월 1회 자동실행하기 위한 시스템 크론설정
42 4 1 * * root run-parts /etc/cron.monthly
->매월 1일 새벽 4시 42분마다 /etc/cron.monthly 디렉토리내에 존재하는 파일들을 실행
* root 이외의 사용자에게 crontab 명령어를 이용할 수 있게 하는 방법
- /etc/cron.allow 파일에 사용자의 id를 등록
일반사용자의 crontab 명령어사용을 제안하고자 한다면
- /etc/cron.deny 파일에 사용자의 id 를 등록
3. FAQ
1) cron 설정한 후에는 crond 데몬을 재실행해야 하나요?
아닙니다. crontab -e 으로 설정 후 빠져나오면 바로 적용됩니다.
2) truefeel 사용자는 cron을 못 쓰게 하고 싶습니다.
/etc/cron.allow : 허용할 사용자 ID 목록
/etc/cron.deny : 거부할 사용자 ID 목록
cron.allow 파일이 있으면 이 파일에 들어있는 ID만 사용 가능
cron.deny 파일이 있으면 이 파일에 들어있는 ID는 사용 불가
따라서 cron.deny에 truefeel ID를 추가해주면 됩니다.
3) > /dev/null 2>&1 이 무슨 뜻입니까?
지정한 명령어 처리 결과와 발생할지 모르는 에러메시지를 출력하지 않고 모두 버린다는(/dev/null)는
뜻입니다. 만약 결과와 에러를 파일로 저장하려면 /dev/null 대신 파일명을 적어주면 됩니다.
ASSOC Change file extension associations ASSOCIAT One step file association AT Schedule a command to run at a later time ATTRIB Change file attributes
BOOTCFG Edit Windows boot settings BROWSTAT Get domain, browser and PDC info
CACLS Change file permissions CALL Call one batch program from another CD Change Directory - move to a specific Folder CHANGE Change Terminal Server Session properties CHKDSK Check Disk - check and repair disk problems CHKNTFS Check the NTFS file system CHOICE Accept keyboard input to a batch file CIPHER Encrypt or Decrypt files/folders CleanMgr Automated cleanup of Temp files, recycle bin CLEARMEM Clear memory leaks CLIP Copy STDIN to the Windows clipboard. CLS Clear the screen CLUSTER Windows Clustering CMD Start a new CMD shell COLOR Change colors of the CMD window COMP Compare the contents of two files or sets of files COMPACT Compress files or folders on an NTFS partition COMPRESS Compress individual files on an NTFS partition CON2PRT Connect or disconnect a Printer CONVERT Convert a FAT drive to NTFS. COPY Copy one or more files to another location CSCcmd Client-side caching (Offline Files) CSVDE Import or Export Active Directory data
DATE Display or set the date Dcomcnfg DCOM Configuration Utility DEFRAG Defragment hard drive DEL Delete one or more files DELPROF Delete NT user profiles DELTREE Delete a folder and all subfolders DevCon Device Manager Command Line Utility DIR Display a list of files and folders DIRUSE Display disk usage DISKCOMP Compare the contents of two floppy disks DISKCOPY Copy the contents of one floppy disk to another DNSSTAT DNS Statistics DOSKEY Edit command line, recall commands, and create macros DSADD Add user (computer, group..) to active directory DSQUERY List items in active directory DSMOD Modify user (computer, group..) in active directory
ECHO Display message on screen ENDLOCAL End localisation of environment changes in a batch file ERASE Delete one or more files EXIT Quit the CMD shell EXPAND Uncompress files EXTRACT Uncompress CAB files
FC Compare two files FDISK Disk Format and partition FIND Search for a text string in a file FINDSTR Search for strings in files FOR /F Loop command: against a set of files FOR /F Loop command: against the results of another command FOR Loop command: all options Files, Directory, List FORFILES Batch process multiple files FORMAT Format a disk FREEDISK Check free disk space (in bytes) FSUTIL File and Volume utilities FTP File Transfer Protocol FTYPE Display or modify file types used in file extension associations
GLOBAL Display membership of global groups GOTO Direct a batch program to jump to a labelled line
HELP Online Help HFNETCHK Network Security Hotfix Checker
IF Conditionally perform a command IFMEMBER Is the current user in an NT Workgroup IPCONFIG Configure IP
LABEL Edit a disk label LOCAL Display membership of local groups LOGEVENT Write text to the NT event viewer. LOGOFF Log a user off LOGTIME Log the date and time in a file
MAPISEND Send email from the command line MEM Display memory usage MD Create new folders MKLINK Create a symbolic link (linkd) MODE Configure a system device MORE Display output, one screen at a time MOUNTVOL Manage a volume mount point MOVE Move files from one folder to another MOVEUSER Move a user from one domain to another MSG Send a message MSIEXEC Microsoft Windows Installer MSINFO Windows NT diagnostics MSTSC Terminal Server Connection (Remote Desktop Protocol) MUNGE Find and Replace text within file(s) MV Copy in-use files
NET Manage network resources NETDOM Domain Manager NETSH Configure network protocols NETSVC Command-line Service Controller NBTSTAT Display networking statistics (NetBIOS over TCP/IP) NETSTAT Display networking statistics (TCP/IP) NOW Display the current Date and Time NSLOOKUP Name server lookup NTBACKUP Backup folders to tape NTRIGHTS Edit user account rights
PATH Display or set a search path for executable files PATHPING Trace route plus network latency and packet loss PAUSE Suspend processing of a batch file and display a message PERMS Show permissions for a user PERFMON Performance Monitor PING Test a network connection POPD Restore the previous value of the current directory saved by PUSHD PORTQRY Display the status of ports and services PRINT Print a text file PRNCNFG Display, configure or rename a printer PRNMNGR Add, delete, list printers set the default printer PROMPT Change the command prompt PsExec Execute process remotely PsFile Show files opened remotely PsGetSid Display the SID of a computer or a user PsInfo List information about a system PsKill Kill processes by name or process ID PsList List detailed information about processes PsLoggedOn Who's logged on (locally or via resource sharing) PsLogList Event log records PsPasswd Change account password PsService View and control services PsShutdown Shutdown or reboot a computer PsSuspend Suspend processes PUSHD Save and then change the current directory
QGREP Search file(s) for lines that match a given pattern.
RASDIAL Manage RAS connections RASPHONE Manage RAS connections RECOVER Recover a damaged file from a defective disk. REG Registry: Read, Set, Export, Delete keys and values REGEDIT Import or export registry settings REGSVR32 Register or unregister a DLL REGINI Change Registry Permissions REM Record comments (remarks) in a batch file REN Rename a file or files. REPLACE Replace or update one file with another RD Delete folder(s) RDISK Create a Recovery Disk RMTSHARE Share a folder or a printer ROBOCOPY Robust File and Folder Copy ROUTE Manipulate network routing tables RUNAS Execute a program under a different user account RUNDLL32 Run a DLL command (add/remove print connections)
SC Service Control SCHTASKS Create or Edit Scheduled Tasks SCLIST Display NT Services ScriptIt Control GUI applications SET Display, set, or remove environment variables SETLOCAL Control the visibility of environment variables SETX Set environment variables permanently SHARE List or edit a file share or print share SHIFT Shift the position of replaceable parameters in a batch file SHORTCUT Create a windows shortcut (.LNK file) SHOWGRPS List the NT Workgroups a user has joined SHOWMBRS List the Users who are members of a Workgroup SHUTDOWN Shutdown the computer SLEEP Wait for x seconds SOON Schedule a command to run in the near future SORT Sort input START Start a separate window to run a specified program or command SU Switch User SUBINACL Edit file and folder Permissions, Ownership and Domain SUBST Associate a path with a drive letter SYSTEMINFO List system configuration
TASKLIST List running applications and services TIME Display or set the system time TIMEOUT Delay processing of a batch file TITLE Set the window title for a CMD.EXE session TOUCH Change file timestamps TRACERT Trace route to a remote host TREE Graphical display of folder structure TYPE Display the contents of a text file
USRSTAT List domain usernames and last login
VER Display version information VERIFY Verify that files have been saved VOL Display a disk label
WHERE Locate and display files in a directory tree WHOAMI Output the current UserName and domain WINDIFF Compare the contents of two files or sets of files WINMSD Windows system diagnostics WINMSDP Windows system diagnostics II WMIC WMI Commands
XCACLS Change file permissions XCOPY Copy files and folders