

:max_bytes(150000):strip_icc()/ScreenShot2019-08-30at9.33.33PM-dbc10ff0d4c145bab025e64a0f68d08d.png)
See GNU/bash man page for the shopt command online here: In other words, turn on this option to delete hidden files: # Bash shell and may not work on other shells If the dotglob option set, bash includes filenames beginning with a ‘.’ in the results of pathname expansion. $ rm -rfv /path/to/dir1/ Bash remove all files from a directory including hidden files using the dotglob option In this example, delete all files including hidden files, run: To remove all files except hidden files in a directory use: To see hidden files pass the -a to the ls command: In Linux, any file or directory that starts with a dot character called a dot file. In other words, ignore nonexistent files and arguments, never prompt. -r : Remove directories and their contents recursively.Understanding rm command option that deleted all files in a directory To delete all files folders from a directory, run: You can see what is being done when deleting all files in directory pass the -v option to the rm command:Īs you can see rm command failed to remove subdirectories /home/vivek/data/images and /home/vivek/data/scripts. To delete all files in a directory named /home/vivek/data/, run: Suppose you have a directory called /home/vivek/data/. How to remove all the files in a directory? Always keep verified backup to avoid accidental data loss that these commands might cause.

WARNING! Be careful with the rm and unlink commands.
