Is there a way to delete a directory in Terminal?

Asked by dds1958

I need to delete a file in the terminal (if possible). I need to know the command to do this and where I can find this type of information in the future (manual, docs?)

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu gnome-terminal Edit question
Assignee:
No assignee Edit question
Solved by:
Jim Hutchinson
Solved:
Last query:
Last reply:
Revision history for this message
Best Jim Hutchinson (jphutch) said :
#1

Do you mean delete a file using the terminal? The command is rm. Like this

rm file.txt

Of course you have to be in the right directory or give the full path. Change directories with

cd path

or just

rm /home/user/folder/file.txt

If it's not owned by you use sudo.

sudo rm /path/file.txt

Be VERY careful deleting system files and in general don't.

Revision history for this message
Jim Hutchinson (jphutch) said :
#2

Oh, and here is a nice list of commands.

http://www.oreillynet.com/linux/cmd/

And that book is nice if you want something in print.

Revision history for this message
dds1958 (dstockwell) said :
#3

Thanks. I knew about the "rm" command but was wary of using it for reasons that you mentioned and have been outlined in this forum ad infinitum (it's not a very large file -- maybe I'll just leave it alone for now. By the way, Ubuntu rocks!! This is so much better than Windows. I don't know why I hesitated to change.

Revision history for this message
Jim Hutchinson (jphutch) said :
#4

In general, if it's a file you created then it's okay to delete it if you don't need it any more. This would go for system files that you created to set something up as well. Such as creating a config file for some program. If you removed the program you could remove the config file. However, if it was a file the system created I would leave it alone. If you remove a program and it leaves files behind you might be safe to remove them but they could be a dependency for something else so best not to. I would say that Linux is better at managing its files than windows so while windows will leave a bunch of junk behind this is less so for Linux. I have never worried about it. You can use the autoremove option to get rid of stuff Ubuntu knows it doesn't need.

sudo apt-get autoremove

Otherwise I would advise not deleting anything outside your home directory. When I muck things up too bad from playing around too much I just do a clean install. It's all of 20 minutes and I keep /home on a separate partition so nothing is lost. My desktop comes back just as I left it. I only need to reinstall the apps that I had in addition to the default.

Revision history for this message
Thinboy00 (thinboy00) said :
#5

Putting /home on a separate partition is rewarding in that aspect, but a difficult and complex process. The easiest way to mod it from an already installed system is to run the partition manager from a LiveCD (you can't repartition a mounted device or partition, it simply does not work). But remember, Gparted (the partition manager) can malfunction (never happened to me, but don't trust it esp. for mission critical stuff). You might also consider putting /usr on another partition. Again, don't do this unless you understand what you will be doing and already understand:
1. what /home /usr and /etc/fstab are
2. The risks
3. the rewards
4. the time it will take (can be half an hour or more to copy one of /home or /usr )
5. how mounting, partitions, ... work