how to delete Files and Directories in linux

11:08 AM
Deleting Files and Directories


You have files and directories all over the place. How do you get rid of the ones you don't want?


Use rm (remove)—with caution! rm will happily delete everything, with no warning.


To delete a single file, with verbose output, use:


$ rm -v games-stats.txt




removed 'game-stats.txt'




To prompt for confirmation first, use:


$ rm -vi dpkglist


rm: remove regular file `dpkglist'? y


removed `dpkglist'




Use the -r (recursive) flag to delete a directory, with all files and subdirectories:


$ rm -rvi /home/games/stats/baseball




That deletes the /baseball directory, and everything in it. To delete /games and everything in it, use:


$ rm -rvi /home/games




You can use shell wildcards to delete groups of files, as in:


$ rm -v *.txt


removed `file4.txt'


removed `file5.txt'


removed `file6.txt'


removed `file7.txt'




Or:


$ rm -v file*

0 Comments