~/Desktop$ ls

file 01 file 02 file 03

file 04 file 05 file 06

file 07 file 08 file 09

file 10 file 101 file 102

well the list goes on like that till file 109 after which it shows file 10 then file 110 till file 119 then file 11 after which comes file 120 till file 129 then file 13 and so on.

how to delete the first fifty files (file 01 till file 50) and the total number of files is 138.

How to do it for the fish shell also ?
In the answer provided it can be done for a bash shell.

  • ehm 01 till 50 does not equal "first fifty files if they are listed like what you said in the 1st part. 01 ... 50 would be 50 files when each is 2 digits but having 101, 102,...,129 in there it would be more than 50. – Rinzwind Sep 28 '16 at 18:57
  • @Rinzwind Heh, good point. I Will keep my answer for now until OP clarifies further. – edwinksl Sep 28 '16 at 19:01

You can delete them by running:

rm file\ {01..50}

The \ is there to escape the space that you have in the filename while {01..50} defines a range of integers from 01 to 50.

I recommend changing rm to ls first to confirm the correct files are listed before actually using rm to delete them!

  • is there any method to use the above answer in fish shell ? It works properly in a bash shell but not inside a fish shell. – devilz Mar 27 '17 at 12:02

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.