To delete (remove) a file, use the rm command. As an example, we are going to create a copy of the science.txt file then delete it.
Inside your unixstuff directory, type
You can use the rmdir command to remove a directory (make sure it is empty first). Try to remove the backups directory. You will not be able to since UNIX will not let you remove a non-empty directory.
rmdir mydir
rm -r directory
And for extra measures (since files rm'd cannot be recovered easily if at all),
rm -rfv /path/to/dir
The -f forces the deletion (if you're allowed to delete the files) and the -v shows verbose information (tells you what is being deleted).
If you're sudo'd and you're using rm, be sure to check what you're deleting and make sure the path is correct.
Inside your unixstuff directory, type
% cp science.txt tempfile.txt
% ls
% rm tempfile.txt
% ls
% ls
% rm tempfile.txt
% ls
rmdir mydir
Removes the directory mydir
Remove a directory, even if files existed in that directory.
And for extra measures (since files rm'd cannot be recovered easily if at all),
rm -rfv /path/to/dir
The -f forces the deletion (if you're allowed to delete the files) and the -v shows verbose information (tells you what is being deleted).
If you're sudo'd and you're using rm, be sure to check what you're deleting and make sure the path is correct.
No comments:
Post a Comment