LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 10-26-2010, 01:49 AM   #1
Hariharan
Member
 
Registered: Nov 2004
Location: Bangalore
Posts: 64

Rep: Reputation: 0
script to delete the user define input


Hi All,

I ve a script to delete a folder is given below

file="/path/to/delete/folder/*"
for dir in $file
do
rm -rf $dir
done

1. I need a script to clear the cacheroot in my box.
2. What user mention to delete the folder that should ve to delete.

Thanks,
Hariharan
 
Old 10-26-2010, 03:21 AM   #2
ionrivera
Member
 
Registered: May 2010
Distribution: Debian, RHEL, AIX, Solaris, HP-UX
Posts: 61

Rep: Reputation: 4
I don't understand your post clearly but if you want to delete files and or folders supplied by user in an (argument):
e.g. ./yourscript "name_of_folder_you_want_to_delete"

Note that predefined variables to access passed arguments are ($1, $2, $3 and so on..)

Take a look at this code:
Code:
#!/bin/bash
file=/path/to/delete/folder/

find $file -name "$1"|xargs rm -R

Last edited by ionrivera; 10-26-2010 at 03:32 AM.
 
Old 10-26-2010, 04:39 AM   #3
Hariharan
Member
 
Registered: Nov 2004
Location: Bangalore
Posts: 64

Original Poster
Rep: Reputation: 0
Hi,
I need script for clear the folder in my linux box.
what i mean for eg: we wanna to delete a content in that folder,so we ve to mention the path for that folder
like that i need a script.
 
Old 10-26-2010, 06:56 AM   #4
ionrivera
Member
 
Registered: May 2010
Distribution: Debian, RHEL, AIX, Solaris, HP-UX
Posts: 61

Rep: Reputation: 4
If your saying that you want to delete the contents of the specified folder supplied:
e.g. ./yourscript "/folder/containing/files/u/want/to/delete"

Code:
#!/bin/bash
file=$(ls "$1")
for files in $file
do
rm -f $1/${files}
done

Last edited by ionrivera; 10-29-2010 at 02:25 AM.
 
Old 10-27-2010, 01:17 AM   #5
Hariharan
Member
 
Registered: Nov 2004
Location: Bangalore
Posts: 64

Original Poster
Rep: Reputation: 0
Hi,
Thank u......
can u explain that program line by line......Plz....
 
Old 10-29-2010, 02:05 AM   #6
ionrivera
Member
 
Registered: May 2010
Distribution: Debian, RHEL, AIX, Solaris, HP-UX
Posts: 61

Rep: Reputation: 4
This code will basically delete all files in a given folder specified by the user (./your_script /folder/containing/files/u/want/to/delete).
Heres the simple explanation of the script:

Code:
#!/bin/bash

file=$(ls "$1")
#          ^ $1 is your argument. (e.g. ./your_script /folder/containing/files/u/want/to/delete)
# $1=/folder/containing/files/u/want/to/delete
# So, calling the $file variable will display results for ls /folder/containing/files/u/want/to/delete

for files in $file
# this will loop results of ls /folder/containing/files/u/want/to/delete line by line while doing rm -f

do

rm -f $1/${files}
# rm -f /folder/containing/files/u/want/to/delete/sample.mp3

done

Last edited by ionrivera; 10-29-2010 at 02:28 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
I cannot figure out how to get user input into a script froster Linux - Newbie 2 11-05-2009 07:13 PM
Help with a delete user script nazs Linux - General 1 02-20-2006 05:14 PM
Shell script user input tuckermaddox Linux - Newbie 5 08-12-2004 03:14 AM
Masking user input in sh script? RMSe17 Linux - Software 3 07-20-2004 10:17 PM
User input using a BASH script... causticmtl Programming 5 07-13-2003 09:59 PM


All times are GMT -5. The time now is 07:24 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration