There are some extensionless files in current directory (there are not dot in their names).I want to rename like so:filename -> filename.mdI tried doing mv * *.md but that didn't help.I am interested in a function that takes an argument for the extension and renames accordingly, and the another one for the files to perform operation on.
How to change extension of all files in a directory?
bash;rename
Patterns are matched by the shell, not by the command, so what you tried had no chance to work: first the shell expands * to all files (not just the extensionless ones: you never said anything about the files not having a . in their name), and *.md to all files whose name in .md; then the shell passes the concatenation of the two lists to the mv command.In zshIn zsh, run the following command once (put them in your ~/.zshrc for the future):autoload -U zmv# you don't need the following two now, but put them also in your .zshrcalias zcp='zmv -C'alias zln='zmv -L'You can then run zmv to rename files according to a pattern. Both the pattern and the replacement text need to be quoted so that they are passed-as is to the zmv function which will expand them in due course.zmv '^*.*' '$f.md'Note the single quotes around both arguments: the pattern and the replacement expression must be passed literally to the zmv function.^*.* means all files except the ones matching *.*, it's a shortcut for *~*.* (both are zsh extensions to the traditional pattern syntax). If you want to use this pattern outside zmv, you need to run setopt extended_glob first (put that in your .zshrc too).In bashBash has no such convenient tool, so you have to resort to a loop. First, activate ksh globbing extensions; that's something you should put in yout ~/.bashrc.shopt -s extglobNow you can use the !(PATTERN) operator to match extensionless files.for x in !(*.*); do  mv -- $x $x.mddoneThe double quotes arond $x are necessary in case the file names contain whitespace or globbing characters. The -- after the command name is necessary in case a file name begins with -.In any shellIf you don't have the !() operator, you can loop over all files and test each file name inside the loop.for x in *; do  case $x in    *.*) ;;         # skip this file    *) mv -- $x $x.md;;  esacdone