C1W2: Looking for Bash Script Tutorial

Hi,

When I was doing lab exercise C1W2, I saw a bash script code as below:

!find /tmp/data/ -size 0 -exec rm {} +
!find /tmp/data/ -type f ! -name "*.jpg" -exec rm {} +

I have two questions about it:

  1. Could you explain more details about rm {} + mean?
  2. I am looking for blogs or tutorials about Bash Script, could you give me some good materials from basic to advance about this?

Thanks in advance.

This is not a question about bash syntax per se: it is a question about the “-exec” action of the find command. You can find the linux manpage for find here. Here is a screen shot of the section of that manpage about “-exec” with the “+” syntax:

In terms of finding information about bash in general, have you tried googling “bash tutorial”?

1 Like

Hi @cuongvo
The purpose of that couple of statements is to remove (rm {}) the file with size 0 and to remove all files with an extension different from .jpg.

The syntax is a bit complicated because more commands have been concatened on just one line.
the following statement finds all the files with ‘0’ size

find /tmp/data/ -size 0

then the output of the first command is sent as input to the second one that will remove all the files listed by the first command

-exec rm {} +

The second command is a bit more complicated
the first statement finds all the files

find /tmp/data/ -type f

then all files not jpg are selected

! -name “*.jpg”

finally the not jpg files are removed

-exec rm {} +

An interesting tutotial is available at this link.
hope this can help
regards

2 Likes

Thanks so much @paulinpaloalto and @fabioantonini for a very clear answer.
I think that linux syntax is real cool and complicated. So I need to move on the tutorial to gain deeper understand about linux command line.

Once again, thanks for all your support.

2 Likes