Friday, July 13, 2012

Using regexp in Linux commands

What if you have several files with same name but different extension and you want to choose only few files and leave the rests?

See the example here:

Create several files:
najmi@vostro:~/test$ touch aku.png aku.jpg aku.txt

najmi@vostro:~/test$ ls
aku.jpg  aku.png  aku.txt

New directory to separate the files
najmi@vostro:~/test$ mkdir newdir

Use {} braces to include only the specific extensions that you want to handle:
najmi@vostro:~/test$ mv aku.{jpg,txt} newdir/ -v
`aku.jpg' -> `newdir/aku.jpg'
`aku.txt' -> `newdir/aku.txt'

Check current directory
najmi@vostro:~/test$ ls
aku.png  newdir

Selected files already affected(moved)
najmi@vostro:~/test$ ls newdir/
aku.jpg  aku.txt

No comments:

Post a Comment