Announcement

Collapse
No announcement yet.

Short HOWTO: Create several files with or w/o the same extension

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Short HOWTO: Create several files with or w/o the same extension

    In order to be able to create several files at the same time you can type this in konsole or xterm.

    touch somefile{1,2,3,4,5}.txt

    # Results

    somefile1.txt, somefile2.txt and so on

    touch somefile.{cpp,h,pro,ui}

    # Results

    somefile.cpp, somefile.h, somefile.pro, somefile.ui

    It's up to you where you place the {} parentheses but remember that the results are not the same.
    Multibooting: Kubuntu Noble 24.04
    Before: Jammy 22.04, Focal 20.04, Precise 12.04 Xenial 16.04 and Bionic 18.04
    Win XP, 7 & 10 sadly
    Using Linux since June, 2008

    #2
    Re: Short HOWTO: Create several files with or w/o the same extension

    Originally posted by kyonides
    touch somefile{1,2,3,4,5}.txt
    Pretty cool, but it can be done even simpler:

    Code:
    $touch somefile{1..10}.txt
    $ ls -1 somefile*
    somefile10.txt
    somefile1.txt
    somefile2.txt
    somefile3.txt
    somefile4.txt
    somefile5.txt
    somefile6.txt
    somefile7.txt
    somefile8.txt
    somefile9.txt
    The ".." syntax inside brace expressions causes BASH to iterate from the first character to the second character.

    Originally posted by The GNU Bash Reference Manual Edition 3.2, section 3.5.1 "Brace Expansion"
    A sequence expression takes the form `{X..Y}', where X and Y are either integers or single characters. When integers are supplied, the expression expands to each number between X and Y, inclusive. When characters are supplied, the expression expands to each character lexicographically between X and Y, inclusive. Note that both X and Y must be of the same type.
    So you don't have to necessarily use integers in the expression. This also works:

    Code:
    $ touch somefile_{a..z}.txt
    $ ls -w 80 somefile_*
    somefile_a.txt somefile_g.txt somefile_m.txt somefile_s.txt somefile_y.txt
    somefile_b.txt somefile_h.txt somefile_n.txt somefile_t.txt somefile_z.txt
    somefile_c.txt somefile_i.txt somefile_o.txt somefile_u.txt
    somefile_d.txt somefile_j.txt somefile_p.txt somefile_v.txt
    somefile_e.txt somefile_k.txt somefile_q.txt somefile_w.txt
    somefile_f.txt somefile_l.txt somefile_r.txt somefile_x.txt
    Welcome newbies!
    Verify the ISO
    Kubuntu's documentation

    Comment

    Working...
    X