find . -type f -name "(file name)_*"|sed 's/\.\///g'|grep -v '/' |xargs -I'A' mv 'A' (file path)/'A'
1 Answers
@Author
find . -type f
Search files at current directory including all sub directories
find . -type f -name "(file name)*"
I have following files:
73151424.sh
file
name
file1name
name2file
file1name
file name_
(file name)
$ find . -type f -name "(file name)"
./(file name)_
$ cp file1name "(file name)1"
$ find . -type f -name "(file name)"
./(file name)
./(file name)1
Hence find the file names who can have the name "(file name)" followed by zero or more occurence of
$cp file1name "(file name)_____"
$ find . -type f -name "(file name)*"
./(file name)
./(file name)_1
./(file name)_____
When we are using any command better to use
2>&1
find ./ 2>&1 |
redirect error also to same output stream
sed 's/.///g'
Using sed
Replace dot character
.
followed by a slash character
/
with
empty string
//
Replace
./
with
//
at all occurences(globally) using
//g
sedto remove., filters out names that contain/, and runsxargson the output to callmv. Which particular step is causing confusion? - William Pursellxargs.Ais the "replstr"; basically a placeholder that is replaced by the filenames. - William Pursell