Mayank Mittal Mayank Mittal - 1 year ago 89
Linux Question

Add id to the downloaded youtube playlist

I've downloaded a youtube playlist with youtube-dl is there any way i can rename the files i've downloaded to the appended id of the file in playlist.
e.g. now - xyz.mp4, abc.mkv,
want - 1 - xyz.mp4, 2 - abc.mkv(which is according to the number in the youtube playlist)

Answer Source

If the files are sortable by date (check if the following produces the right output):

i=1; ls -1trd * | while read -r filename; do echo $i' - '"$filename"; i="$(( i + 1 ))"; done

Then this will rename them. NO UNDO FUNCTION FOR THIS

i=1; ls -1trd * | while read -r filename; do mv -vb "$filename" $i' - '"$filename"; i="$(( i + 1 ))"; done
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download