-2

I need to write a bash script that will go through all the files in the directory listed as the first argument. It will print out the name and file size of any file that is less than 100 bytes long and more than 1000 bytes long. this is what i have so far:

#!/bin/bash
# 
#

find /home/clf18ftf  -type f -size -100c -size +1000c
  • 2
    Yes, several of us can write a script to look in a specified directory and show the file name with extension and the file size, for all files which are a) <100 bytes in size, plus b) > 1,000 bytes in size. May I ask you to click on edit and show us what you've written so far? There's an expectation, as per the rules here unix.stackexchange.com/help/how-to-ask, you will have done some research and tried to answer the question yourself. – K7AAY Dec 4 '18 at 22:08
  • 3
    Sounds like you want us to do your homework for you. – Tommiie Dec 4 '18 at 22:15
  • 2
    Are you trying to write a meta bash script, or is that an error in the question? (“I need to write a bash script that will write a bash script”) – ctrl-alt-delor Dec 4 '18 at 22:18
  • 1
    @ctrl-alt-delor I've rolled back your edit: we can't be sure if the OP swapped the less-than/greater-than relation, or was inaccurate in using "and" (rather than "or"). Let's wait for actual clarification. (I was going to nitpick about "and"/"or" earlier, but decided against it…) – n.st Dec 4 '18 at 22:30
  • 1
    @TheRealFawcett You're still asking for files that are "less than 100 bytes long and more than 1000 bytes long" at the same time. Such a file cannot exist. Did you mean to search for all files that are either < 100 B or > 1000 B? – n.st Dec 4 '18 at 23:37
1

I think find is your friend here. No need to write a script, just a one liner.

You will need find «directory to search» -type f -size -100c -size +1000c

read the find manual man find, and test what I have given you, there is an error in it.

  • ss64.com/bash/find.html is also very useful – K7AAY Dec 4 '18 at 22:33
  • i tried this however it does . not work? – The Real Fawcett Dec 4 '18 at 23:20
  • Yes I said there is an error in it. (though not according to the question, it finds all files that are smaller than 100 bytes and are also larger than 1000 bytes). – ctrl-alt-delor Dec 5 '18 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.