4

When I run this command from php

sudo -u db2inst1 ls -t /var/lib/edumate/bdrs/*/*/daily/*NODE* | sort -r

I receive sudo: unable to execute /bin/ls: Argument list too long

ls lists all daily backup files we have for each customer. Customer has their directory under the bdrs directory. So I guess the number of files got bigger than allowed because it used to work correctly.

Is there any way how to get list of all daily backup files using one shell command?

Radek
  • 2,993
  • 18
  • 39
  • 52

2 Answers2

6

Convert it to find so that the expanded file names won't be in the actual command (right now the shell is "globbing" which you don't want.

sudo -u db2inst1 find /var/lib/edumate/bdrs/ -ipath '/var/lib/edumate/bdrs/*/*/daily/*NODE*' | sort -r

1

It's rather easier with zsh. Its On glob qualifier changes the sorting order to in reverse lexicographic name order.

sudo -u db2inst1 zsh -c 'print -l /var/lib/edumate/bdrs/*/*/daily/*NODE*(On)'

There's no point in passing -t to ls, by the way, since you don't care about its sorting order.

  • I do care about sorting :-) I need the files to be sorted desc by creation time. – Radek Jul 19 '12 at 01:02
  • @Radek Your sample command pipes into sort -r, which sorts by name (descending): the order of the ls output is irrelevant. You can't sort by file creation time because most unix systems do not store file creation times. You can easily sort by modification time in zsh: replace (On) by (om) (this is difficult to do without zsh). But for backup files, the name may be the right way to sort, if it encodes the date. – Gilles 'SO- stop being evil' Jul 19 '12 at 01:05
  • The filenames contain a timestamp. You're right ... I started with -t and then added sort -r and left -t in place doing nothing. Anyway, your code works and it is sorted as I need. Thank you. – Radek Jul 19 '12 at 01:07