mv ./assets/en/images/pricing/'current offers'/'SIMPLE GRID' ./assets/en/images/pricing/'current_offers'/'SIMPLE_GRID' but is not working.
Could you please give me a suggestion or any other idea to do this?
Thanks for the help.
Best regards
---------- Post updated at 04:27 PM ---------- Previous update was at 04:07 PM ----------
I have tried also these
find . -name '* *' | while read file;
do
target=`echo "$file" | sed 's/ /_/g'`;
echo "Renaming '$file' to '$target'";
mv "$file" "$target";
done;
But is not working
I received an error, since it replace the first found instance for example
assets/en/images/pricing/current_offers but when tries to change the second
assets/en/images/pricing/current offers/SIMPLE GRID it shows "No such file or directory"
The first matter of business is to reverse the order of the matches, so you are looking at the last matches first, which will be the deepest subdirectories/files in a particular tree. This will prevent you from renaming a parent directory first, and later having an invalid path to a subdirectory. You can use 'tac' to reverse the order of the matches returned by find.
You are getting the error message because you are replacing all spaces in the line with underscores, including those in the path. However, the mv command will only rename the filename (or directory) given after the last slash, not the entire path including a filename.
For example, if I have a directory structure like this (with spaces):
parent dir
\_ sub dir
And I do this to change the spaces into underscores:
mv is going to give me an error because parent_dir (with underscores) does not exist for sub\ dir to be placed there. mv is only operating on sub\ dir, and it is given an invalid path.
To prevent this, separate the filename from the path, so you can operate on the filename separately from the path. The 'dirname' and 'basename' commands help you do this.
Lastly, use sed to replace all spaces in the filename with underscores, then glue the path and filename back together in your mv command.
Changing your code around, it would end up looking something like this:
I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. This is for Solaris. Please help. (1 Reply)
Hello Everyone,
I have a file sam1 with the below content
SYSYSID;MANDT;/SIE/AD_Z0M_INDX;/SIE/AD_Z0M_KEY1
echo $Regex
\bSYSYSID\b|\bMANDT\b|\b/SIE/AD_Z0M_INDX\b|\b/SIE/AD_Z0M_KEY1\b
cat sam1 | grep -Eo $Regex
I expect the result as
SYSYSID
MANDT
/SIE/AD_Z0M_INDX
/SIE/AD_Z0M_KEY1... (4 Replies)
Hi Folks,
I have a script that I am using. The files are in Directory c:\files\change\options
In that directory I have many other sub folders like R1 R2 R5 E4 etc...
When I run this script in windows, It looks like its just changing the first folder R1 and not the rest.
Can I get an... (6 Replies)
Hi all,
Using grep command, i want to find the pattern of text in all directories and sub-directories.
e.g: if i want to search for a pattern named "parmeter", i used the command
grep -i "param" ../*
is this correct? (1 Reply)
looking for a wget option that does not retrieve entire path from source box...
currently working with the following syntax:
wget --no-verbose --mirror --no-parent --no-host-directories --page-requisites --ftp-user=mis --ftp-password=secret ftp://192.x.x.x/tmp/test
is anyone familiar... (0 Replies)
Hello all,
Here's the deal...I have one directory with many subdirs and files.
What I want to find out is who is keeping old files and directories...say files and dirs that they didn't use since a number of n days, only one level under the initial dir. Output to a file.
A script for... (5 Replies)
I need to rename a directory in every home directory on a given workstation. I am a newb to scripting so maybe thats why I cant exactly figure out how to correctly do this.
The first thing I need to be able to do to write this script is figure out how to list all the directorys (these are not... (11 Replies)
Hello All, I am trying to list only directories in my current directory using the command "ls -d". But the output only contains the default directory "." and doesn't list the rest of the directories in the working directory. Can anyone explain why this is happening (2 Replies)
i am new to perl. i am writing a perl script. i want to know how to change the working directories? for ex. i have a perl script in c:\proj\ . i want to run this script in this directory but i need my script to change its working directory to D:\xyz\ dynamically in the script.
your help is... (1 Reply)