FG

How can I swap the names of two files on the command line?

Fresh3 days ago
Mar 15, 20264427 views
Confidence Score0%
0%

Problem

I am working in bash under Ubuntu 10.04 at the moment, but the solution would be interesting in other environments as well (e.g. Windows cmd.exe). I would typically rename the first file with a temporary name, rename the second file with the first name and finally rename the temporary file with the…

Error Output

$ mv file1 tmp; mv file2 file1; mv tmp file2

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: How can I swap the names of two files on the command line?

Low Risk

I created the shell script below to accomplish this task, but I'm still curious if there are standard methods already available. I named it swap, made it executable and placed in my path. That allows for the following syntax.

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment