Last active
September 28, 2017 19:50
-
-
Save DavidPesticcio/559d8ef6ad5298319bf548e8d9a0060b to your computer and use it in GitHub Desktop.
Linux: Tips & Tricks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Find all files between a start-date, and an end-date: | |
( touch -t $(date --date='6 months ago' +%Y%m%d"0000") /tmp/start && touch -t $(date --date='5 months ago' +%Y%m%d"0000") /tmp/stop ) && find . -newer /tmp/start \! -newer /tmp/stop -exec ls -l {} \; | less | |
Some Bash variables tricks: | |
$ set quick brown fox jumps | |
$ echo ${*: -1:1} # last argument | |
jumps | |
$ echo ${*: -1} # or simply | |
jumps | |
$ echo ${*: -2:1} # next to last | |
fox | |
# Variable expansion. | |
# TL;DR Loop through a list of variable names, expanding their contents into another variable. | |
# Use variables to hold stuff - like SQL queries etc, use a for loop to go through the list of variables | |
# extracting their content into another variable, or use the result directly. | |
var1="blah blah" | |
var2="foo bar" | |
varnames="var1 var2" | |
for var in $varnames | |
do | |
# Extract the contents of the variable in the list in varnames | |
contents="$(eval echo \$$var)" | |
echo "var \$contents now contains the value held in \$$var" | |
echo "\$var = $var" | |
echo "\$contents = $contents" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment