Results 1 to 5 of 5

Thread: output to a fileout (home directory)

  1. #1
    Join Date
    Oct 2006
    Beans
    607

    output to a fileout (home directory)

    Code:
    'du -sk /home/* | sort -n | perl -ne '\''($s,$f)=split(m{\t});for (qw(K M G)) {if($s<1024) {printf("%.1f",$s);print "$_\t$f"; last};$s=$s/1024}'\' | >> /tmp/file_useage
    I need this to output to a file, as i want all home directory listed in size but it a text file

    I know this work if I alias it (which is the way i have been working out previously for admin work but i need to extract it for a manager and it need to be a text file

    Code:
    alias duf='du -sk /home/* | sort -n | perl -ne '\''($s,$f)=split(m{\t});for (qw(K M G)) {if($s<1024) {printf("%.1f",$s);print "$_\t$f"; last};$s=$s/1024}'\'

  2. #2
    Join Date
    Apr 2009
    Location
    Germany
    Beans
    2,134
    Distro
    Ubuntu Development Release

    Re: output to a fileout (home directory)

    the pipe at the end is wrong when you want to output into a file:
    Code:
    ...4}'\' | >> /tmp/file_useage
    remove   ^ this

  3. #3
    Join Date
    Oct 2006
    Beans
    607

    Re: output to a fileout (home directory)

    tried that get this instead
    -bash: du -sk /home/* | sort -n | perl -ne '($s,$f)=split(m{\t});for (qw(K M G)) {if($s<1024) {printf("%.1f",$s);print "$_\t$f"; last};$s=$s/1024}': No such file or directory
    Any more ideas?

  4. #4
    Join Date
    Oct 2006
    Beans
    607

    Re: output to a fileout (home directory)

    Fixed it.... a cup of tea and clear head!!
    Code:
    alias duf='du -sk /home/* | sort -n | perl -ne '\''($s,$f)=split(m{\t});for (qw(K M G)) {if($s<1024) {printf("%.1f",$s);print "$_\t$f"; last};$s=$s/1024}'\' | duf >> /tmp/file_useage
    just pipe alias duf out to a file

  5. #5
    Join Date
    Jul 2009
    Location
    London
    Beans
    1,480
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: output to a fileout (home directory)

    Quote Originally Posted by ibizatunes View Post
    Fixed it.... a cup of tea and clear head!!
    Code:
    alias duf='du -sk /home/* | sort -n | perl -ne '\''($s,$f)=split(m{\t});for (qw(K M G)) {if($s<1024) {printf("%.1f",$s);print "$_\t$f"; last};$s=$s/1024}'\' | duf >> /tmp/file_useage
    just pipe alias duf out to a file
    this makes no sense to me.

    Either:
    (a) you define your alias to generate results to std out, and then when wishing to save the results you execute the alias with a redirection, e.g:
    Code:
    $ alias duf='du -sk /home/* | sort -n | perl -ne '\''($s,$f)=split(m{\t});for (qw(K M G)) {if($s<1024) {printf("%.1f",$s);print "$_\t$f"; last};$s=$s/1024}'\'
    $ duf > /path/to/some/file
    (b) Or, you define your alias with redirection to a file builtin, so that you just execute the alias.
    Code:
    $ alias duf='du -sk /home/* | sort -n | perl -ne '\''($s,$f)=split(m{\t});for (qw(K M G)) {if($s<1024) {printf("%.1f",$s);print "$_\t$f"; last};$s=$s/1024}'\'' > /path/to/some/file'
    $ duf
    you probably want > redirection rather than >> since with >> you will append results to the file each time rather than replacing what was previously there.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •