5 replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
source | link
ls -t1 /mnt/dwh/ftp/dwh_ftp_cbs/ARLOGS/ | tail -n +22 | xargs rm -f

Won't work because the output of ls will only include the files' names, not their full path. It would also skip files whose name starts with a ..

cd /mnt/dwh/ftp/dwh && ls -At1 | tail -n +21 | xargs rm -f --

would solve that, but you'd still have problems with filenames that contain blanks or newline or apostrophe or backslash or double quote characters (and possibly file names with bytes that don't form valid characters in the locale).

(export LC_ALL=C
 cd /mnt/dwh/ftp/dwh && ls -At1 |
   tail -n +21 |
   sed 's/"/\\"/g;s/.*/"&"/' |
   xargs rm -f --
)

would fix most of those, but you'd still have a problem with filenames containing newline characters. The problem is that the output of ls -At1 is not post-processable.

The output of ls -Atd1 ./.* ./* could be post-processed (as those ./ prefixes indicate where each filename starts in the output, but not easily), but you run the risk of reaching the limit on the number of arguments passed to a command by passing the list of filenames to ls like that.

Best would be to use a shell that can do that sorting in its globsuse a shell that can do that sorting in its globs, or rely on GNU extensions if your only need to work on GNU systems:

 cd /mnt/dwh/ftp/dwh &&
   find . ! -name . -prune ! -type d -printf '%T@\t%p\0' |
     tr '\0\n' '\n\0' |
     sort -rn |
     tail -n +21 |
     cut -f 2- |
     tr '\0\n' '\n\0' |
     xargs -r0 rm -f

Here, we're excluding file of type directory, which will affect the numbering but is probably closer to what you want as I don't suppose you want to remove directories. If you want to remove directories, remove the -type d and add the -r option to rm.

Or:

eval "set -- $(COLUMNS=4294967295 ls -Atx --quoting-style=shell-always)"
if [ "$#" -gt 20 ]; then
  shift 20
  printf '%s\0' "$@" | xargs -r0 rm -f --
fi

Or use a generic programming language like perl, python, ruby...

ls -t1 /mnt/dwh/ftp/dwh_ftp_cbs/ARLOGS/ | tail -n +22 | xargs rm -f

Won't work because the output of ls will only include the files' names, not their full path. It would also skip files whose name starts with a ..

cd /mnt/dwh/ftp/dwh && ls -At1 | tail -n +21 | xargs rm -f --

would solve that, but you'd still have problems with filenames that contain blanks or newline or apostrophe or backslash or double quote characters (and possibly file names with bytes that don't form valid characters in the locale).

(export LC_ALL=C
 cd /mnt/dwh/ftp/dwh && ls -At1 |
   tail -n +21 |
   sed 's/"/\\"/g;s/.*/"&"/' |
   xargs rm -f --
)

would fix most of those, but you'd still have a problem with filenames containing newline characters. The problem is that the output of ls -At1 is not post-processable.

The output of ls -Atd1 ./.* ./* could be post-processed (as those ./ prefixes indicate where each filename starts in the output, but not easily), but you run the risk of reaching the limit on the number of arguments passed to a command by passing the list of filenames to ls like that.

Best would be to use a shell that can do that sorting in its globs, or rely on GNU extensions if your only need to work on GNU systems:

 cd /mnt/dwh/ftp/dwh &&
   find . ! -name . -prune ! -type d -printf '%T@\t%p\0' |
     tr '\0\n' '\n\0' |
     sort -rn |
     tail -n +21 |
     cut -f 2- |
     tr '\0\n' '\n\0' |
     xargs -r0 rm -f

Here, we're excluding file of type directory, which will affect the numbering but is probably closer to what you want as I don't suppose you want to remove directories. If you want to remove directories, remove the -type d and add the -r option to rm.

Or:

eval "set -- $(COLUMNS=4294967295 ls -Atx --quoting-style=shell-always)"
if [ "$#" -gt 20 ]; then
  shift 20
  printf '%s\0' "$@" | xargs -r0 rm -f --
fi

Or use a generic programming language like perl, python, ruby...

ls -t1 /mnt/dwh/ftp/dwh_ftp_cbs/ARLOGS/ | tail -n +22 | xargs rm -f

Won't work because the output of ls will only include the files' names, not their full path. It would also skip files whose name starts with a ..

cd /mnt/dwh/ftp/dwh && ls -At1 | tail -n +21 | xargs rm -f --

would solve that, but you'd still have problems with filenames that contain blanks or newline or apostrophe or backslash or double quote characters (and possibly file names with bytes that don't form valid characters in the locale).

(export LC_ALL=C
 cd /mnt/dwh/ftp/dwh && ls -At1 |
   tail -n +21 |
   sed 's/"/\\"/g;s/.*/"&"/' |
   xargs rm -f --
)

would fix most of those, but you'd still have a problem with filenames containing newline characters. The problem is that the output of ls -At1 is not post-processable.

The output of ls -Atd1 ./.* ./* could be post-processed (as those ./ prefixes indicate where each filename starts in the output, but not easily), but you run the risk of reaching the limit on the number of arguments passed to a command by passing the list of filenames to ls like that.

Best would be to use a shell that can do that sorting in its globs, or rely on GNU extensions if your only need to work on GNU systems:

 cd /mnt/dwh/ftp/dwh &&
   find . ! -name . -prune ! -type d -printf '%T@\t%p\0' |
     tr '\0\n' '\n\0' |
     sort -rn |
     tail -n +21 |
     cut -f 2- |
     tr '\0\n' '\n\0' |
     xargs -r0 rm -f

Here, we're excluding file of type directory, which will affect the numbering but is probably closer to what you want as I don't suppose you want to remove directories. If you want to remove directories, remove the -type d and add the -r option to rm.

Or:

eval "set -- $(COLUMNS=4294967295 ls -Atx --quoting-style=shell-always)"
if [ "$#" -gt 20 ]; then
  shift 20
  printf '%s\0' "$@" | xargs -r0 rm -f --
fi

Or use a generic programming language like perl, python, ruby...

4 added 263 characters in body
source | link
ls -t1 /mnt/dwh/ftp/dwh_ftp_cbs/ARLOGS/ | tail -n +22 | xargs rm -f

Won't work because the output of ls will only include the files' names, not their full path. It would also skip files whose name starts with a ..

cd /mnt/dwh/ftp/dwh && ls -At1 | tail -n +21 | xargs rm -f --

would solve that, but you'd still have problems with filenames that contain blanks or newline or apostrophe or backslash or double quote characters (and possibly file names with bytes that don't form valid characters in the locale).

(export LC_ALL=C
 cd /mnt/dwh/ftp/dwh && ls -At1 |
   tail -n +21 |
   sed 's/"/\\"/g;s/.*/"&"/' |
   xargs rm -f --
)

would fix most of those, but you'd still have a problem with filenames containing newline characters. The problem is that the output of ls -At1 is not post-processable.

The output of ls -Atd1 ./.* ./* could be post-processed (as those ./ prefixes indicate where each filename starts in the output, but not easily), but you run the risk of reaching the limit on the number of arguments passed to a command by passing the list of filenames to ls like that.

Best would be to use a shell that can do that sorting in its globs, or rely on GNU extensions if your only need to work on GNU systems:

 cd /mnt/dwh/ftp/dwh &&
   find . ! -name . -prune ! -type d -printf '%T@\t%p\0' |
     tr '\0\n' '\n\0' |
     sort -rn |
     tail -n +21 |
     cut -f 2- |
     tr '\0\n' '\n\0' |
     xargs -r0 rm -f

Here, we're excluding file of type directory, which will affect the numbering but is probably closer to what you want as I don't suppose you want to remove directories. If you want to remove directories, remove the -type d and add the -r option to rm.

Or:

eval "set -- $(COLUMNS=4294967295 ls -Atx --quoting-style=shell-always)"
if [ "$#" -gt 20 ]; then
  shift 20
  printf '%s\0' "$@" | xargs -r0 rm -f --
fi

Or use a generic programming language like perl, python, ruby...

ls -t1 /mnt/dwh/ftp/dwh_ftp_cbs/ARLOGS/ | tail -n +22 | xargs rm -f

Won't work because the output of ls will only include the files' names, not their full path. It would also skip files whose name starts with a ..

cd /mnt/dwh/ftp/dwh && ls -At1 | tail -n +21 | xargs rm -f --

would solve that, but you'd still have problems with filenames that contain blanks or newline or apostrophe or backslash or double quote characters (and possibly file names with bytes that don't form valid characters in the locale).

(export LC_ALL=C
 cd /mnt/dwh/ftp/dwh && ls -At1 |
   tail -n +21 |
   sed 's/"/\\"/g;s/.*/"&"/' |
   xargs rm -f --
)

