I would like to change a file name with extension of csv into
test.txt
/Users/xx/xx
part-r-00000-865affea-3ead-445e-ad3e-8703a8d79026.csv
part-r-00000-865affea-3ead-445e-ad3e-xxxx.csv
test.txt
You can use globbing to target a file without knowing its whole name.
Considering you know the file's directory, its extension, and that it is the only one with this extension in this directory, you can simply use this mv
:
mv /Users/xx/xx/*.csv /Users/xx/xx/test.txt
This will rename every .csv
file in /Users/xx/xx/
(in your case, your single CSV file) into /Users/xx/xx/test.txt
.
That would obviously be a problem if there was multiple .csv
files since each would overwrite the previous one. If it could become a problem, you should either check the number of files which are matched by this glob and exit with error if it's greater than 1 or use a command that will only ever act on a single file such as the one suggested by RomanPerekhrest.