remove all files do not match given extensions from a folder
1
rm !(*.foo|*.bar|*.baz)
create a script of the last command
1
echo "!!" > last.sh
reuse last command
12345678910
# all parameters!*# last parameters!$# nth parameters!:n# reuse but replace the matched part with new string, usually to correct the typo^foo^boo# the last command without arguments!:-
Backticks (``) are evil
1234567
echo "The date is: $(date +%D)"# This is a simple example of using proper command nesting using $() over ``. There are a number of advantages of $() over backticks. First, they can be easily nested without escapes:program1 $(program2 $(program3 $(program4)))#versusprogram1 `program2 \`program3 \`program4\`\``# Second, they're easier to read, then trying to decipher the difference between the backtick and the singlequote: `'. The only drawback $() suffers from is lack of total portability. If your script must be portable to the archaic Bourne shell, or old versions of the C-shell or Korn shell, then backticks are appropriate, otherwise, we should all get into the habit of $(). Your future script maintainers will thank you for producing cleaner code.
Display a block of text with matched range
1
awk '/start_pattern/,/stop_pattern/' file.txt
remove duplicate entries without sorting
12
awk '!x[$0]++' fileawk '!x[$1]++' file
Find Duplicate Files (based on size first, then MD5 hash)