Results 1 to 6 of 6
Hi I'm learning to program in linux, and i can't seem to work out how to remove all the file with a directory without leaving the home directory.
Also how ...
- 11-11-2008 #1Just Joined!
- Join Date
- Nov 2008
- Posts
- 3
Removing all files in a dir, while in home dir - HELP!
Hi I'm learning to program in linux, and i can't seem to work out how to remove all the file with a directory without leaving the home directory.
Also how to copy on directory to another from the home directory.
Can any help please? Much appreciated.
Thanks.Last edited by patel_ankz; 11-11-2008 at 11:34 AM. Reason: mistake
- 11-11-2008 #2
Are you looking for the rm and cp commands? To remove a directory (and all its contents) from anywhere on the computer, just use:
To copy a directory from one place to somewhere else, you'd would probably want:Code:rm -rf /absolute/path/to/directory
These are system commands, but you were unclear about how you're programming in linux. Are you doing bash scripting? C? Perl? All of them could use different syntax, but you can almost always implement these system calls in any programming language if necessary.Code:cp -r /source/directory /new/directory
Registered Linux User: #479567
Asking a question? Read this page first.
Now... sudo make me a sandwich.
ratiocinativeroot.blogspot.com
- 11-11-2008 #3Just Joined!
- Join Date
- Nov 2008
- Posts
- 3
Yeah I'm doing C programming using csh, but I was just touching up on the basics. Erm the way you showed me, that removes the directory itself right? I want to delete everything within a directory from the home directory.
- 11-11-2008 #4removes all files and subdirectories underneath that folderCode:
rm -rf /path/to/directory/*
- 11-11-2008 #5
weird that it double posted, it told me i had to wait between posts after pressing post, then I waited and pressed post, now its a double post ^_^
- 11-11-2008 #6Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
I am not too sure what are you doing. csh is a shell, and it's not the C programming language. Sorry if that's obvious, just want to make sure we are talking about the same thing.
Your problem is that maybe you don't understand the different between a relative path and an absolute path. To remove anything no matter where you are, and that includes your home dir, you can always use an absolute path. An absolute path is a path starting with a slash /, the rest are all relative paths.
If you use an absolute path your current location is completely irrelevant.
Then you also need to learn the difference between files and dirs. By default, rm only delete files, so, if you want to remove all the files in /a/given/dir, you need to do
You probably want to specify -f so you don't have to confirm every file.Code:rm /a/given/dir/*
rm can also delete dirs if you use -r, that would indeed delete the directory itself as you say. But by default rm can't delete directories.
In opposition to the absolute paths, there are relative ones. A relative path is specified relative to a given location. For example, if you are in /home/i92guboj, we could re-write /a/given/dir/ as "../../a/given/dir/".


Reply With Quote
