2017년 12월 18일 월요일

리눅스 ipcs 정리

#!/bin/sh
SHMID=`ipcs -m | grep $USER | cut -d " " -f2`
SEMID=`ipcs -s | grep $USER | cut -d " " -f2`
MSQID=`ipcs -q | grep $USER | cut -d " " -f2`
for shm in $SHMID
do
        ipcrm -m $shm
done
for sem in $SEMID
do
        ipcrm -s $sem
done
for msq in $MSQID
do
        ipcrm -q $msq
done

리눅스 자신의 프로세스 모니터링

cat monitor.sh

#!/bin/sh
while [ 1 ];
do
ps -ef | grep $USER
sleep 1
clear
done

2017년 4월 4일 화요일

[리눅스,유닉스] 공백이나 특수문자 등으로 시작하는 파일 지우기

종종 시스템에 웃지 못할 파일이 있는 경우
즉, 공백이나 특수문자, 혹은 - 문자로 시작하는 파일도 지울 수 없을 때 사용
$ ls -ltri
702887 -rw-r--r--   1 perf       users          566 Apr  5 08:06 perftest.sh
630368 -rw-r--r--   1 perf       users         2252 Apr  5 08:07 compare.sh
702892 drwxrwxrwx   8 perf       users         1024 Apr  5 08:07 work
5486485 -rw-rw-rw-   1 perf       users         566 Apr  5 08
5486498 -rw-r--r--   1 perf       users       35200 Apr  5 09:31 perf.tar

$ find . -inum 5486485 -exec rm -f {} \;

$ ls -ltri
702887 -rw-r--r--   1 perf       users          566 Apr  5 08:06 perftest.sh
630368 -rw-r--r--   1 perf       users         2252 Apr  5 08:07 compare.sh
702892 drwxrwxrwx   8 perf       users         1024 Apr  5 08:07 work
5486498 -rw-r--r--   1 perf       users       35200 Apr  5 09:31 perf.tar

2017년 3월 20일 월요일

Query exercise

직업별 컬럼을 생성하여 정리하되 doctor, professor, singer, actor순서로 정렬하며
각 컬럼은 alpabet 오름 차순으로 정렬
Data

iSQL> select * from occupations;
NAME                  OCCUPATION
-----------------------------------------------
Ashley                   Professor
Samantha              Actor
Julia                      Doctor
Britney                 Professor
Maria                   Professor
Meera                  Professor
Priya                   Doctor
Priyanka              Professor
Jennifer               Actor
Ketty                   Actor
Belvet                  Professor
Naomi                 Professor
Jane                    Singer
Jenny                  Singer
Kristeen              Singer
Christeen            Singer
Eve                    Actor
Aamina              Doctor
18 rows selected.



Output

DOCTOR                PROFESSOR             SINGER                ACTOR
---------------------------------------------------------------------------------------------
Aamina                Ashley                Christeen             Eve
Julia                     Belvet                Jane                  Jennifer
Priya                    Britney               Jenny                 Ketty
                            Maria                 Kristeen              Samantha
                            Meera
                            Naomi
                            Priyanka
7 rows selected.

문제 출처: hackerrank

My Answer

select doctor, professor, singer, actor from
(
select rownum rown from (select name as doctor from occupations where occupation = 'Doctor' order by name)
union
select rownum rown from (select name as professor from occupations where occupation = 'Professor' order by name)
union
select rownum rown from (select name as singer from occupations where occupation = 'Singer' order by name)
union
select rownum rown from (select name as actor from occupations where occupation = 'Actor' order by name)
) main,
(select rownum rown, doctor from (select name as doctor from occupations where occupation = 'Doctor' order by name)) a,
(select rownum rown, professor from (select name as professor from occupations where occupation = 'Professor' order by name)) b,
(select rownum rown, singer from (select name as singer from occupations where occupation = 'Singer' order by name)) c,
(select rownum rown, actor from (select name as actor from occupations where occupation = 'Actor' order by name)) d
where main.rown=a.rown(+)
and main.rown=b.rown(+)
and main.rown=c.rown(+)
and main.rown=d.rown(+);


리눅스 문자와숫자 조합의 파일이름 정렬( Sort alphanumeric filenames in Linux )

아래 처럼 문자와 숫자가 섞여 있는 파일에 대해서 정렬이 제대로 되지 않을 때 When sorting is not done properly for files with mixed letters and numbers as shown below [codeh...