LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-03-2007, 02:09 PM   #1
lamak_98
LQ Newbie
 
Registered: Oct 2007
Posts: 3

Rep: Reputation: 0
Smile Help Me>> Need help in writing Bash script


I need bash script to do following
1. take directories name as argument
2. go into that directory and recursively delete all files and directories inside this directory.

$ ls
30070610
30070611
30070612
$ rmdir --ignore-fail-on-non-empty 300706*
rmdir: `30070610': File exists
rmdir: `30070611': File exists
rmdir: `30070612': File exists

thanks a lot
 
Old 10-03-2007, 02:19 PM   #2
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: SlackWare > Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy .. bullseye bookworm
Posts: 1,832

Rep: Reputation: 108Reputation: 108
Hya,

I have an impression that this is your homework.

So, I will give you some clue.

Read man (or info) page of rm.

Happy Penguins!
 
Old 10-03-2007, 02:52 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
I can't duplicate your results. Are 300706* files or directories? Do they have any contents?

When posting homework questions, you'll get more help by stating what the class is, what books you are using, etc.
 
Old 10-03-2007, 03:13 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
And here's two basic Bash scripting guides you want to check out: http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html,
http://www.tldp.org/LDP/Bash-Beginne...tml/index.html.
 
Old 10-03-2007, 03:55 PM   #5
devn
Member
 
Registered: Mar 2007
Location: Bangladesh
Distribution: Suse, Solaris
Posts: 40

Rep: Reputation: 15
did you try out recursive deletion switch of rm?

Maybe
Code:
rm -R $YOUR_DIR_NAME
will help.
 
Old 10-03-2007, 04:26 PM   #6
lamak_98
LQ Newbie
 
Registered: Oct 2007
Posts: 3

Original Poster
Rep: Reputation: 0
thanks...devn
that worked.

hello kaz2100 & pixellany, I wasn't doing HW, rather doing a work that needed to delete bunch of logs.. btw am new to bash scripting.. so give some break.
thanks

Last edited by lamak_98; 10-03-2007 at 04:30 PM.
 
Old 10-04-2007, 10:44 AM   #7
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: SlackWare > Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy .. bullseye bookworm
Posts: 1,832

Rep: Reputation: 108Reputation: 108
Hya,

Apology. Next time, please explicitly express the reason of post, so that nobody will have an impression of homework.

By the way, (this is another reason I had that impression), in your post #1, what you wrote down in English does not agree what you wanted to try (ls and rmdir). Neither the answer by dven.

Code:
rm -r $1/*
or
Code:
cd $1
rm -r *
cd ..
will do in tcsh, bash..... Otherwise, the containing directory is also deleted.

Anyway, read documents also.

Happy Penguins!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing a bash script. lebabyg Linux - General 2 03-31-2007 11:39 AM
Bash (help writing script) lebabyg Linux - General 7 07-04-2006 05:22 PM
writing a bash script poiuytrewq Linux - Newbie 2 10-07-2004 10:26 PM
Help writing a pinging bash script dehuszar Linux - Software 3 06-18-2004 02:03 PM
writing bash script ankitgdit Programming 4 08-19-2003 06:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration