I have the a series of markdown files in the working directory:
$ ls *.md
csv_reader.md egrep.md find.md found_pdfs.md osPathSep_help.md readme.md smtplib_help.md today.md
I want to remove them except "today.md"
#!/usr/local/bin/bash
for i in ./*.md ; do
if [[ $i != "today.md" ]]; then
echo $i
fi
done
Run it and get
$ bash bash/remove_files.sh
./csv_reader.md
./egrep.md
./find.md
./found_pdfs.md
./osPathSep_help.md
./readme.md
./smtplib_help.md
./today.md
Nonetheless, the structured commands are not handy in the command line, how could I accomplish such a task with shorter commands
for f in *.md; do test "$f" = "today.md" || echo rm "$f"; done
. (remove theecho
to actually remove them). – Oct 31 '18 at 08:18mv today.md today.bak; rm *.md; mv today.bak today.md
– jingyu9575 Oct 31 '18 at 09:23;
. – rexkogitans Oct 31 '18 at 09:29