You are not logged in.

#1 2008-02-07 00:27:06

Xs1t0ry
Member
From: Canada
Registered: 2007-07-01
Posts: 181

How do I delete a directory?

Hi

I tried using

rm ./directory

to delete some directory and it won't let me! It says it can't delete directories. This sounds weird so I thought I would ask if this is true. The directory has 3 files in it and it is not critical. I am logged in as root

Advice?

Offline

#2 2008-02-07 00:28:18

synorgy
Member
From: $HOME
Registered: 2005-07-11
Posts: 272
Website

Re: How do I delete a directory?

delete it recursively with

rm -r ./directory

"Unix is basically a simple operating system, but you have to be a genius to understand the simplicity." (Dennis Ritchie)

Offline

#3 2008-02-07 00:30:29

Misfit138
Misfit Emeritus
From: USA
Registered: 2006-11-27
Posts: 4,189

Re: How do I delete a directory?

I could give you the answer...but try this first:

man rm

If you still can't figure it out, post back. wink

Offline

#4 2008-02-07 00:36:22

_adam_
Member
From: Dora, Alabama
Registered: 2006-05-18
Posts: 94

Re: How do I delete a directory?

see also ``rmdir"

Offline

#5 2008-02-07 00:57:48

Xs1t0ry
Member
From: Canada
Registered: 2007-07-01
Posts: 181

Re: How do I delete a directory?

Thanks for the replies. rmdir worked as long as I deleted all the files in the directory first. Is there a way to just force it to all be deleted? Maybe rmdir -f? lol

Also, can you string together files to be deleted?

ie. rm /a /b /c
would delete files a, b and c?

Offline

#6 2008-02-07 01:10:33

loserMcloser
Member
From: Canada
Registered: 2004-12-15
Posts: 130

Re: How do I delete a directory?

rm -rf directory

Offline

#7 2008-02-07 01:11:57

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: How do I delete a directory?

Xs1t0ry wrote:

Thanks for the replies. rmdir worked as long as I deleted all the files in the directory first. Is there a way to just force it to all be deleted? Maybe rmdir -f? lol

The best thing to do is to either use "man [command]" or "[command] --help" to learn about syntax and available options and switches.  Having said that, I never use rmdir, but "rm -r" deletes the directory and everything inside it.

Xs1t0ry wrote:

Also, can you string together files to be deleted?

ie. rm /a /b /c
would delete files a, b and c?

Yes.

Offline

#8 2008-02-07 01:13:41

loserMcloser
Member
From: Canada
Registered: 2004-12-15
Posts: 130

Re: How do I delete a directory?

Xs1t0ry wrote:

ie. rm /a /b /c
would delete files a, b and c?

Yup, try it and see! big_smile

If you're afraid of experimenting with rm, use "rm -i" and it will ask you "are you sure" for each file it thinks you asked it to delete.

Offline

#9 2008-02-07 01:41:10

_adam_
Member
From: Dora, Alabama
Registered: 2006-05-18
Posts: 94

Re: How do I delete a directory?

a good thing to do is also put

alias rm='rm -i'

in your ~/.bashrc

It might be a pain in the ass after a while, but one day it might just save your ass big_smile

Offline

#10 2008-02-07 02:47:17

Xs1t0ry
Member
From: Canada
Registered: 2007-07-01
Posts: 181

Re: How do I delete a directory?

Thanks, I will!

Offline

#11 2008-02-07 18:17:10

alex_anthony
Member
From: UK
Registered: 2007-09-25
Posts: 344

Re: How do I delete a directory?

and if you want to delete multiple files, remember wildcards
e.g.
rm /some/directory/*
or
rm /picture/directory/PIC????

Offline

#12 2008-02-08 01:08:45

schivmeister
Developer/TU
From: Singapore
Registered: 2007-05-17
Posts: 971
Website

Re: How do I delete a directory?

rm --help

tells you

-r, -R, --recursive   remove directories and their contents recursively

but of course, it's not necessarily understandable by everyone what "recursive" means. It may well be a scary thing. But then you must not have been using Linux for long, in which case I wish you luck and joy in using Arch.

Jokes aside, add the -r option to any alias for rm. Or for a fun way of life

# nano /usr/bin/delete

then paste in

#!/bin/bash
# /usr/bin/delete: Simple AND stupid trasher

date=$(date +%d-%m-%y)

if [ ! -d ${HOME}/.trash/$date ]; then
  mkdir -p ${HOME}/.trash/$date
fi

for i in $@; do
  mv $i ${HOME}/.trash/$date
done
}

and then

# chmod 755 /usr/bin/delete

and you may

delete file directory whatever whenever

and the files will be in ~/.trash waiting for you to

for i in `ls -a1 --color=never ${HOME}/.trash`; do rm -rIv $i; done

one fine day smile Except if both a file and directory have the same names it will not work. And so, it's stupid. But i loike.

Last edited by schivmeister (2008-02-08 01:19:54)


I need real, proper pen and paper for this.

Offline

#13 2008-02-08 03:32:26

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: How do I delete a directory?

_adam_ wrote:

a good thing to do is also put

alias rm='rm -i'

in your ~/.bashrc

It might be a pain in the ass after a while, but one day it might just save your ass big_smile

this is a really bad idea.  sure, it will save your ass on your system, but what if you are ssh'd into a system and for whatever reason that alias isn't set. you will be expecting it and screw yourself over.


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#14 2008-02-08 05:11:22

codemac
Member
From: Cliche Tech Place
Registered: 2005-05-13
Posts: 794
Website

Re: How do I delete a directory?

Just a heads up here.

If you didn't know how to delete a directory... there is a small chance that ArchLinux is not the right distro for you to learn linux on.  You could really hurt data/etc.  I don't want to stop you from using it if you really want to, I'm just sayin' it so I can say toldyaso later.

Offline

#15 2008-02-09 00:37:42

pyther
Member
Registered: 2008-01-21
Posts: 1,395
Website

Re: How do I delete a directory?

^^
You got to learn some how, but if you have important information make sure you backup and being willing to accept your possible mistakes.


Website - Blog - arch-home
Arch User since March 2005

Offline

Board footer

Powered by FluxBB