diff --git a/sheets/convert b/sheets/convert index 4342c05..57bdd9e 100644 --- a/sheets/convert +++ b/sheets/convert @@ -1,24 +1,21 @@ -# To resize an image to a fixed width and proportional height: +# Resize an image to a fixed width and proportional height: convert original-image.jpg -resize 100x converted-image.jpg -# To resize an image to a fixed height and proportional width: +# Resize an image to a fixed height and proportional width: convert original-image.jpg -resize x100 converted-image.jpg -# To resize an image to a fixed width and height: +# Resize an image to a fixed width and height: convert original-image.jpg -resize 100x100 converted-image.jpg -# To resize an image and simultaneously change its file type: +# Resize an image and simultaneously change its file type: convert original-image.jpg -resize 100x converted-image.png -# To resize all of the images within a directory: -# To implement a for loop: -for file in `ls original/image/path/`; - do new_path=${file%.*}; - new_file=`basename $new_path`; - convert $file -resize 150 conerted/image/path/$new_file.png; +# Resize all of the images within a directory, using a for loop: +for file in original/image/path/*; do + convert "$file" -resize 150 converted/image/path/"$file" done -# Make text annotatation (text = Flower) +# Make text annotation (text = Flower) convert flower.jpg -font courier -fill white -pointsize 20 -annotate +50+50 'Flower' flower_annotate1.jpg # Crop an image @@ -33,3 +30,5 @@ convert -border 1x1 -bordercolor "#FFFFFF" image.png new-image.png # Convert PNG to JPEG (with 70% quality) convert -quality 70 image.png new_image.jpg +# Apply vignette and grayscale effects to all JPGs in the CWD, using a for loop. +for FILE in *.jpg; { convert -background black -colorspace gray -vignette 200x100 "$FILE" "$FILE"; } diff --git a/sheets/find b/sheets/find index abe454d..81e089f 100644 --- a/sheets/find +++ b/sheets/find @@ -56,3 +56,6 @@ find . -type f -iname '*.png' -exec bash -c 'mv "$0" "${0%.*}.jpg"' {} \; # Use logic and grouping to delete extension-specific files. find \( -iname "*.jpg" -or -iname "*.sfv" -or -iname "*.xspf" \) -type f -delete + +# List all executable files, by basename, found within PATH. +find ${PATH//:/ } -type f -executable -printf "%P\n" diff --git a/sheets/nl b/sheets/nl new file mode 100644 index 0000000..b82cd57 --- /dev/null +++ b/sheets/nl @@ -0,0 +1,7 @@ +# Number lines given to `nl` via STDIN. +printf "Here\nis\nsome\nexample\ntext." | nl + +# Number (all) lines given to `nl` via provided file(s). +nl -b a /path/to/file +# The above can also be achieved with `cat`, which is perhaps more portable: +cat -n /path/to/file diff --git a/sheets/sed b/sheets/sed new file mode 100644 index 0000000..3ebd5a4 --- /dev/null +++ b/sheets/sed @@ -0,0 +1,2 @@ +# Edit a file, via substitution, in-place; changes are made to the file(s). +sudo sed -i 's/Name=Xfce Session/Name=Xfce_Session/' /usr/share/xsessions/xfce.desktop diff --git a/sheets/xargs b/sheets/xargs index b9571f0..f329873 100644 --- a/sheets/xargs +++ b/sheets/xargs @@ -1,13 +1,17 @@ -# find all file name ending with .pdf and remove them +# Find all file names ending with .pdf and remove them find -name \*.pdf | xargs rm +# The above, however, is preferable written without xargs: +find -name \*.pdf -exec rm {} \+ +# Or, for find's own functionality, it's best as: +find -name \*.pdf -delete -# find all file name ending with .pdf and remove them +# 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 -# if file name contains spaces you should use this instead +# If file name contains spaces you should use this instead find -name \*.pdf | xargs -I{} rm -rf '{}' # Will show every .pdf like: @@ -15,6 +19,8 @@ find -name \*.pdf | xargs -I{} rm -rf '{}' # &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" -# group words by three in a string -seq 1 10 | xargs -n3 echo +# Group words by three in a string +seq 1 10 | xargs -n3