for loop, counting forward for backward

for i in {1..15}; do echo $i; done
The brace expansion also allows you to count backward: for i in {15..1}; do echo $i; done You can also use this construct to create new file or new directory: mkdir dir{1..3} # Same as mkdir dir1 dir2 dir3

0
By: haivu
2009-03-21 23:08:41

These Might Interest You

  • This will enable the possibility to navigate in the history of the command you type with the arrow keys, example "na" and the arrow will give all command starting by na in the history.You can add these lines to your .bashrc (without &&) to use that in your default terminal.


    0
    bind '"\e[A": history-search-backward' && bind '"\e[B": history-search-forward' && bind '"\eOA": history-search-backward' && bind '"\eOB": history-search-forward'
    archesys · 2017-09-29 10:31:56 0
  • Tested with bash v4.1.5 on ubuntu 10.10 Limitations: as written above, only works for programs with no file extention (i.e 'proggy', but not 'proggy.sh') because \eb maps to readine function backward-word rather then shell-backward-word (which is unbinded by default on ubuntu), and correspondingly for \ef. if you're willing to have Ctrl-f and Ctrl-g taken up too , you can insert the following lines into ~/.inputrc, in which case invoking Ctrl-e will do the right thing both for "proggy" and "proggy.sh". -- cut here -- \C-f:shell-backward-word \C-g:shell-forward-word "\C-e":"\C-f`which \C-g`\e\C-e" -- cut here -- Show Sample Output


    0
    bind '"\C-e":"\eb `which \ef`\e\C-e"'
    jennings6k · 2011-01-26 16:11:52 0
  • Say you need to ping every 5th IP address on your network .. this will give you a way of doing that. jot can also do counting ... like jot 4 1 2 3 4 download from http://oreilly.com/catalog/upt2/examples/#jot or fins athena-jot in rpm format Show Sample Output


    -5
    for f in `jot - 0 50 5` ; do ping -c 1 -m 50 10.0.2.$f ; done
    chinkshady · 2009-03-23 23:51:18 7
  • flip shell history with PG UP/PG DOWN like with arrows. just type ss and PG UP and see all ssh commands, type ls and PG DOWN - see all ls commands. need to uncomment two options in /etc/inputrc: "\e[5~": history-search-backward "\e[6~": history-search-forward hack found: http://broddlit.wordpress.com/2008/04/12/making-the-bash-history-a-better-place/


    1
    bash history: modification /etc/inputrc
    kramer · 2012-01-19 22:32:15 0

What Others Think

for complex or more specialized counting, find jot ( http://oreilly.com/catalog/upt2/examples/#jot) that way you can do counting a lot easier say you want to ping a /24 range of ips, but every 5th IP for f in `jot - 0 255 5` ; do ping 192.168.0.$f ; done
chinkshady · 482 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: