LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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

Reply
 
Search this Thread
Old 12-14-2012, 02:12 AM   #1
pradeepdee6
Member
 
Registered: Jul 2012
Posts: 30

Rep: Reputation: Disabled
How to delete a directory in /tmp directory


Hi Everyone,

Im creating a directory in /tmp location for temporary storage of files. then i move them to actual folder.

Im not able to delete the directory.
Server Version: AIX dseax203 3 5 00CF1AEC4C00
shell : Bash

Quote:
Code:

#!/usr/bin/ksh
FILEDIR="/opt/proj/rem_fil"

mkdir /tmp/get.$$.Temp
cd /tmp/get.$$.Temp

ftp -n -vi > FTP_LOG.txt
open dseax203
user User Pass
cd mft_test
get abc*
close
quit

chmod 777 abc*
mv /tmp/get.$$.Temp/* $FILEDIR
rm -f /tmp/get.$$.Temp
Please help me how can i delete the directory in /tmp directory.


Thanks in Advance.
 
Old 12-14-2012, 02:42 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
You missed the -r (recursion) option of rm, necessary to remove directories. If the directory is empty the rmdir command is enough, otherwise rm -r is mandatory.
 
Old 12-14-2012, 03:11 AM   #3
pradeepdee6
Member
 
Registered: Jul 2012
Posts: 30

Original Poster
Rep: Reputation: Disabled
Hi colucix,

Thankyou very much for the reply.

I tried with rm -r, rm -rf. But the result was same, im not able to delete the directory.
Since im moving all the files and the directory will be empty, even then rmdir is not able to deleted teh directory.

when i manually use th ecommand in comand prompt, the directory gets deleted.
But when the same command included in shell script, it ll not be able to delete.

Thanks in Advance
 
Old 12-14-2012, 03:17 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Any error message from the script? What if you change #!/usr/bin/ksh with #!/usr/bin/bash or the exact path to the bash shell, if different?
 
Old 12-14-2012, 03:32 AM   #5
pradeepdee6
Member
 
Registered: Jul 2012
Posts: 30

Original Poster
Rep: Reputation: Disabled
Hi colucix,
This is the error message.
Quote:
rm: 0653-610 Cannot remove current directory /tmp/get.15097918.Temp.
#!/usr/bin/bash made no difference.

does /tmp has any special permissions that doesnot allow deleting a directory in it ??
 
Old 12-14-2012, 03:37 AM   #6
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
I didn't notice it before, but most likely you have to go out of the directory before removing it.
 
1 members found this post helpful.
Old 12-14-2012, 03:40 AM   #7
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,592
Blog Entries: 2

Rep: Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047
You can't delete the directory when it is your current working directory. Insert a
Code:
cd -
before the rm command to change the current working directory back to the previous state before removing that directory.
 
1 members found this post helpful.
Old 12-14-2012, 03:41 AM   #8
pradeepdee6
Member
 
Registered: Jul 2012
Posts: 30

Original Poster
Rep: Reputation: Disabled
Thanks you so much Hi colucix.

Quote:
but most likely you have to go out of the directory before removing it.
This was the main reason for my error.

Thanks
 
  


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
Can't login, says tmp directory full but tmp file is empty! Could be linked to MySQL? bethanlowder Fedora 7 09-25-2009 07:17 AM
/TMP Directory carlosinfl Linux - General 4 01-23-2007 01:02 PM
shell script: delete all directories named directory.# except directory.N brian0918 Programming 3 07-13-2005 06:54 PM
2 gigabyte /tmp directory..ok to delete contents pAn1k Linux - Newbie 3 09-02-2004 09:56 AM
Can I delete everything in the /tmp directory? BajaNick Linux - General 5 07-04-2004 01:35 PM


All times are GMT -5. The time now is 03:03 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