User Tools

Site Tools


bash_notes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
bash_notes [2022/04/06 22:25] – [list file names within a specific range] rajubash_notes [2023/12/28 08:46] – [useful links] raju
Line 1: Line 1:
 ===== tasks ===== ===== tasks =====
-==== list file names within a specific range ==== +==== dummy ==== 
-Q: Given a set of files in a directory: +  * [[list files within a specific range]]
-<code> +
-file1.txt +
-file2.txt +
-... +
-file30.txt +
-... +
-</code> +
-how do I list files within a specific range, say 18 through 31?+
  
-A:+===== dummy ===== 
 +==== other pages in this wiki ==== 
 +  * [[bash scripting]] 
 + 
 +==== useful links ==== 
 +  * https://explainshell.com/ - useful for understanding complex shell commands 
 +  * https://mywiki.wooledge.org/ArithmeticExpression - Arithmetic Expansion 
 +  * https://misc.flogisoft.com/bash/tip_colors_and_formatting - escape characters, color prompts, echo colored strings 
 +  * http://ezprompt.net/ - Easy bash prompt generator 
 + 
 +==== documentation links ==== 
 +  * ignoredups, erasedups - https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html search for ignoredups . 
 + 
 +==== what is the difference between "ls > dirlist 2>&1" and "ls 2>&1 > dirlist"? ==== 
 +The command
 <code> <code>
-ls file{18..31}.txt+ls > dirlist 2>&1
 </code> </code>
- +directs both standard output (file descriptor 1) and standard error (file descriptor 2) to the file dirlistwhile the command
-To run a command on each of themuse a for loop+
 <code> <code>
-for file in file{18..31}.txt +ls 2>&1 > dirlist
-...+
 </code> </code>
 +directs only the standard output to file dirlist, because the standard error was made a copy of the standard output before the standard output was redirected to dirlist.
  
-This construct is known as a "sequence expression" and is part of Bash's brace expansion feature. It takes the form ''{x..y[..incr]}'', where x and y are either integers or single characters, and incr, an optional increment, is an integer.+To conclude, the order of redirections is significant.
  
-Ref: +Ref:https://www.gnu.org/software/bash/manual/html_node/Redirections.html -> 5th paragraph.
-  * https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html - documentation on Bash's brace expansion feature. +
-  * https://superuser.com/questions/236484/list-files-numbered-in-a-specific-range - where I first came across the above solution. Dennis Williamson's reply is pretty comprehensive; provides alternatives solutions; addresses corner cases; high information density. It is worth reading it end to end.+
  
-tags | list file names with a range 
- 
-===== dummy ===== 
-==== useful links ==== 
-  * https://mywiki.wooledge.org/ArithmeticExpression - Arithmetic Expansion  
 ===== getopts ===== ===== getopts =====
 ==== useful articles ==== ==== useful articles ====
bash_notes.txt · Last modified: 2023/12/28 08:49 by raju