Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»General Articles»(Resolved) -bash: /bin/mv: Argument list too long

    (Resolved) -bash: /bin/mv: Argument list too long

    RahulBy RahulNovember 23, 20212 Mins ReadUpdated:January 13, 2022

    One of my development server contains millions of files under a single directory. To free the disk space, we decided to move to them a new folder created on another disk attached to same system. When tried to move file with mv command, received the following error.

    -bash: /bin/mv: Argument list too long

    The “Argument list too long” error, generally comes, when we passed a large number of parameters to single command. A system variable ARG_MAX defines the Maximum Character Length of Arguments In a shell command.

    The Solution

    The quick solution is to use xargs command line utility or find command with -exec … {}. Both commands breaks a large command in smaller and complete the job without errors.

    • Using find with xargs – The following command will move all files with .txt extension to destination directory.
      find . -name '*.txt' | xargs mv --target-directory=/path/to/dest_dir/ 
      
    • Using find with exec – You can also use exec to perform the same task.
      find . -name '*.txt' -exec mv {} /path/to/dest_dir/ \;
      

      The default above commands will navigate recursively to the sub-directories. To limit the find to current directory only use -maxdepth followed by limit number to sub-directories.

      find . -name '*.txt' -maxdepth 1 -exec mv {} /path/to/dest_dir/ \;
      

    You can find the max limit with command getconf ARG_MAX on shell.

    command find shell xargs
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow To Install Python 3.10 on Ubuntu, Debian & Linux Mint
    Next Article Bash Select Command (Create Menu in Shell Scripts)

    Related Posts

    How to Install Sublime Text 4 on Ubuntu 22.04

    2 Mins Read

    How to Find Django Install Location in Linux

    Updated:April 27, 20221 Min Read

    (Resolved) – ReactJS 404 Error on Page Reload

    2 Mins Read

    Adding a New SSH Key in GitHub

    Updated:April 1, 20223 Mins Read

    13 Best Linux Terminal Emulators and Bash Editors

    8 Mins Read

    How To Install Oracle VirtualBox on Debian 11

    2 Mins Read

    1 Comment

    1. Indrajeet on December 29, 2021 10:42 am

      Great info. That will be useful for my website.

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Install Sublime Text 4 on Ubuntu 22.04
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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