would fix most of those, but you'd still have a problem with filenames containing newline characters. The problem is that the output of ls -At1 is not post-processable.

The output of ls -Atd1 ./.* ./* could be post-processed (as those ./ prefixes indicate where each filename starts in the output, but not easily), but you run the risk of reaching the limit on the number of arguments passed to a command by passing the list of filenames to ls like that.

Best would be to use a shell that can do that sorting in its globs, or rely on GNU extensions if your only need to work on GNU systems:

 cd /mnt/dwh/ftp/dwh &&
   find . ! -name . -prune ! -type d -printf '%T@\t%p\0' |
     tr '\0\n' '\n\0' |
     sort -rn |
     tail -n +21 |
     cut -f 2- |
     tr '\0\n' '\n\0' |
     xargs -r0 rm -f

Or:

eval "set -- $(COLUMNS=4294967295 ls -Atx --quoting-style=shell-always)"
if [ "$#" -gt 20 ]; then
  shift 20
  printf '%s\0' "$@" | xargs -r0 rm -f --
fi

Or use a generic programming language like perl, python, ruby...

ls -t1 /mnt/dwh/ftp/dwh_ftp_cbs/ARLOGS/ | tail -n +22 | xargs rm -f

Won't work because the output of ls will only include the files' names, not their full path. It would also skip files whose name starts with a ..

cd /mnt/dwh/ftp/dwh && ls -At1 | tail -n +21 | xargs rm -f --

would solve that, but you'd still have problems with filenames that contain blanks or newline or apostrophe or backslash or double quote characters (and possibly file names with bytes that don't form valid characters in the locale).

(export LC_ALL=C
 cd /mnt/dwh/ftp/dwh && ls -At1 |
   tail -n +21 |
   sed 's/"/\\"/g;s/.*/"&"/' |
   xargs rm -f --
)

would fix most of those, but you'd still have a problem with filenames containing newline characters. The problem is that the output of ls -At1 is not post-processable.

The output of ls -Atd1 ./.* ./* could be post-processed (as those ./ prefixes indicate where each filename starts in the output, but not easily), but you run the risk of reaching the limit on the number of arguments passed to a command by passing the list of filenames to ls like that.

Best would be to use a shell that can do that sorting in its globs, or rely on GNU extensions if your only need to work on GNU systems:

 cd /mnt/dwh/ftp/dwh &&
   find . ! -name . -prune ! -type d -printf '%T@\t%p\0' |
     tr '\0\n' '\n\0' |
     sort -rn |
     tail -n +21 |
     cut -f 2- |
     tr '\0\n' '\n\0' |
     xargs -r0 rm -f

Here, we're excluding file of type directory, which will affect the numbering but is probably closer to what you want as I don't suppose you want to remove directories. If you want to remove directories, remove the -type d and add the -r option to rm.

Or:

eval "set -- $(COLUMNS=4294967295 ls -Atx --quoting-style=shell-always)"
if [ "$#" -gt 20 ]; then
  shift 20
  printf '%s\0' "$@" | xargs -r0 rm -f --
fi

Or use a generic programming language like perl, python, ruby...

3 added 10 characters in body
source | link
ls -t1 /mnt/dwh/ftp/dwh_ftp_cbs/ARLOGS/ | tail -n +22 | xargs rm -f

Won't work because the output of ls will only include the files' names, not their full path. It would also skip files whose name starts with a ..

cd /mnt/dwh/ftp/dwh && ls -At1 | tail -n +21 | xargs rm -f --

would solve that, but you'd still have problems with filenames that contain blanks or newline or apostrophe or backslash or double quote characters (and possibly file names with bytes that don't form valid characters in the locale).

(export LC_ALL=C
 cd /mnt/dwh/ftp/dwh && ls -At1 |
   tail -n +21 |
   sed 's/"/\\"/g;s/.*/"&"/' |
   xargs rm -f --
)

would fix most of those, but you'd still have a problem with filenames containing newline characters. The problem is that the output of ls -At1 is not post-processable.

