text: user16067: I have a directory of FASTA files, some of which are empty (placeholders that were output from a pipeline) and I would like to delete the empty files using a for loop on the command line.
  From what I have seen so far I can use the wc -l [file] approach to see "if there are lines present, delete the file" but I want to make sure the syntax is right before deleting important files. I was thinking it might be easier for the command to look for the " > " symbol found at the header in FASTA files and if it's not present delete the file.
  Here is what I have so far:
  for file in *.fasta; do "if wc -l < 1 rm file"; done
  
  Or
  for file in *.fasta; do "grep > | rm file"; done
  
  
  user3848: @Ram RS has identified the solution here via find, if that does not work then the following will work,
  find . -maxdepth 1 -type f -empty | xargs rm 
  
  
  Edit 2
  The solution is obvious ...
  find . -type l -delete
  
  The code under Edit is is better if the OP knows in advance precisely how many links the symbolic link file has, basically its always one. However, we don't know, thus -type l will delete every symbolic link.
  
  To address @Steve's point of inadvertent deletion in case of a null return ... The code was checked prior release and this didn't occur (and also now rechecked).
  
  user10775: As already stated, one way is to use the GNU find (the default on Linux) command. This will find and print all empty files in the current directory:
  find . -maxdepth 1 -type f -empty -print
  
  Append the -delete action to the command above when you're ready to remove them. If you need to find (and then delete) empty files recursively, simply remove the -maxdepth 1 option.
  
  
  In a comment, you mention that these are actually "alias" files which are the results of a Nextflow pipeline. Unless the default publishDir mode has been changed, Nextflow will publish output files to the publishDir using symbolic links to the files in the working directory (i.e. ./work). I suspect what you are trying to do is to find and remove the links to these empty files, but not the files themselves. In this case, I think what you want is:
  find . -type l -exec test ! -s '{}' \; -print
  
  Again, append the -delete action to the command above to actually remove the symlinks. If you instead need to delete files from Nextflow's working directory, use nextflow clean in conjunction with nextflow log to safely clean up the failed runs.
  
  user298: This isn't the most efficient approach, using find will be easier and faster as long as your find supports the -empty option, but since this is what you asked for, here is how to do it based on the number of lines:
  for file in *.fasta; do 
   [[ $(wc -l < "$file") -eq 0 ]] && echo rm -- "$file"
  done
  
  If you want to recursively descend into subdirectories, use:
  shopt -s globstar
  for file in  *.fasta */**.fasta; do.
    [[ $(wc -l < "$file") -eq 0 ]] && echo rm -- "$file"
  done
  
  If that prints the right files, remove the echo to actually delete them.
  Note that this will also delete files that are not empty but don't have a newline character. These are not valid "text files", but strictly speaking they aren't empty, they just have no lines as lines are defined by the \n character. For example, this file would be deleted:
  printf 'aaa' > file
  
  
  user650: Always Google before asking on forums. I googled "delete empty files linux" and this was the second result: https://www.baeldung.com/linux/delete-empty-files-dirs
  # Print and delete empty files just in the current directory
  $ find . -maxdepth 1 -type f -empty -print -delete
  # Print and delete empty files in the current directory and all sub-directories
  $ find . -type f -empty -print -delete
  
  
original_text: 16067: <p>I have a directory of FASTA files, some of which are empty (placeholders that were output from a pipeline) and I would like to delete the empty files using a for loop on the command line.</p>
  <p>From what I have seen so far I can use the <code>wc -l [file]</code> approach to see &quot;if there are lines present, delete the file&quot; but I want to make sure the syntax is right before deleting important files. I was thinking it might be easier for the command to look for the &quot; &gt; &quot; symbol found at the header in FASTA files and if it's not present delete the file.</p>
  <p>Here is what I have so far:</p>
  <pre><code>for file in *.fasta; do &quot;if wc -l &lt; 1 rm file&quot;; done
  </code></pre>
  <p>Or</p>
  <pre><code>for file in *.fasta; do &quot;grep &gt; | rm file&quot;; done
  </code></pre>
   3848: <p>@Ram RS has identified the solution here via <code>find</code>, if that does not work then the following will work,</p>
  <pre><code>find . -maxdepth 1 -type f -empty | xargs rm 
  </code></pre>
  <hr />
  <p><strong>Edit 2</strong></p>
  <p>The solution is obvious ...</p>
  <pre><code>find . -type l -delete
  </code></pre>
  <p>The code under <strong>Edit</strong> is is better if the OP knows in advance <em>precisely</em> how many links the symbolic link file has, basically its always one. However, we don't know, thus <code>-type l</code> will delete every symbolic link.</p>
  <hr />
  <p>To address @Steve's point of inadvertent deletion in case of a null return ... The code was checked prior release and this didn't occur (and also now rechecked).</p>
   10775: <p>As already stated, one way is to use the GNU <code>find</code> (the default on Linux) command. This will find and print all empty files in the current directory:</p>
  <pre><code>find . -maxdepth 1 -type f -empty -print
  </code></pre>
  <p>Append the <code>-delete</code> action to the command above when you're ready to remove them. If you need to find (and then delete) empty files recursively, simply remove the <code>-maxdepth 1</code> option.</p>
  <hr />
  <hr />
  <p>In a comment, you mention that these are actually &quot;alias&quot; files which are the results of a <a href="https://www.nextflow.io/" rel="nofollow noreferrer">Nextflow</a> pipeline. Unless the default <a href="https://www.nextflow.io/docs/latest/process.html#publishdir" rel="nofollow noreferrer">publishDir</a> mode has been changed, Nextflow will publish output files to the publishDir using symbolic links to the files in the working directory (i.e. <code>./work</code>). I suspect what you are trying to do is to find and remove the links to these empty files, but not the files themselves. In this case, I think what you want is:</p>
  <pre><code>find . -type l -exec test ! -s '{}' \; -print
  </code></pre>
  <p>Again, append the <code>-delete</code> action to the command above to actually remove the symlinks. If you instead need to delete files from Nextflow's working directory, use <code>nextflow clean</code> in conjunction with <code>nextflow log</code> to safely clean up the failed runs.</p>
   298: <p>This isn't the most efficient approach, using <code>find</code> will be easier and faster as long as your <code>find</code> supports the <code>-empty</code> option, but since this is what you asked for, here is how to do it based on the number of lines:</p>
  <pre class="lang-sh prettyprint-override"><code>for file in *.fasta; do 
   [[ $(wc -l &lt; &quot;$file&quot;) -eq 0 ]] &amp;&amp; echo rm -- &quot;$file&quot;
  done
  </code></pre>
  <p>If you want to recursively descend into subdirectories, use:</p>
  <pre class="lang-sh prettyprint-override"><code>shopt -s globstar
  for file in  *.fasta */**.fasta; do.
    [[ $(wc -l &lt; &quot;$file&quot;) -eq 0 ]] &amp;&amp; echo rm -- &quot;$file&quot;
  done
  </code></pre>
  <p>If that prints the right files, remove the <code>echo</code> to actually delete them.</p>
  <p>Note that this will also delete files that are not empty but don't have a newline character. These are not valid &quot;text files&quot;, but strictly speaking they aren't empty, they just have no <em>lines</em> as lines are defined by the <code>\n</code> character. For example, this file would be deleted:</p>
  <pre><code>printf 'aaa' &gt; file
  </code></pre>
   650: <p>Always Google before asking on forums. I googled &quot;delete empty files linux&quot; and this was the second result: <a href="https://www.baeldung.com/linux/delete-empty-files-dirs" rel="nofollow noreferrer">https://www.baeldung.com/linux/delete-empty-files-dirs</a></p>
  <pre><code># Print and delete empty files just in the current directory
  $ find . -maxdepth 1 -type f -empty -print -delete
  # Print and delete empty files in the current directory and all sub-directories
  $ find . -type f -empty -print -delete
  </code></pre>
  