Select file which contains sqlite
in my current directory:
ls | grep sqlite
null and empty string in sqlite.txt
pythoin write None into sqlite.txt
Move them into /tmp
directory:
ls |grep sqlite |xargs -i mv {} /tmp
ls /tmp | grep sqlite
null and empty string in sqlite.txt
pythoin write None into sqlite.txt
How can move them into /tmp
and change the file extension as rst
at the same time?
ls |grep sqlite | some_simple_bash_command
After executing it:
ls /tmp | grep sqlite
null and empty string in sqlite.rst
pythoin write None into sqlite.rst
@David C. Rankin,grep sqlite *
can't work at all!
Try this Shellcheck-clean code:
for f in *sqlite*; do
mv -v -- "$f" "/tmp/${f%.*}.rst"
done
*sqlite*
expands to the list of files in the current directory that contain the string sqlite
anywhere in their names. See the Pattern Matching section of the Bash Reference Manual.${f%.*}
expands to the value of $f
with any suffix removed. See Removing part of a string (BashFAQ/100 (How do I do string manipulation in bash?)).--
argument to mv
is to ensure proper handling of files whose names begin with -
. See Bash Pitfalls #2 (cp $file $target).