Merge pull request #130 from terminalforlife/master
New File, New Examples, and Some Code/Comment Tweakspull/132/head
commit
dd8d8307e5
@ -0,0 +1,5 @@
|
||||
# cdparanoia
|
||||
# Audio-extraction tool for sampling CDs
|
||||
|
||||
# Rip tracks 1-20 from an audio CD in the provided device.
|
||||
cdparanoia -B 1-20 -d /dev/sr1
|
@ -0,0 +1,29 @@
|
||||
# read (The Bash Built-in)
|
||||
# Read a line from the standard input and split it into fields
|
||||
|
||||
# Standard approach to prompting the user for a single-character response, such
|
||||
# as a simple 'Y' or 'N' response. Using Bash's `read`, you can save time and
|
||||
# lines by having the prompt taken care of by `read` itself.
|
||||
#
|
||||
# The use of the `-e` flag tells read to return a new line afterwards. As the
|
||||
# `help read` output says:
|
||||
#
|
||||
# use Readline to obtain the line in an interactive shell
|
||||
#
|
||||
# Because we're using the `-n 1` flag and argument, we'll want `-e`, as the
|
||||
# user will not get a chance to press the Enter or Return key which would
|
||||
# otherwise give us that new line.
|
||||
read -n 1 -e -p 'Prompt: '
|
||||
|
||||
# A while read loop in Bash is easily one of the best features, when properly
|
||||
# utilized; it often makes the use of tools like grep(1), sed(1), and even
|
||||
# awk(1) redundant, depending on the functionality required. This can offer
|
||||
# more efficiency, depending on what's needed and the amount of data to parse.
|
||||
#
|
||||
# In this example, the [I]nput [F]ield [S]eperator is set to `=` for only the
|
||||
# `read` built-in, and the `-a` flag is used to split the input, per the
|
||||
# provided IFS, into an array. This then means the first index is the key and
|
||||
# the second index the value, which is ideal when parsing configurtion files.
|
||||
while IFS='=' read -a Line; do
|
||||
COMMANDS
|
||||
done < INPUT_FILE
|
@ -1,20 +1,34 @@
|
||||
# udisksctl
|
||||
# The udisks command line tool
|
||||
|
||||
# Output low-level information for the provided block device and partition.
|
||||
udisksctl info -b /dev/sdd1
|
||||
|
||||
# Mount partition on the given block device. This will by default use '/media', and
|
||||
# on typical systems won't even require root privileges.
|
||||
# Mount partition on the given block device. This will by default use
|
||||
# '/media', and on typical systems won't even require root privileges.
|
||||
udisksctl mount -b /dev/sd??
|
||||
|
||||
# Set up a loop device using 'imagefile'. This only sets it up, so you will
|
||||
# probably also want to mount it thereafter, using the device given to you after
|
||||
# executing this command. often, if not always, this is '/dev/loopX', where X is
|
||||
# the loop device number.
|
||||
# probably also want to mount it thereafter, using the device given to you
|
||||
# after executing this command. often, if not always, this is '/dev/loopX', -
|
||||
# where X is the loop device number.
|
||||
udisksctl loop-setup -f image file
|
||||
|
||||
# Like the above, except this will delete the loop device (assuming 'loop0' was
|
||||
# previously created) but note that this will NOT delete the image file. Be sure to
|
||||
# unmount the filesystem(s) on the device first, before deleting it.
|
||||
# previously created) but note that this will NOT delete the image file. Be
|
||||
# sure to unmount the filesystem(s) on the device first, before deleting it.
|
||||
udisksctl loop-delete -b /dev/loop0
|
||||
|
||||
# Power off a block device. May not work for all devices, and may vary in effect.
|
||||
# Power off block device. May not work for all devices, and may vary in effect.
|
||||
udisksctl power-off -b /dev/sdb
|
||||
|
||||
# Example of a suitable mount request for auto-mounting at startup. Useful if
|
||||
# fstab isn't playing nice. This also demonstrates using `mount`-style options.
|
||||
udisksctl mount --no-user-interaction --options noatime -b /dev/sde1
|
||||
|
||||
# In some distributions of Linux, such as an Ubuntu 18.04 base install, will
|
||||
# not have its policies set to allow regular users to mount filesystems with
|
||||
# udisksctl(1) without root access, despite that being the point of this tool.
|
||||
# This can be resolved by updating the policies to this effect. In Ubuntu 18.04
|
||||
# it's as easy as a simple package installation procedure.
|
||||
sudo apt-get install policykit-desktop-privileges
|
||||
|
@ -1,26 +1,32 @@
|
||||
# Find all file names ending with .pdf and remove them
|
||||
# xargs
|
||||
# Build and execute command lines from standard input
|
||||
|
||||
# Find all file names ending with .pdf, then remove them.
|
||||
find -name \*.pdf | xargs rm
|
||||
# The above, however, is preferable written without xargs:
|
||||
# The above, however, is better-written without xargs:
|
||||
find -name \*.pdf -exec rm {} \+
|
||||
# Or, for find's own functionality, it's best as:
|
||||
# Although it's best to use find's own functionality, in this situation.
|
||||
find -name \*.pdf -delete
|
||||
|
||||
# Find all file name ending with .pdf and remove them
|
||||
# (bulletproof version: handles filenames with \n and skips *.pdf directories)
|
||||
# -r = --no-run-if-empty
|
||||
# -n10 = group by 10 files
|
||||
find -name \*.pdf -type f -print0 | xargs -0rn10 rm
|
||||
# Find all file names ending with '.pdf' and remove them. This approach also
|
||||
# handles filenames with '\n' and skips '*.pdf' directories. The xargs(1) flag
|
||||
# `-r` is equivalent to `--no-run-if-empty`, and the use of `-n` will in this
|
||||
# case group execution by 10 files.
|
||||
find -name \*.pdf -type f -print0 | xargs -0 -r -n 10 rm
|
||||
|
||||
# If file name contains spaces you should use this instead
|
||||
find -name \*.pdf | xargs -I{} rm -rf '{}'
|
||||
# If file names may contains spaces, you can use the xargs(1) flag `-I` and its
|
||||
# proceeding argument to specify the filename placeholder, as in find(1)'s use
|
||||
# of `{}` in `-exec`. Although find(1)'s `{}` needs not be cuddled by quotes, -
|
||||
# xargs(1) does.
|
||||
find -name \*.pdf | xargs -I {} rm -r '{}'
|
||||
|
||||
# Will show every .pdf like:
|
||||
# &toto.pdf=
|
||||
# &titi.pdf=
|
||||
# -n1 => One file by one file. ( -n2 => 2 files by 2 files )
|
||||
find -name \*.pdf | xargs -I{} -n1 echo '&{}='
|
||||
# The above is, however, much faster and easier without xargs:
|
||||
find -name \*.pdf -printf "%p\n"
|
||||
# Print a list of files in the format of `*FILE=`. The use of xargs(1) flag
|
||||
# `-n` here with its argument of `1` means to process the files one-by-one.
|
||||
find -name \*.pdf | xargs -I {} -n 1 echo '&{}='
|
||||
# The above is, however, much faster, more efficient, and easier without xargs.
|
||||
find -name \*.pdf -printf '&%f=\n'
|
||||
|
||||
# Group words by three in a string
|
||||
seq 1 10 | xargs -n3
|
||||
# Group words by three in a string.
|
||||
seq 1 10 | xargs -n 3
|
||||
# Alternatively, and more efficiently, use Bash brace expansion, if available.
|
||||
printf '%d ' {1..10} | xargs -n 3
|
||||
|
Loading…
Reference in New Issue