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!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I'm downloading many files to my server. most of them have *.avi extension. I have unsuccessfully tried to write a script which will list all the avi files to a document and then zip all the avi files and then remove the original avi file. This is what I'm doing manually,
zip -r filename.zip filename.avi
Which shell commands should I look to accomplish my goal. I have no experience with shell scripting before. If it is a small code, please post it as well as some good scripting tutorials are also welcomed.
FILES=`ls -1 *.avi`
for x in $FILES
After creating the script file you have to make it executable by doing a 'chmod +x scriptname', and then run it like ./scriptname. You could add in a parameter to accept a directory to work on with $1:
FILES=`ls -1 $1/*.avi`
Then run it like this:
Note that it's late for me, so I take no responsibility for any stupid mistakes I may have made here.
Originally posted by quickk I'm a little bit confused, what is "FS". I did a search and found that it means filesystem on linux but I don't know how to use that command. Can you please give an example?
I think he meant 'IFS', which is how you define the Input File Separator. Defining IFS to be a blank line as in the example above forces the script to treat the each entire line output by the 'ls -1' command as a single filename. If you didn't do that then a filename with spaces in it would generate an error message because the default IFS is a space, and the shell would think each word in the filename was a separate file.
Originally posted by quickk I did this and it works. But the problem is that it saves with "filename.mp3.zip" extension. Is there any way of removing .mp3 extension from filenames.
You could incorporate the 'basename' command into the script and issue a rename (mv) to change the filename after it's been compressed, but if you remove the file extension then you'll have no way of knowing what the file should be when you uncompress it.
Unlike the Mac OS, linux still uses the file extension to determine what a file is and what application it should try to use to open it.
You have filename.mp3 and you compress it to filename.zip. Later on you uncompress it to filename, but when you try to play it in xmms it doesn't recognize it because it doesn't know it's an mp3 file.
BTW, on another note - you should try zip, compress, and gzip on your files to see which gives you the best compression and then put the one you want into the script.