Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I had a directory named myname which was archived in myname.tar. Now I want to take myname.tar, unarchive it, and delete all the files in the myname directory (after unarchiving).

Here are my commands for the above task:

find -name deleteme.tar
tar -xvf deleteme.tar
rm -r delete/*

These individual commands are working fine, but I need a one-line command, so I tried this:

find -name deleteme.tar | tar -xvf deleteme.at | rm -r delete/*

I got this error:

"rm -r deleteme/*
rm: cannot remove `deleteme/*': No such file or directory "

What am I doing wrong?

share|improve this question
Try replacing your | symbols with ; instead: find -name deleteme.tar; tar -xvf deleteme.tar; rm -r delete/* – ire_and_curses Sep 10 '12 at 20:31
The command sequence doesn't make a whole lot of sense to me. It reads like: find tar file, extract tar file, delete extracted contents. Is the purpose to exercise the hard disk? – jw013 Sep 10 '12 at 21:36
I get the impression the OP is looking for something like find ... -exec and not something as simple as ;. – jw013 Sep 10 '12 at 21:36

The symbols you are looking for are called control operators. You are using the wrong ones - you need ; or &&.

With ;, commands are executed in order, and it does not matter if the previous one ended with success or not.

With &&, every command that fails will prevent the next ones from executing.

You can read more for example here: http://www.humbug.in/docs/the-linux-training-book/ch08s01.html

share|improve this answer

In case you're using bash, may I suggest you read the man page of bash (man bash), and search for "control operator" (/control operator + [Enter]).

There, the different functions of things like | and ; are explained.

You might want to look into using && instead of ;, though. If you do that, you can perform the following functions in that sequence only if the previous one was successful. Meaning, if find cannot find your file, it wouldn't try to compress nothing:

find -name deleteme.tar && tar xvf deleteme.tar && rm -r delete/* || echo "something went wrong" 1>&2

Just a minor suggestion, though...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.