ls 결과를 간결하게 표시하고 싶을 때 보통 어떤 옵션 하시나요?

ytt123의 이미지

ls 옵션을 아래처럼 사용하고요, 출력 화면인데요.

$ls -larht

-rw-rw-r-- 1 myuser mygroup 26424816 Sep 23 17:56 sdrew

제 작업에서, 파일 이름이나 디렉토리가 긴 경우가 많다보니 두 줄로 넘어가는 경우가 종종 있어요. 그래서 창을 조절해야해서 특히 노트북에서 작업할 때 불편합니다.

그래서 아래처럼 사용자이름, 파일 사이즈, 날짜 만 최소한으로 표시 되도록 하려면 옵션을 어떻게 조정해야 할까요.

myuser 26424816 Sep 23 17:56 sdrew

ymir의 이미지

$ alias lls='/bin/ls -l --time-style=long-iso | while read -r p i u g s d h n; do echo "$u $s $d $h $n"; done'
$ lls
 
ymir 311938116 2019-09-26 09:24 2019-09-26-raspbian-buster-lite.img.xz
ymir 5854936 2022-10-24 21:14 dwarfs-0.6.2-Linux.tar.xz
ymir 1002126328 2020-01-17 10:36 kali-linux-2019.4-rpi3-nexmon.img.xz

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

ytt123의 이미지

항상 감동...합니다.

혹시, 정렬을 깔끔하게 할 수도 있을까요? 그러니까 두번째 컬럼(파일 크기)가 자리수가 제각각 이라서요, 이 자리수를 공란으로 (좌 또는 우 정렬되게) 할 수 있으면 가독성이 더 좋을 거 같아서요.

감사합니다.

ymir의 이미지

$ alias lls2='/bin/ls -l --time-style=long-iso | while read -r p i u g s d h n; do printf "%s %10s %s %s %s\n" $u $s $d $h $n; done'
$ lls2
 
ymir  311938116 2019-09-26 09:24 2019-09-26-raspbian-buster-lite.img.xz
ymir    5854936 2022-10-24 21:14 dwarfs-0.6.2-Linux.tar.xz
ymir 1002126328 2020-01-17 10:36 kali-linux-2019.4-rpi3-nexmon.img.xz

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

ytt123의 이미지

도움이 많이 되었어요.

한가지 궁금한 점은,

ls 다음에 --color=auto 옵션을 써주어도 파일에 색깔이 안입혀지네요.

이것도 색깔 입힐 수 있나요?

ymir의 이미지

$ man ls
...
       --color[=WHEN]
              colorize  the output; WHEN can be 'always' (default if omitted),
              'auto', or 'never'; more info below
...
       Using  color  to distinguish file types is disabled both by default and
       with --color=never.  With --color=auto, ls emits color codes only  when
       standard  output is connected to a terminal.  The LS_COLORS environment
       variable can change the settings.  Use the dircolors command to set it.
...

auto 대신 always 를 쓰세요.

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

ymir의 이미지

$ alias lst='stat -c "%U %s %y %n" *'
$ lst
ymir 311938116 2019-09-26 09:24:27.000000000 +0900 2019-09-26-raspbian-buster-lite.img.xz
ymir 5854936 2022-10-24 21:14:16.000000000 +0900 dwarfs-0.6.2-Linux.tar.xz
ymir 1002126328 2020-01-17 10:36:47.746255600 +0900 kali-linux-2019.4-rpi3-nexmon.img.xz

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

김정균의 이미지

이건 어떠신가요? 약간의 formatting 까지..

[oops@main ~]$ alias lz="ls -larht --time-style=long-iso | awk '{ if ( \$3 != \"\" ) { printf (\"%-10s %5s %10s %5s %s\\n\", \$3, \$5, \$6, \$7, \$8); } }'"
[oops@main ~]$ lz
 
user         193 2016-12-14 00:17 .bash_profile
user          18 2016-12-14 00:17 .bash_logout
root          18 2017-01-17 12:58 ..
user         451 2017-01-17 17:12 .bashrc
user          65 2017-01-17 17:14 .subversion
user         106 2017-01-24 13:13 .gitconfig
user        3.9K 2017-02-26 21:28 .mysql_history
user         864 2017-07-20 02:02 .bash_history
ytt123의 이미지

주옥같은 답변 들, 항상 감사할 뿐입니다!

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.