Unix command to remove space from a file name
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have a file whose file name has a space like First Name_20180810.csv
. The date (20180810
in the above example) changes daily in the filename.
How can I rename First Name_*.csv
to be FirstName_*.csv
?
rename filenames whitespace
add a comment |Â
up vote
0
down vote
favorite
I have a file whose file name has a space like First Name_20180810.csv
. The date (20180810
in the above example) changes daily in the filename.
How can I rename First Name_*.csv
to be FirstName_*.csv
?
rename filenames whitespace
1
difficult to understand, try using the blockquote or code sample to enter the file name or commands from body toolbar while drafting your question
â Bharat
Aug 10 at 21:00
Similar to stackoverflow.com/questions/6911301/⦠...
â Anon
Aug 11 at 3:20
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a file whose file name has a space like First Name_20180810.csv
. The date (20180810
in the above example) changes daily in the filename.
How can I rename First Name_*.csv
to be FirstName_*.csv
?
rename filenames whitespace
I have a file whose file name has a space like First Name_20180810.csv
. The date (20180810
in the above example) changes daily in the filename.
How can I rename First Name_*.csv
to be FirstName_*.csv
?
rename filenames whitespace
rename filenames whitespace
edited Aug 11 at 7:16
Kusalananda
106k14209327
106k14209327
asked Aug 10 at 20:55
faujong
82
82
1
difficult to understand, try using the blockquote or code sample to enter the file name or commands from body toolbar while drafting your question
â Bharat
Aug 10 at 21:00
Similar to stackoverflow.com/questions/6911301/⦠...
â Anon
Aug 11 at 3:20
add a comment |Â
1
difficult to understand, try using the blockquote or code sample to enter the file name or commands from body toolbar while drafting your question
â Bharat
Aug 10 at 21:00
Similar to stackoverflow.com/questions/6911301/⦠...
â Anon
Aug 11 at 3:20
1
1
difficult to understand, try using the blockquote or code sample to enter the file name or commands from body toolbar while drafting your question
â Bharat
Aug 10 at 21:00
difficult to understand, try using the blockquote or code sample to enter the file name or commands from body toolbar while drafting your question
â Bharat
Aug 10 at 21:00
Similar to stackoverflow.com/questions/6911301/⦠...
â Anon
Aug 11 at 3:20
Similar to stackoverflow.com/questions/6911301/⦠...
â Anon
Aug 11 at 3:20
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
1
down vote
accepted
If you do not have access to the rename
tool, this should work:
for file in *.csv; do
if ! [[ -f "$file// /" ]]; then
mv "$file" "$file// /"
else
echo "Replacement for '$file' already exists; skipping"
fi
done
I always recommend usingmv -i
or-n
when doing any sort of bulk move/rename, to avoid silent and irreversible data loss in case there are any name conflicts.
â Gordon Davisson
Aug 11 at 6:50
add a comment |Â
up vote
1
down vote
Use rename
command:
rename "s/ //g" *.csv
man rename
:examples
add a comment |Â
up vote
0
down vote
If I understand correctly something like this should work for a single file
mv First Name_20180810.csv FirstName_20180810.csv
ya I'll just assume they only need 1 file changed. It's not clear from the question
â GNUzilla
Aug 10 at 21:06
Thank you all. Yes, there is only 1 file whose name I need to change. The command will run daily, and the file name changes daily. For example, today the file name is First Name_20180812.csv, tomorrow the file name is First Name_20180813.csv. So, the command can't be "mv First Name_20180812.csv FirstName_20180812.csv", because tomorrow the file nameis First Name_20180813.csv
â faujong
Aug 12 at 23:35
The solution that DopeGhoti/confetti gave works. Here is my command on 1 line: for file in /dv/DataStage/TEST/MyFile*.csv ; do if ! [[ -f "$file// /" ]]; then mv "$file" "$file// /" ; fi ; done
â faujong
Aug 23 at 21:06
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
If you do not have access to the rename
tool, this should work:
for file in *.csv; do
if ! [[ -f "$file// /" ]]; then
mv "$file" "$file// /"
else
echo "Replacement for '$file' already exists; skipping"
fi
done
I always recommend usingmv -i
or-n
when doing any sort of bulk move/rename, to avoid silent and irreversible data loss in case there are any name conflicts.
â Gordon Davisson
Aug 11 at 6:50
add a comment |Â
up vote
1
down vote
accepted
If you do not have access to the rename
tool, this should work:
for file in *.csv; do
if ! [[ -f "$file// /" ]]; then
mv "$file" "$file// /"
else
echo "Replacement for '$file' already exists; skipping"
fi
done
I always recommend usingmv -i
or-n
when doing any sort of bulk move/rename, to avoid silent and irreversible data loss in case there are any name conflicts.
â Gordon Davisson
Aug 11 at 6:50
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
If you do not have access to the rename
tool, this should work:
for file in *.csv; do
if ! [[ -f "$file// /" ]]; then
mv "$file" "$file// /"
else
echo "Replacement for '$file' already exists; skipping"
fi
done
If you do not have access to the rename
tool, this should work:
for file in *.csv; do
if ! [[ -f "$file// /" ]]; then
mv "$file" "$file// /"
else
echo "Replacement for '$file' already exists; skipping"
fi
done
edited Aug 11 at 8:18
confetti
25513
25513
answered Aug 10 at 22:27
DopeGhoti
41k55080
41k55080
I always recommend usingmv -i
or-n
when doing any sort of bulk move/rename, to avoid silent and irreversible data loss in case there are any name conflicts.
â Gordon Davisson
Aug 11 at 6:50
add a comment |Â
I always recommend usingmv -i
or-n
when doing any sort of bulk move/rename, to avoid silent and irreversible data loss in case there are any name conflicts.
â Gordon Davisson
Aug 11 at 6:50
I always recommend using
mv -i
or -n
when doing any sort of bulk move/rename, to avoid silent and irreversible data loss in case there are any name conflicts.â Gordon Davisson
Aug 11 at 6:50
I always recommend using
mv -i
or -n
when doing any sort of bulk move/rename, to avoid silent and irreversible data loss in case there are any name conflicts.â Gordon Davisson
Aug 11 at 6:50
add a comment |Â
up vote
1
down vote
Use rename
command:
rename "s/ //g" *.csv
man rename
:examples
add a comment |Â
up vote
1
down vote
Use rename
command:
rename "s/ //g" *.csv
man rename
:examples
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Use rename
command:
rename "s/ //g" *.csv
man rename
:examples
Use rename
command:
rename "s/ //g" *.csv
man rename
:examples
answered Aug 10 at 22:00
GAD3R
22.8k154895
22.8k154895
add a comment |Â
add a comment |Â
up vote
0
down vote
If I understand correctly something like this should work for a single file
mv First Name_20180810.csv FirstName_20180810.csv
ya I'll just assume they only need 1 file changed. It's not clear from the question
â GNUzilla
Aug 10 at 21:06
Thank you all. Yes, there is only 1 file whose name I need to change. The command will run daily, and the file name changes daily. For example, today the file name is First Name_20180812.csv, tomorrow the file name is First Name_20180813.csv. So, the command can't be "mv First Name_20180812.csv FirstName_20180812.csv", because tomorrow the file nameis First Name_20180813.csv
â faujong
Aug 12 at 23:35
The solution that DopeGhoti/confetti gave works. Here is my command on 1 line: for file in /dv/DataStage/TEST/MyFile*.csv ; do if ! [[ -f "$file// /" ]]; then mv "$file" "$file// /" ; fi ; done
â faujong
Aug 23 at 21:06
add a comment |Â
up vote
0
down vote
If I understand correctly something like this should work for a single file
mv First Name_20180810.csv FirstName_20180810.csv
ya I'll just assume they only need 1 file changed. It's not clear from the question
â GNUzilla
Aug 10 at 21:06
Thank you all. Yes, there is only 1 file whose name I need to change. The command will run daily, and the file name changes daily. For example, today the file name is First Name_20180812.csv, tomorrow the file name is First Name_20180813.csv. So, the command can't be "mv First Name_20180812.csv FirstName_20180812.csv", because tomorrow the file nameis First Name_20180813.csv
â faujong
Aug 12 at 23:35
The solution that DopeGhoti/confetti gave works. Here is my command on 1 line: for file in /dv/DataStage/TEST/MyFile*.csv ; do if ! [[ -f "$file// /" ]]; then mv "$file" "$file// /" ; fi ; done
â faujong
Aug 23 at 21:06
add a comment |Â
up vote
0
down vote
up vote
0
down vote
If I understand correctly something like this should work for a single file
mv First Name_20180810.csv FirstName_20180810.csv
If I understand correctly something like this should work for a single file
mv First Name_20180810.csv FirstName_20180810.csv
edited Aug 10 at 21:06
answered Aug 10 at 21:02
GNUzilla
11
11
ya I'll just assume they only need 1 file changed. It's not clear from the question
â GNUzilla
Aug 10 at 21:06
Thank you all. Yes, there is only 1 file whose name I need to change. The command will run daily, and the file name changes daily. For example, today the file name is First Name_20180812.csv, tomorrow the file name is First Name_20180813.csv. So, the command can't be "mv First Name_20180812.csv FirstName_20180812.csv", because tomorrow the file nameis First Name_20180813.csv
â faujong
Aug 12 at 23:35
The solution that DopeGhoti/confetti gave works. Here is my command on 1 line: for file in /dv/DataStage/TEST/MyFile*.csv ; do if ! [[ -f "$file// /" ]]; then mv "$file" "$file// /" ; fi ; done
â faujong
Aug 23 at 21:06
add a comment |Â
ya I'll just assume they only need 1 file changed. It's not clear from the question
â GNUzilla
Aug 10 at 21:06
Thank you all. Yes, there is only 1 file whose name I need to change. The command will run daily, and the file name changes daily. For example, today the file name is First Name_20180812.csv, tomorrow the file name is First Name_20180813.csv. So, the command can't be "mv First Name_20180812.csv FirstName_20180812.csv", because tomorrow the file nameis First Name_20180813.csv
â faujong
Aug 12 at 23:35
The solution that DopeGhoti/confetti gave works. Here is my command on 1 line: for file in /dv/DataStage/TEST/MyFile*.csv ; do if ! [[ -f "$file// /" ]]; then mv "$file" "$file// /" ; fi ; done
â faujong
Aug 23 at 21:06
ya I'll just assume they only need 1 file changed. It's not clear from the question
â GNUzilla
Aug 10 at 21:06
ya I'll just assume they only need 1 file changed. It's not clear from the question
â GNUzilla
Aug 10 at 21:06
Thank you all. Yes, there is only 1 file whose name I need to change. The command will run daily, and the file name changes daily. For example, today the file name is First Name_20180812.csv, tomorrow the file name is First Name_20180813.csv. So, the command can't be "mv First Name_20180812.csv FirstName_20180812.csv", because tomorrow the file nameis First Name_20180813.csv
â faujong
Aug 12 at 23:35
Thank you all. Yes, there is only 1 file whose name I need to change. The command will run daily, and the file name changes daily. For example, today the file name is First Name_20180812.csv, tomorrow the file name is First Name_20180813.csv. So, the command can't be "mv First Name_20180812.csv FirstName_20180812.csv", because tomorrow the file nameis First Name_20180813.csv
â faujong
Aug 12 at 23:35
The solution that DopeGhoti/confetti gave works. Here is my command on 1 line: for file in /dv/DataStage/TEST/MyFile*.csv ; do if ! [[ -f "$file// /" ]]; then mv "$file" "$file// /" ; fi ; done
â faujong
Aug 23 at 21:06
The solution that DopeGhoti/confetti gave works. Here is my command on 1 line: for file in /dv/DataStage/TEST/MyFile*.csv ; do if ! [[ -f "$file// /" ]]; then mv "$file" "$file// /" ; fi ; done
â faujong
Aug 23 at 21:06
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461899%2funix-command-to-remove-space-from-a-file-name%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
difficult to understand, try using the blockquote or code sample to enter the file name or commands from body toolbar while drafting your question
â Bharat
Aug 10 at 21:00
Similar to stackoverflow.com/questions/6911301/⦠...
â Anon
Aug 11 at 3:20