Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Q1: Basename = the source name right?
Q2: Could you explain the ( meaning )compilation of "file" in these commands ?
for file in $JPG
zip -u -m /home/sok/Receive/$base.zip $file
Is file means the variable value of the source?
A1: "basename" command returns the name of file/directory after stripping the suffix/extension. So if I run basename command on a file named 1.jpg as "basename 1.jpg .jpg" then it'll return 1. Do man basename for details.
A2: in the script "file", "base", and "JPG" are variables which store respectively the name of the jpg file with extension, name of the jpg file w/o extension and list of jpg files. $ denotes a variable.
Code:
for file in $JPG; do
means it'll look for any file whose name matches with the list in $JPG
Code:
base=`basename $file .jpg`
means it'll extract the name stripping the extension and store it to base
Code:
zip -m /path-to-dest/$base.zip $file
means it'll create zip from the source file ($file) and store it in destination ($base.zip)
You are right, sir.
I changed my code. It's true no need to compress a JEPG image.
I have a question.
I repleced "file" with "image" as the following:
Code:
forfilein $collect;
with
Code:
for image in $collect;
But, when using file,it look as the following:
bold and coloured "file ". 1- why ?Is there different, using it instead of using any variable name?
Does it effect on the moving operation?
2- Why the size of the empty folder is 4.k (4096) not zero?
1. I am not sure I understand your first question. Are you worried about the fact that color of the word "file" is same as the word "image" when you open the script in your text editor? If that is the case, no need to worry. Most text editors have a syntax-based coloring scheme and from the extension and preamble of the file they try to determine the type of the file. Based on these, the text editor colors some words differently than others. This has nothing to do with the function. So replacing "file" with "image" or any other name will not change the way the script is supposed to work.
2. As far as I know, each directory, even when they are empty, requires to store some info, such as name, permission, timestamp, etc. It therefore needs some space to store these. The size of the empty directory is the size required to store these. This size varies with file system you are using, and probably 4kb is the smallest block in your file system. So it shows up as a directory of size 4k
1. I am not sure I understand your first question. Are you worried about the fact that color of the word "file" is same as the word "image" when you open the script in your text editor? If that is the case, no need to worry. Most text editors have a syntax-based coloring scheme and from the extension and preamble of the file they try to determine the type of the file. Based on these, the text editor colors some words differently than others. This has nothing to do with the function. So replacing "file" with "image" or any other name will not change the way the script is supposed to work.
I worried because "file"&"image" is not the same color.S I think the interpreter will different interact with "file"?! I thought
the colored thing as a defined data type.
Quote:
2. As far as I know, each directory, even when they are empty, requires to store some info, such as name, permission, timestamp, etc. It therefore needs some space to store these. The size of the empty directory is the size required to store these. This size varies with file system you are using, and probably 4kb is the smallest block in your file system. So it shows up as a directory of size 4k
HTH,
I like that analysis and now, I am well-convinced of it. I was thinking in it.And you provide me with extra details, thanks.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.