I frequently need to remove empty directories (and files). Poorly written scripts (my own) make them at times. For me this does the job nicely.
find . -empty | xargs rmdir
Cheers
Govind Chandra
On Fri, May 04, 2007 at 02:50:51PM +0100, Barrys linux mail wrote:
Govind Chandra wrote:
find . -empty | xargs rmdir
Cheers
Govind Chandra
Hi really dumb question, still learning about commands for the terminal. please tell me what is the symbol after the word empty and before xargs, is that you hitting the enter key?
No, that's the pipe... basically, takes stdout from one command and "pipes" it in to stdin on the other command.
Cheers,
On Fri, May 04, 2007 at 02:56:43PM +0100, David Reynolds wrote:
On 4 May 2007, at 2:54 pm, Brett Parker wrote:
No, that's the pipe... basically, takes stdout from one command and "pipes" it in to stdin on the other command.
What's stdout? :P
It's the standard output stream, of course... s'where stuff gets printed at!
What's a nubian?
Good question... lets find out...
From WordNet (r) 2.0 [wn]:
Nubian n : a native or inhabitant of Nubia; "Nubians now form an ethnic minority in Egypt"
There go, you've learnt something new! (dict++)
Thanks,
On 04/05/07, Barrys linux mail bazubuntumail@tiscali.co.uk wrote:
Hi really dumb question, still learning about commands for the terminal. please tell me what is the symbol after the word empty and before xargs, is that you hitting the enter key? Barry
No, it's meant to be there. It's a pipe character (or virtual bar):
http://en.wikipedia.org/wiki/Vertical_bar
It shares a key on the keyboard with \ and sends the output from one command as an input to another.
HTH,
Peter.
On 04-May-07 13:50:51, Barrys linux mail wrote:
Govind Chandra wrote:
find . -empty | xargs rmdir
Cheers
Govind Chandra
Hi really dumb question, still learning about commands for the terminal. please tell me what is the symbol after the word empty and before xargs, is that you hitting the enter key? Barry
No, it's the vertical bar (Shift + "" on most keyboards).
It's used in a command to denote a "pipe" -- the output of one command ("find" in this case) is piped into the input of another command (here "xargs").
The concept of a pipe goes back to the very origins of Unix (from which Linux is derived, of course), and is a key component in the originators' ideal that complex tasks should be broken down into simpler tasks, and each such task assigned to a small and simple program specially written to perform that specific kind of task efficiently and well.
Thus, for instance, go into a directory with a lot of files in it, and give the command below (you can enter the following lines separately as shown, if you want to, since the shell will wait until the command is syntactically complete):
ls -l | awk '{print $5 " " $9}' | sort -n | awk '{cum += $1};{print $2 "\t" $1 "\t" cum}' | less
This will print the name of each file, followed by its size in bytes, followed by the cumulative total of sizes so far, with the filenames being printed in the order of increasing file size. rationale:
ls -l |
lists the files in long format, with the filename in position 9 and the byte-size in position 5, and pipes this output intoL
awk '{print $5 " " $9}' |
which extracts the fields in the 5th and 9th positions and outputs them (in that order) separated by a space; and pipes them into
sort -n |
which sorts its input in numerical order (so that 256 precedes 1024, and not the other (alphabetical) way round, which is what 'sort' does by default); and pipes its output into
awk '{cum += $1};{print $2 "\t" $1 "\t" cum}' |
which calculates the cumulative total 'cum' by adding the number in the first position (byte-size) to 'cum'. and then outputting the results as follows:
first, the item in the second position of its intput (filename) next, the item in the first position (file byte-size) finally, the value of 'cum' all separated by TABs; and pipes its output to
less
so that you can page through it.
There's also a command 'tee' (for "T-junction") such that
<anything that produces output> | tee file1 file2 ... filek
copies the output into all of the files file1 ... filek and *also* produces output which is available for piping into any other command.
This you can set up not just a chain of piped commands as above, but can also pick up the results of earlier commends and process these at a later stage, and merge them in.
These sorts of command linkage are known in the trade as "Unix plumbing", and represent a technique for joining up simple commands (each of which "does one job and does it well" in the words of Kernighan and Ritchie) to carry out a complicated task.
It not only beats the clunky cumbersome performance of "this program can do everything" software, which is usually massively heavy and in any cases doesn't "do everything" but only what its writers thought it needed to do; may not do it very well (think Word); and doesn't offer you much scope to "roll your own".
Hoping this helps, Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) ted.harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 04-May-07 Time: 15:28:18 ------------------------------ XFMail ------------------------------
On Fri, May 04, 2007 at 02:22:42PM +0100, Govind Chandra wrote:
I frequently need to remove empty directories (and files). Poorly written scripts (my own) make them at times. For me this does the job nicely.
find . -empty | xargs rmdir
Yes, fine, but doesn't work for empty maildir folders.
The requirement for deleting a maildir is:-
There's a dirctory with 'cur', 'new' and 'tmp' sub-directories. All of 'cur', 'new' and 'tmp' are empty.