Shell Script

I am trying to write a shell script that covert all the music file in a folder to use the following format. Tract 01.wav....... Would the following script work?

makedir /music_ram
mount -t tmpfs -o -size=800m none /music_ram

mv "01*.wav" /music_ram/Track 01.wav
mv "02*.wav" /music_ram/Track 02.wav
mv "03*.wav" /music_ram/Track 03.wav
mv "04*.wav" /music_ram/Track 04.wav
mv "05*.wav" /music_ram/Track 05.wav
mv "06*.wav" /music_ram/Track 06.wav
mv "07*.wav" /music_ram/Track 07.wav
mv "08*.wav" /music_ram/Track 08.wav
mv "09*.wav" /music_ram/Track 09.wav
mv "10*.wav" /music_ram/Track 10.wav
mv "11*.wav" /music_ram/Track 11.wav
mv "12*.wav" /music_ram/Track 12.wav
mv "13*.wav" /music_ram/Track 13.wav
mv "14*.wav" /music_ram/Track 14.wav
mv "15*.wav" /music_ram/Track 15.wav
mv "16*.wav" /music_ram/Track 16.wav
mv "17*.wav" /music_ram/Track 17.wav
mv "18*.wav" /music_ram/Track 18.wav
mv "19*.wav" /music_ram/Track 19.wav
mv "20*.wav" /music_ram/Track 20.wav

1. makedir? mkdir?
2. Why create directory under / (root) directory?
3. You may want to cd (change directory) to the directory where *.WAV are placed...

I don't know what does it mean by mounting none to a directory, so I leave it to other members...

TOP

why not try it by using "cp" instead of "mv"?

TOP

原帖由 ackcheng 於 2009-1-2 00:52 發表
I am trying to write a shell script that covert all the music file in a folder to use the following format. Tract 01.wav....... Would the following script work?


makedir /music_ram
mount -t tmpfs -o -size=800m none /music_ram

mv "01*.wav" /music_ram/Track 01.wav
mv "02*.wav" /music_ram/Track 02.wav
mv "03*.wav" /music_ram/Track 03.wav


我諗有 D 小問題令你個 script 未必 work 喎
首先有版友講o左 makedir 應該係 mkdir
跟住句 mount command 個 -o -size=800m 應該係 -o size=800m
然後就係 D mv commands, 你係想 move "Track 01.wav", "Track 02.wav" 等等入去個 directory 入面? 你句 mv command 個 source 寫 "01*.wav", 咁應該唔會 match 到用 Track 開頭o既 file 名 其實如果你想將全部 Track 開頭o既 files move 晒去o個個 directory, 你用一句
mv Track*.wav /music_ram/
就 OK
最後都係提一句, 你 move 落去個 directory reboot 完就會 clear o左, 你 move 之前最好先 make sure D file 係用完就洗得

TOP

個script初頭最好有個if. 假如個directory唔係度先再mkdir.

TOP

原帖由 ackcheng 於 2009-1-2 00:52 發表
I am trying to write a shell script that covert all the music file in a folder to use the following format. Tract 01.wav....... Would the following script work?

makedir /music_ram
mount -t tmpfs -o - ...


Do you know the different of "01*.wav" ( double quotation mark ) and 01*.wav ( no quotation mark ) ??

TOP

原帖由 corvus 於 2009-1-2 14:12 發表
個script初頭最好有個if. 假如個directory唔係度先再mkdir.


It could be a little bit better, but I can't see a big difference in terms of performance or neatness.
"mkdir" itself will check on its own, right ??

TOP

回覆 7# 的帖子

You don't want any unnecessary message in the sysout (or redirected logfile).

mkdir: cannot create directory `test': File exists

TOP

原帖由 little_keung 於 2009-1-2 15:46 發表


Do you know the different of "01*.wav" ( double quotation mark ) and 01*.wav ( no quotation mark ) ??


Wow, 你唔講我都冇為意添   返而後面個 "Track 01.wav" 應該要 quote

Filename expansion 係容易搞亂, 舉個例, 一個 Folder 入面有三個 File 我當叫 file01.txt, file02.txt, file03.txt:
1) ls -l  file*.txt
2) ls -l "file*.txt"
3) for i in "file*.txt"; do ls -l $i; done
邊個 list 到邊個又 list 唔到 ?

TOP

原帖由 corvus 於 2009-1-2 16:18 發表
You don't want any unnecessary message in the sysout (or redirected logfile).



I agree it is a good practice, but I don't agree it is an important step to solve the current issue.

TOP