1
votes
find . -type f -name "(file name)_*"|sed 's/\.\///g'|grep -v '/' |xargs -I'A' mv 'A' (file path)/'A'
1
It runs find, pipes the output to sed to remove ., filters out names that contain /, and runs xargs on the output to call mv. Which particular step is causing confusion? - William Pursell
Part mv A. What is use of A here?? - Sarthakk
Check the documentation for xargs. A is the "replstr"; basically a placeholder that is replaced by the filenames. - William Pursell
Finally understood everything. Thank you so much for helping:) - Sarthakk

1 Answers

-1
votes

@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