unix command pipe


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users unix command pipe
# 1  
Old 01-07-2009
unix command pipe

I am pretty new to UNIX. My client has a requirement where in a directory we have some files with somewhat similar name
like test_XX.txt, test_XY.txt, test_XZ.txt, test_ZZ.txt, test_ZY.txt, test_ZX.txt, test_YY.txt......Out of these files
few files have 0 bytes. Is there a way where we can go ahead and remove those files which start with "test"[as that is the only common string in the file name] and have 0 bytes size. I tried the following commands:
find . -type f -size 0 | xargs rm [It removed all the files irrespective of name with 0 byte size]
Is there a solution for this?
# 2  
Old 01-07-2009
Try:
Code:
find ./test* -type f -size 0 -exec ls -l {} \;

if that lists only the files you want then:
Code:
find ./test* -type f -size 0 -exec rm {} \;


Last edited by Ikon; 01-07-2009 at 05:17 PM.. Reason: changes exec to -exec
# 3  
Old 01-07-2009
getting this error:find: 0652-009 There is a missing conjunction
# 4  
Old 01-07-2009
Oppsss try again.. Left out a -

Try:
Code:
find ./test* -type f -size 0 -exec ls -l {} \;

if that lists only the files you want then:
Code:
find ./test* -type f -size 0 -exec rm {} \;

# 5  
Old 01-07-2009
Ikon ,

Its awesome it worked.

I hv a question for my learning as I have mentioned I am pretty new since i only need to use unix when its really meant.


find ./test* -type f -size 0 -exec rm {} \;

I just dont know the underlined part .......I know the use of * as it is used to get the filename or any name starting with test........but the forward slash / i dont know.
# 6  
Old 01-07-2009
Sorry Ikon,

Thank you so much.
# 7  
Old 01-07-2009
You dont have to have the ./

I just use it for "Current Directory"...

Code:
find /path/to/some/files/test* -type f -size 0 -exec rm {} \;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pipe command to script

Hello to all, Having a ruby script that works when an argument is given in command line in this way: ruby script.rb input_to_ruby To accept arguments as input, inside the ruby script has File.open(ARGV) input_to_ruby is generated by another command, so I need to create first input_to_ruby... (6 Replies)
Discussion started by: Ophiuchus
6 Replies

2. Shell Programming and Scripting

pipe in command

Hello, I try to concatenate a command to execute. Sadly it throws an error. #!/bin/bash cd / cmd="find -name *.txt | awk '{ printf "FILE: "$1; system("less "$1);}' | egrep 'FILE:|$1'" echo "1." $($cmd) echo "2." $("$cmd") echo "3." `$cmd` echo "4." `"$cmd"`1.&3. 'find: paths must... (2 Replies)
Discussion started by: daWonderer
2 Replies

3. Shell Programming and Scripting

Homework: Make a one-line Unix command - using pipe(s)

Task A: Make a one-line Unix command - using pipe(s) - to display the number of files in your home directory including the hidden files that begin with '.' Task B:Make a one-line Unix command - using pipe(s) - to display the number of unique zip codes in famous.dat (hint: use -u on sort) Task... (1 Reply)
Discussion started by: wises
1 Replies

4. Shell Programming and Scripting

pipe grep command

Hi all, Can someone help me with the following problem. I am executing the following command: (search for occurences of 'error' in files that match cl-*.log expression) > grep -cw -i --max-count=1 'error' cl-*.log this command outputs: cl-apache.log:1 cl-apache_error.log:1... (3 Replies)
Discussion started by: epro66
3 Replies

5. UNIX for Dummies Questions & Answers

Pipe in command string

Hi, Can't you have a pipe in a command string ? If I try the following I get errors. Why ? > cmd="ls -lrt | grep xyz" > $cmd |: No such file or directory grep: No such file or directory xyx: No such file or directory Thanks in advance Hench (3 Replies)
Discussion started by: hench
3 Replies

6. UNIX for Dummies Questions & Answers

How can I use pipe command ?

Hi My friends I have used this command to find files are modified within the past 24 hours and then many files are shown but I want transfer all these files to special directory by using pipe . can any one tell me what is the next step ? (11 Replies)
Discussion started by: bintaleb
11 Replies

7. Programming

unix pipe in C

I currently stuck on a simple program that requires unix pipe. I'm have never programmed with unix pipe before, so if anyone can point me to the right different will be greatly appreciated! I'm suppose to write a program that the parent spawns many child processes and each of the child process... (1 Reply)
Discussion started by: meh
1 Replies

8. UNIX for Dummies Questions & Answers

UNIX Pipe

Hi , I want to understand how the PIPE works in unix . Precisely what I am doing is this . 1. Creating a Named PIPE with the command mknod sqlldr.dat p 2. Directing a file output to the PIPE file in the background cat abc > sqlldr.dat 3.SQL Loader in oracle is... (5 Replies)
Discussion started by: akrathi
5 Replies

9. UNIX for Dummies Questions & Answers

pipe command

current dir : /home/sales ls -l abc.txt 17th aug bcd .txt 16t oct ------- ------ Total files : 100 if i want to move only those files dated 17 aug into another sub directory /home/sales/texas how do i pipe the result of 'ls' command to a 'mv' command (1 Reply)
Discussion started by: zomboo
1 Replies

10. UNIX for Advanced & Expert Users

How to pipe command

Hi All, I want to create a command that executes a text editor with the most recent file in the current current directory. So a good start to achieve this is : ls -lrt | cut -c55- | tail -1 which provides the name of the most recent file in a directory The problem is to pipe the... (4 Replies)
Discussion started by: anonymous.nico
4 Replies
Login or Register to Ask a Question