Bash command to delete entire Files from folder
Hi friends, I want to completely remove the entire files from the specific folder without deleting the folder. I want to remove it via the bash command. What can be the good bash command to delete the files from the folders? I tried what I knew but it encountered me the error message even though I am executing the command in the specific folder. Any trick to delete all the files from the folder without deleting the folder. Please help what can I do?
Re: Bash command to delete entire Files from folder
Hello friend, I am not the continuous user of UNIX operating system. But I had something idea related to it. You can remove the entire files without deleting the specific folder by the following Bash command: find . -type f -name "*{}*" -exec rm -fr {} \;
You can also test it with the help of IS command, it can be less risky to you: find . -type f -name "*{}*" -exec ls {} \;
The command which I had specified is not yet tested. Because I don’t have the UNIX systems to test this bash commands. Test it let me know what happens?
Re: Bash command to delete entire Files from folder
Suppose I have being using the 30 other folders, where I have to normally type the folders pathname each and every time. Can I modify the command to remove the entire files which is present in the specific folders? The folder is in the following folder:
A-ABC-20101512-0001
A-ABC-20100322-0002
A-ABC-20100482-0003
………….
Note that the numbers are in the format DDMMYY-NN. I can write the command in the following format: find A-ABC-DDMMYY-NN/folder/subfolder -type f –delete. The given command can be adjusted to the files which you want to remove for each other 30 folders in single command. Without operating it for the other different folder.
Re: Bash command to delete entire Files from folder
There is no need to search for the command and then execute the command. The command I can give to the system whose content will get deleted from the folders is $ rm -fR "{}*". This command will remove all the files and also directories from the specific folders. –f command represents the system to do the force remove and –R command is recursive. If you want to remove the files interactively then you can ask for the confirmation for each and every file, make use of the –i option in place of the –f option. Try it this will help you.
Re: Bash command to delete entire Files from folder
I think kattman is correct. In Linux/UNIX shell, the command to empty out a directory is
Code:
cd "/path/to/directory"
rm -rf *
If you are looking for bash-like commands on windows, biterscripting is your best bet. The commands in biterscripting are
Code:
cd "/path/to/directory"
system -s "del /F /Q *"
Hope this helps.