No menu items!
More
    HomeTutsUbuntuHow to Delete File and Folder with 'rm' Command in Ubuntu

    How to Delete File and Folder with ‘rm’ Command in Ubuntu

    This guide will walk you through the basics to advanced usage of the ‘rm’ command in Linux. We’ll cover everything from the simple deletion of files to more complex tasks, such as recursive deletion and forced deletion.

    How to Basic Use of ‘rm’ Command in Ubuntu

    Delete a file in Linux, you use the ‘rm’ command followed by the filename, for the complete syntax, rm [arguments] file. This command is your go-to tool for removing files or directories in your Linux filesystem.

    rm file.txt
    
    # Output:
    # file.txt is deleted

    That’s the basic use of the ‘rm’ command. It’s straightforward, but powerful. However, it’s important to note that using the ‘rm’ command is irreversible.

    How to Advanced Use of ‘rm’ Command

    These flags can make the ‘rm’ command more powerful and flexible, allowing you to handle more complex file and directory deletion tasks.

    FlagDescriptionExample
    -r or -RRecursive removal. Allows the deletion of directories and their contents.rm -r directory
    -fForce deletion. Ignores nonexistent files and arguments, and never prompts.rm -f filename
    -iInteractive prompt before every removal.rm -i filename
    -vVerbose. Explains what is being done.rm -v filename
    -dRemove directories without prompting for confirmation.rm -d directory
    --preserve-rootDo not remove ‘/’ (default).rm --preserve-root
    --no-preserve-rootDo not treat ‘/’ specially.rm --no-preserve-root
    --one-file-systemSkip directories on different file systems.rm --one-file-system
    -IPrompt once before removing more than three files, or when removing recursively.rm -I
    --End of options.rm -- -filename

    Example

    rm -rf /var/www/domain.com/my-directory

    Delete my-directory recursive removal and never prompts.

    LEAVE A REPLY

    Please enter your comment!
    Please enter your name here