Jump to content

The command Touch?


peman
 Share

Recommended Posts

Hi

I need to know how to create several files in one command line?

I want to have ch01 ch02 ch03... and so on up to ch14

Is'nt the touch command?

 

I also want to know how to create several files with content like author or something like that.

 

Thanks! :)

Edited by peman
Link to comment
Share on other sites

I couldn't resist, ramfree + bash, my two favorite discussion topics :mr-green: :P

 

While ramfree's advice is 100% correct, I would have done it using a "for" loop:

 

#! /bin/bash

for ((i=1; i<=14; ++i)); # or for i in $(seq 14);

do

        touch $(printf "ch%02d" $i)

done

 

 

The printf stuff allows you to name the files as you wanted:

~/example$ ./thisscript
~/example$ ls
ch01  ch03  ch05  ch07  ch09  ch11  ch13
ch02  ch04  ch06  ch08  ch10  ch12  ch14

 

If you want to include, for example the author name on each file, then instead of using the touch command just replace that line with this one:

echo "Author: Myself" > $(printf "ch%02d" $i)

 

Hence, on each file you'll have that text ; ie:

 ~/example$ cat ch01
Author: Myself

 

HTH

Link to comment
Share on other sites

just move everything to a directory? you could use find+xargs to copy them over.

 

Though right, it could be done w/o xargs:

~$ find basedir/ -iname "*.mp3" -exec bash -c 'mv $1 DEST_DIR/' {} {} \;

 

or lets wait gAru to whip up something that also arranges them according to genre :twisted:

 

ciao!

 

That's simple :P just replace DEST_DIR with the output of mp3info -p '%g' mp3file; the problem is that all the mp3 should have a coherent genre value (if not, you might end with a new directory for each mp3, and of course, it must have a valid ID3 tag.

 

For example, this would be (not tested):

 ~$ find basedir/ -iname "*.mp3" -exec bash -c 'GENRE_DIR=$(mp3info -p "%g" $1); [ "${GENRE_DIR}" == "" ] && GENRE_DIR=no_genre_dir/; mkdir -p "$GENRE_DIR"; mv $1 "$GENRE_DIR/"' {} {} \;

 

trivial, isn't it?

 

:juggle:

Edited by aru
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...