Bash script help required - move uncompress and rename
Linux - NewbieThis 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.
Done some searches but can't find a script that does this or nearly does this for me to "borrow".
My requirement is as follows. I want to search a directory recursively looking for new .rar/ .zip files. When a new file is found I want to extract the contents to another directory. To top things off would like to rename the source file as something like original.rar.extracted.
Many thanks if anyone could start me in the right direction!
All the best.
Trux
To add: using ubuntu netbook remix - jaunty.
Last edited by truxntrax; 09-19-2009 at 03:47 PM..
Reason: More details
For extracting the rar/zip must have to install rarlinux
and use unrar command in your shell script.
for details on unrar command
I hope this will help you
In additiont to the unrar platinumedge mentioned, you'll want unzip, of course. Also, you'll want the find command for recursive directory search with time constraints. You'll need mv for the rename. As far as the '.extracted' thing, I'm not sure why that'd be necessary, but unzip's -d flag may be what you want, but I'm not very familiar with rar. The man pages for these tools and your shell should have all the details you need.
Hi thanks for reply's. I understand which tools I need and how to do this without a script but how do I write this into a bash script which runs recursively?
The renaming is to ensure when the script checks the directory n minutes later the same file will not be unrared/ unzipped again. I will also be able to see which files the script has successfully run against.
Hi thanks for reply's. I understand which tools I need and how to do this without a script but how do I write this into a bash script which runs recursively?
The renaming is to ensure when the script checks the directory n minutes later the same file will not be unrared/ unzipped again. I will also be able to see which files the script has successfully run against.
Thanks again!
Trux
I suggest you take a look at the man pages for find, and check out Google for any one of the many bash scripting tutorials.
But if you already know how to do it from the command line, you already know how to write the script. Essentially, a script file is the same thing as a Windows batch file...just a bunch of commands, in a text file.
This:
Code:
#!/bin/bash
<your command one>
...
...
...
<end of your commands>
is a script. Obviously, put your commands in it... The #!/bin/bash executes a new child shell, which is handy to make sure your environment variables and such get passed. You can create this in any editor (vi, emacs, gedit, etc.), and save it as plain text. After, do a "chmod 755" on that file name (read manpage for the chmod command), to make it an executable program. After that, run it with "./<filename>".
I wouldn't run my scripts as './script' unless for a throwaway. I'd recommend creating a personal scripts directory and putting it on your path so you can execute your frequently used scripts like any other command.
He may not need a loop at all - find's '-exec' flag could do.
And, truxntrax, you can specify to find that it only find files of a certain age, so it won't unpack anything older, so you shouldn't need the renaming to protect against multiple unpacks. As far as seeing what was done, you could just put some logging in your script. I dunno - it's up to you and people almost never completely specify what they're trying to accomplish, so whatever works for you.
You are correct I can do this all in command line it's just stringing things together into a script. I do not understand the syntax.
Got enough to play with from your suggestions.
Being an IT programme manager I should know better I did ask how to achieve a solution rather than telling you my requirements. Anyway I've got enough to get me started.
Also, I'd have an archive dir and mv the orig zip file to that after processing. Always keep the input dir clear.
You might want to embed the date/time of processing into the archived filename.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.