UNIX / Linux: Delete All Files Using rm Command

by on January 5, 2010 · 1 comment· LAST UPDATED July 5, 2011

in

How do I delete all files in UNIX or Linux stored in /home/you/letters/ directory?

In order to remove a file, you need to use the ls command to list the contents of the directory and find the filename you want to remove. For example, if yoy have a file or files in the /home/you/letters/ directory that you want to delete from the system. Type the following command to change the directory:
$ cd /home/you/letters
List the contents of the directory, run:
$ ls
OR
$ ls -l
OR
$ ls -l | less
To delete all files, enter:
$ rm *
OR
$ /bin/rm *
To remove a directory, use the rmdir command, run:
$ cd /home/you
$ rmdir letters

To remove a directory called /tmp/foo/ and all its files including subdirectories, use the rm command as follows:
$ rm -rf /tmp/foo/

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 1 comment… read it below or add one }

1 mohit September 30, 2011 at 6:58 am

can in any case rm -f 1.txt
will remove all teh files in directory

Reply

Leave a Comment

Tagged as: , , , , , , ,

Previous Faq:

Next Faq: