Forrest logo
back to the rename tool

file-rename:tldr:53aff

file-rename: Replace whitespace with underscores.
$ rename 's/\s+/_/g' ${*}
try on your machine

The command you provided is used to rename files or directories by replacing spaces with underscores in their names. Here's how it works:

  1. rename: This is the command itself. It is used to rename files and directories in Linux systems.

  2. 's/\s+/_/g': This is a regular expression pattern surrounded by single quotes. It specifies the pattern to match and the replacement.

    • \s represents whitespace characters (spaces, tabs, etc.)
    • + matches one or more occurrences of the preceding element (in this case, whitespace characters)
    • _ is the replacement character, which will replace the matched whitespace characters
    • g is a flag indicating that the replacement should be done globally, not just the first occurrence
  3. ${*}: This is a variable that represents all the arguments passed to the script or command. In this case, ${*} means all the files and directories in the current directory.

So, when you execute the command, it will search for all files and directories in the current location and replace any whitespace characters in their names with underscores.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the rename tool