유닉스, 리눅스 ls, find질문

wongidos의 이미지

안녕하세요.
ls, find명령어를 잘 몰라서 문의 드립니다.
파일 사이즈나 생성 순서가 아닌 파일 이름 기준입니다.

인자: completed_20FEB2018_0800.csv

1. completed_20FEB2018_0800.csv 보다 큰 것 중에
2. 오름차순해서
3. 제일 위 1건….

Ex)

1. file_01MON2018_0000.zip
2. file_01MON2018_0800.zip
3. file_01MON2018_1600.zip
4. file_02MON2018_0000.zip
5. file_02MON2018_0800.zip
6. file_02MON2018_1600.zip
args가 3이면 4,5,6중에 4를 가져옴.
args가 1이면 2,3,4,5,6중에 1를 가져옴.
Args가 6이면 null..
이게 가능할까요?

ymir의 이미지

sed 'Nq;d' 로 N 번째 라인만 출력할 수 있습니다.
ls -1 | sed '2q;d' 과 같이 입력하면 두 번째 파일명만 출력 됩니다.
저 N 을 원하는 숫자+1 로 바꿔주면, 입력한 숫자의 다음 라인이 출력되겠죠.

추가> sed -n 'Np' 도 위와 마찬가지로, N 번째 라인만 출력합니다.

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

wongidos의 이미지

파일명 중에 file_01MON2018_0800.zip보다 크다는 어떤 명령어를 쓰야 하는지요?
즉, ls 된 것 중에 파일명 기준 file_01MON2018_0800.zip보다 큰것을 가져오고 싶습니다.

file_01MON2018_0000.zip
file_01MON2018_0800.zip
file_01MON2018_1600.zip
file_02MON2018_0000.zip
file_02MON2018_0800.zip
file_02MON2018_1600.zip

ymir의 이미지

크다 작다는 개념에 매몰되지 말고 순서를 생각하세요.
ls 는 기본적으로 alphanumeric sort 를 해서 결과를 내주니..
원하는 파일명을 찾은 후에 그 다음 라인만 출력해 주면 되겠죠.

$ ls -1
file_01MON2018_0000.zip
file_01MON2018_0800.zip
file_01MON2018_1600.zip
file_02MON2018_0000.zip
file_02MON2018_0800.zip
file_02MON2018_1600.zip
$ ls -1 | grep -A1 file_01MON2018_0800.zip
file_01MON2018_0800.zip
file_01MON2018_1600.zip
$ ls -1 | grep -A1 file_01MON2018_0800.zip | tail -1
file_01MON2018_1600.zip

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

wongidos의 이미지

대단하십니다.^^

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.