The output of ls -Atd1 ./.* ./* could be post-processed (as those ./ prefixes indicate where each filename starts in the output, but not easily), but you run the risk of reaching the limit on the number of arguments passed to a command by passing the list of filenames to ls like that.

Best would be to use a shell that can do that sorting in its globs, or rely on GNU extensions if your only need to work on GNU systems:

 cd /mnt/dwh/ftp/dwh &&
   find . ! -name . -prune ! -type d -printf '%T@\t%p\0' |
     tr '\0\n' '\n\0' |
     sort -rn |
     tail -n +21 |
     cut -f 2- |
     tr '\0\n' '\n\0' |
     xargs -r0 rm -f

Or:

eval "set -- $(COLUMNS=4294967295 ls -Atx --quoting-style=shell-always)"
if [ "$#" -gt 20 ]; then
  shift 20
  printf '%s\0' "$@" | xargs -r0 rm -f --
fi

Or use a generic programming language like perl, python, ruby...

ls -t1 /mnt/dwh/ftp/dwh_ftp_cbs/ARLOGS/ | tail -n +22 | xargs rm -f

Won't work because the output of ls will only include the files' names, not their full path. It would also skip files whose name starts with a ..

cd /mnt/dwh/ftp/dwh && ls -At1 | tail -n +21 | xargs rm -f --

would solve that, but you'd still have problems with filenames that contain blanks or newline or apostrophe or backslash or double quote characters (and possibly file names with bytes that don't form valid characters in the locale).

(export LC_ALL=C
 cd /mnt/dwh/ftp/dwh && ls -At1 |
   tail -n +21 |
   sed 's/"/\\"/g;s/.*/"&"/' |
   xargs rm -f --
)

would fix most of those, but you'd still have a problem with filenames containing newline characters. The problem is that the output of ls -At1 is not post-processable.

The output of ls -Atd1 ./.* ./* could be post-processed (as those ./ prefixes indicate where each filename starts in the output, but not easily), but you run the risk of reaching the limit on the number of arguments passed to a command by passing the list of filenames to ls like that.

Best would be to use a shell that can do that sorting in its globs, or rely on GNU extensions if your only need to work on GNU systems:

 cd /mnt/dwh/ftp/dwh &&
   find . ! -name . -prune -printf '%T@\t%p\0' |
     tr '\0\n' '\n\0' |
     sort -rn |
     tail -n +21 |
     cut -f 2- |
     tr '\0\n' '\n\0' |
     xargs -r0 rm -f

Or:

eval "set -- $(COLUMNS=4294967295 ls -Atx --quoting-style=shell-always)"
if [ "$#" -gt 20 ]; then
  shift 20
  printf '%s\0' "$@" | xargs -r0 rm -f --
fi

Or use a generic programming language like perl, python, ruby...

ls -t1 /mnt/dwh/ftp/dwh_ftp_cbs/ARLOGS/ | tail -n +22 | xargs rm -f

Won't work because the output of ls will only include the files' names, not their full path. It would also skip files whose name starts with a ..

cd /mnt/dwh/ftp/dwh && ls -At1 | tail -n +21 | xargs rm -f --

would solve that, but you'd still have problems with filenames that contain blanks or newline or apostrophe or backslash or double quote characters (and possibly file names with bytes that don't form valid characters in the locale).

(export LC_ALL=C
 cd /mnt/dwh/ftp/dwh && ls -At1 |
   tail -n +21 |
   sed 's/"/\\"/g;s/.*/"&"/' |
   xargs rm -f --
)

would fix most of those, but you'd still have a problem with filenames containing newline characters. The problem is that the output of ls -At1 is not post-processable.

The output of ls -Atd1 ./.* ./* could be post-processed (as those ./ prefixes indicate where each filename starts in the output, but not easily), but you run the risk of reaching the limit on the number of arguments passed to a command by passing the list of filenames to ls like that.

Best would be to use a shell that can do that sorting in its globs, or rely on GNU extensions if your only need to work on GNU systems:

 cd /mnt/dwh/ftp/dwh &&
   find . ! -name . -prune ! -type d -printf '%T@\t%p\0' |
     tr '\0\n' '\n\0' |
     sort -rn |
     tail -n +21 |
     cut -f 2- |
     tr '\0\n' '\n\0' |
     xargs -r0 rm -f

Or:

eval "set -- $(COLUMNS=4294967295 ls -Atx --quoting-style=shell-always)"
if [ "$#" -gt 20 ]; then
  shift 20
  printf '%s\0' "$@" | xargs -r0 rm -f --
fi

Or use a generic programming language like perl, python, ruby...

2 added 191 characters in body
source | link
1
source | link