Merge pull request #120 from terminalforlife/master

Add New Files & Examples
pull/121/head
Igor Chubin 4 years ago committed by GitHub
commit 4f947347a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -380,7 +380,7 @@ perl -ne 'push @a, $_; @a = @a[@a-10..$#a]; END { print @a }'
perl -ne '/regex/ && print'
# Print only lines that do not match a regular expression
perl -ne '!/regex/ && print'
perl -ne '/regex/ || print'
# Print the line before a line that matches a regular expression
perl -ne '/regex/ && $last && print $last; $last = $_'

@ -38,7 +38,7 @@ echo ${PIPESTATUS[0]} # replace 0 with N
( set -o noclobber; echo > my.lock ) || echo 'Failed to create lock file'
# Fork bomb. Do not run this! Has the potential to wreak havoc. It repeatedly
# and quickly spawns a bazillion processes until the system eventually locks up.
# and quickly spawns a lot of processes until the system eventually locks up.
:(){ :|:& };:
# An alternative, easier-to-understand version without the obfuscation:
func(){ func | func & }; func
@ -47,8 +47,8 @@ func(){ func | func & }; func
#
# DANGER! Don't execute!
#
# Luckily, most modern setups have `--preserve-root` on by default, so this will be
# null and void, but even so, not even remotely worth the risk!
# Luckily, most modern setups have `--preserve-root` on by default, so this
# will be null and void, but even so, not even remotely worth the risk!
[ $[ $RANDOM % 6 ] == 0 ] && rm -rf /* || echo Click #Roulette
# A for loop one-liner.
@ -64,19 +64,20 @@ fi
# Test for a `PATH` executable existing as a file, but note that aliases and
# functions will also output and result in a `0` exit status.
command -v ${program} >/dev/null 2>&1 || error "${program} not installed"
# However, that is a solution commonly found in a script using the Bourne shell, so
# in this case, an alternative, Bash-like, and more accurate version could be:
# However, that is a solution commonly found in a script using the Bourne
# shell, so in this case, an alternative, Bash-like, and more accurate version
# could be:
if ! type -fP bash > /dev/null 2>&1; then
printf "ERROR: Dependency 'bash' not met." >&2
exit 1
fi
# Send both STDOUT and STDERR from COMMAND to FILE. The `2>&1` must go at the end.
# Send both STDOUT and STDERR from COMMAND to FILE.
COMMAND > FILE 2>&1
# Send STDOUT and STDERR from COMMAND to `/dev/null`, where data goes to die.
COMMAND > /dev/null 2>&1
# Pipe the STDOUT and STDERR from COMMAND_1 to COMMAND_2.
COMMAND_1 |& COMMAND_2
# Verbosely convert whitespaces (` `) to underscores (`_`) in the names of files.
# Verbosely convert whitespaces (` `) to underscores (`_`) in file names.
for name in *\ *; do mv -vn "$name" "${name// /_}"; done

@ -0,0 +1,32 @@
# links2
# Lynx-like alternative character mode WWW browser
# Note that some distributions of Linux package links2(1) as simply `links`.
# Launch and browse immediately to the provided web address.
links2 duckduckgo.co.uk
# Dump the formatted result (not source) of a given page to STDOUT.
links2 -dump duckduckgo.co.uk
# When the `-dump` option is used, the user can also provide the `-width`
# option, in order to specify the desired maximum line length, in characters.
links2 -dump -width 80 duckduckgo.co.uk
# Spoof the UA (UserAgent) which can help you visit various sites which might
# restrict access from a non-standard browser, such as Firefox. In this case, -
# we're faking a Mozilla Firefox 5.0 browser.
links2 -http.fake-user-agent 'Mozilla/5.0' duckduckgo.co.uk
# Have links2(1) request not to be tracked (as if anyone respects this!?). The
# `1` is a boolean integer, indicating to enable the aforetyped option. This
# option is by default disabled, according the August 2006 man page.
links2 -http.do-not-track 1 duckduckgo.co.uk
# Perhaps one of the most useful flags links2(1) supports enables numbered
# links, allowing the user to simply type in the number followed by Enter or
# Return, allowing for easier and quicker browsing.
links2 -html-numbered-links 1 duckduckgo.co.uk
# A Shell function which can be used to quickly access and search with DDG. For
# example, the user might wish to learn about Perl, so enter: l2 Perl
l2(){ links2 http://duckduckgo.com/?q="$*"; }

@ -0,0 +1,15 @@
# scp
# Secure copy (remote file copy program)
# Secury copies files from remote ADDR's APTH to the current-working-directory.
# By default here, port 22 is used, or whichever port is otherwise configured.
scp ADDR:PATH ./
# Using aliases (not Bash aliases) work with scp(1) as well. In this example, -
# the PATH1 of the first remote source defined as ALIAS1 is sent to PATH2 of
# the remote destination defined as ALIAS2.
scp ALIAS1:PATH1 ALIAS2:PATH2
# You can use the `-P` flag -- uppercase, unlike ssh(1) -- to determine the
# PORT, in-case it's non-standard (not 22) or not defined within an alias.
scp -P PORT ADDR:PATH ./

@ -0,0 +1,13 @@
# sensors
# Print sensors information
# By default, if possible, sensors(1) will provide temperature information in
# Celsius. Using the `-f` option, Fahrenheit can instead be used.
sensors -f
# Display sensor information in raw output, suitable for parsing.
sensors -u
# Using sensors(1) and Perl, output only the CPU's fan speed (RPM). May not
# work on all system's software and/or hardcore configurations.
sensors | perl -ne '/^cpu_fan/ && print((split(" "))[1])'
Loading…
Cancel
Save