Skip to main content

filesystem operations

filenames, wildcards, & pathname expansion

wildcardmatches
?any single character
*any string of characters
[set]any character in set
[!set]any character NOT in set
bash wildcards
$ ls -l
total 0
-rw-rw-r-- 1 deploy deploy 0 Feb 5 18:04 prog.c
-rw-rw-r-- 1 deploy deploy 0 Feb 5 18:04 prog.o
-rw-rw-r-- 1 deploy deploy 0 Feb 5 18:04 prog.txt
$ ls -l prog.?
-rw-rw-r-- 1 deploy deploy 0 Feb 5 18:04 prog.c
-rw-rw-r-- 1 deploy deploy 0 Feb 5 18:04 prog.o
$ ls -l prog.*
-rw-rw-r-- 1 deploy deploy 0 Feb 5 18:04 prog.c
-rw-rw-r-- 1 deploy deploy 0 Feb 5 18:04 prog.o
-rw-rw-r-- 1 deploy deploy 0 Feb 5 18:04 prog.txt
$ ls -l prog.?xt
-rw-rw-r-- 1 deploy deploy 0 Feb 5 18:04 prog.txt
$ ls -l prog.t?t
-rw-rw-r-- 1 deploy deploy 0 Feb 5 18:04 prog.txt
$
set expressionmatches
[abc]a, b, or c
[.,;]Period, comma, or semicolon
[-_]Dash or underscore
[a-c]a, b, or c
[a-z]All lowercase letters
[!0-9]All non-digits
[0-9!]All digits and exclamation point
[a-zA-Z]All lower- and uppercase letters
[a-zA-Z0-9_-]All letters, all digits, underscore, and dash

brace expansion

  • list {a,b,c}
  • range {e..k} {4..10}
  • nested {b{a,e,i,},d}
deploy@vmi2682430:~/test$
deploy@vmi2682430:~/test$ echo pre{A,B,C}post
preApost preBpost preCpost
deploy@vmi2682430:~/test$ echo {A,B,C}
A B C
deploy@vmi2682430:~/test$ echo {A,B{1,2,3}C,D}
A B1C B2C B3C D
deploy@vmi2682430:~/test$ echo {A,B{1..10}C,D}
A B1C B2C B3C B4C B5C B6C B7C B8C B9C B10C D
deploy@vmi2682430:~/test$
deploy@vmi2682430:~/test$
deploy@vmi2682430:~/test$ echo pre{c-k}post
pre{c-k}post
deploy@vmi2682430:~/test$ echo pre{c..k}post
precpost predpost preepost prefpost pregpost prehpost preipost prejpost prekpost
deploy@vmi2682430:~/test$ echo pre{C..K}post
preCpost preDpost preEpost preFpost preGpost preHpost preIpost preJpost preKpost
deploy@vmi2682430:~/test$ echo pre{5..9}post
pre5post pre6post pre7post pre8post pre9post
deploy@vmi2682430:~/test$

commands summary

ls
find /var/log -name "*.log"
du -sh *
df -h
And redirection:
command > out.txt
command >> out.txt
command 2>&1