Close Menu
    What's Hot

    YouTube Unblocked Proxy: Overview, Benefits, and Real-World Use Cases

    April 7, 2026

    Linux Kernel Release Frequency Statistics 2026

    April 7, 2026

    How To Use The SSH Login Command

    April 7, 2026
    Facebook X (Twitter) Instagram
    Command Linux
    • About
    • Man Pages
    • Arch Linux
    • Statistics
    • How to
      • Q&A
    • OS
      • Windows
    • Blog
      • Featured
    • MORE
      • Easter Eggs
      • IP Address
    • Write For Us
    • Contact Us
    Command Linux
    Home - Q&A - How to Rename File in Linux Using Terminal Commands

    How to Rename File in Linux Using Terminal Commands

    WillieBy WillieFebruary 11, 2026Updated:March 30, 2026No Comments3 Mins Read

    Changing file names through the terminal is one of the most common tasks for any Linux user. Whether you need to rename file in Linux for a single document or process hundreds at once, two commands handle most of the work: mv and rename.

    The mv command ships with every distribution and works well for quick, individual renames. The rename utility adds Perl regex support for batch operations. This guide covers both with practical examples so you can pick the right one for your situation. You will also find a section on using the graphical file manager.

    How to Rename File in Linux with the mv Command

    The mv command was built to move files and directories. When you give it a new name instead of a new path, it renames the file in place.

    mv [options] source destination

    To change draft.txt into final.txt:

    mv draft.txt final.txt

    No output appears unless you pass -v. Confirm the result with the ls command.

    Add -i to get a prompt before overwriting existing files:

    mv -i draft.txt final.txt

    Other useful flags: -f forces overwrites, -n prevents them, and -v prints what changed. The mv man page lists all available options.

    Rename File in Linux in Bulk with a Bash Loop

    When you need to rename file in Linux across many items, pair mv with a for loop. This swaps every .txt extension to .md:

    for f in *.txt; do mv -- "$f" "${f%.txt}.md"; done

    ${f%.txt} strips the old extension, and .md gets appended. The double dash protects against file names starting with a hyphen.

    How to Rename File in Linux Using the rename Command

    The rename utility uses Perl expressions, making it a better fit when you need to rename file in Linux across complex patterns.

    Install rename

    # Debian/Ubuntu
    sudo apt install rename
    
    # Fedora/CentOS
    sudo yum install prename

    The pattern is rename 's/old/new/' files. Use -v to see changes, -n for a dry run, and -f to force overwrites.

    Swap Extensions

    rename -v 's/.txt/.pdf/' *.txt

    Replace Part of a Name

    rename -v 's/draft/release/' *.txt

    Rename File in Linux Through the Desktop (GUI)

    Most Linux desktops let you rename file in Linux through a file manager. Right-click the target and pick Rename, or press F2. Select multiple items for batch find-and-replace. Adjust executable permissions separately if needed.

    FAQs

    Can I undo a rename in Linux?

    No built-in undo exists. Run mv or rename again with the original name. Use the -n dry-run flag first to preview changes before applying them.

    How do I rename file in Linux with spaces in the name?

    Wrap the filename in quotes: mv "my file.txt" "my_file.txt". You can also escape each space with a backslash: mv my\ file.txt my_file.txt.

    Can I rename directories with the same commands?

    Yes. Both mv and rename work on directories. Run mv old_folder new_folder to rename a directory the same way you would a file.

    Willie
    • Website

    Willie has over 15 years of experience in Linux system administration and DevOps. After managing infrastructure for startups and enterprises alike, he founded Command Linux to share the practical knowledge he wished he had when starting out. He oversees content strategy and contributes guides on server management, automation, and security.

    Related Posts

    How To Use The SSH Login Command

    April 7, 2026

    How to Apt Install Java on Ubuntu (JRE and JDK)

    March 18, 2026

    Echo Color Code in Linux

    March 16, 2026

    How To Change Permissions Of A File In Linux

    March 12, 2026
    Top Posts

    Linux Set Environment Variable: A Complete Beginner’s Manual

    January 12, 2026

    UTIME

    February 4, 2026

    SETSID

    March 7, 2026

    How Alanna Pow Built a Six-Figure Online Career

    January 27, 2026
    • Home
    • Contact Us
    • Privacy Policy
    • Terms of Use

    Type above and press Enter to search. Press Esc to cancel.