Results 1 to 5 of 5

Thread: Bash command to delete entire Files from folder

  1. #1
    Join Date
    Apr 2010
    Posts
    53

    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?

  2. #2
    Join Date
    Sep 2005
    Posts
    1,306

    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?

  3. #3
    Join Date
    Apr 2008
    Posts
    4,088

    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.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,139

    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.

  5. #5
    Join Date
    Dec 2009
    Posts
    23

    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.

Similar Threads

  1. Replies: 6
    Last Post: 27-05-2011, 10:20 AM
  2. Linux bash script with the command w
    By Trini Alvarado in forum Operating Systems
    Replies: 4
    Last Post: 22-03-2010, 12:11 PM
  3. Replies: 1
    Last Post: 13-10-2009, 05:53 PM
  4. bash : ipconfig command not found
    By UbuntU-ME in forum Operating Systems
    Replies: 3
    Last Post: 11-08-2009, 07:16 PM
  5. How to delete folder from the command prompt?
    By Jack in forum Vista Help
    Replies: 7
    Last Post: 07-03-2008, 11:13 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,643,593.17979 seconds with 17 queries