Showing posts with label CLI. Show all posts
Showing posts with label CLI. Show all posts

February 20, 2018

2 Ways to Linux CommandLine Thesaurus Synonyms

icon

[How to] Linux CommandLine Thesaurus | Linux CommandLine Synonyms


I wanted to use my linux commandline to lookup synonyms (thesaurus) recently but didn’t know how.

After some searching I was able to find 2 alternatives that worked very differently, yet helped me tremendously on each account.

Method 1 - DICT

sudo apt install dict dictd dict-gcide dict-moby-thesaurus
sudo systemctl enable dictd
sudo systemctl start dictd
dict --help # or try 'man dict'
#dict -d moby-thesaurus YOURWORDHERE
alias thes='dict -d moby-thesaurus'
thes engineer

Method 2 - WordNet

sudo apt install wordnet
man wn | grep -B1 synon
#wn YOURWORDHERE -syns#, where # is n, v, a, or r
#wn YOURWORDHERE -simsv
wn # or try 'man wn'
wn engineer -synsn | grep -v ^$   #grep just strips empty lines from output
wn engineer -synsv | grep -v ^$

Script for both:

#!/bin/sh
if [ "$1" = "" ] ; then
   echo "usage: $0 WORD"
fi
wn $1 -synsn | grep -v ^$
wn $1 -synsv | grep -v ^$
wn $1 -synsa | grep -v ^$
wn $1 -synsr | grep -v ^$
dict -d moby-thesaurus $1



~~
As always, good luck!

Please consider crypto tipping:
  

December 08, 2017

CLI Shell Console SublimeText Alternative

icon

I love SublimeText! With features like Ctrl-D, Multi-Cursor, and RegEx-Search&Replace, it’s just the best editor ever. Add tools from PackageControl.io and it’s unbeatable. Yes, Atom is probably on-par (plus it’s free), but I’ve already acclimated to ST and that’s just how it is.

But sometimes i just prefer/need to edit in the shell. Almost always, i use nano; However, when you suddenly need something more powerful, it’s back to SublimeText.

I had known about slap-edit, but it’s just too slow, especially through ssh tunnels.

Enter Suplemon! Wow, it’s a great CLI editor to supplement your workflow. If you already have python and pip, then just sudo pip3 install suplemon - -That’s it. Launch suplemon and check it out.

demo

Yes, I know everyone will say “Vim”, but i don’t have time be that good.

~~~

Written with StackEdit.

November 24, 2017

Basic Commandline Video Processing In Linux

video edit icon
Prerequisite: Install packages for MP4Box and ffpmpeg commands:
sudo apt install gpac ffmpeg

 

Three Methods to Trim Video:

  1. MP4Box -splitx ss:ss input.mp4 -out output.mp4 , where ss:ss are numerical values for start-seconds and stop-seconds. (Fastest, does not transcode)
  2. ffmpeg -i input.mp4 -ss hh:mm:ss -t hh:mm:ss -async 1 output.mp4, where hh:mm:ss are numerical values for hours, minutes, seconds.
  3. ffmpeg -i input.mp4 -vf trim=ss:ss output.mp4, where ss is a numerical value for seconds.
Annoyed with converting hours, minutes, seconds into total seconds? Use this bash function:
function to_sec() { echo "$1" | awk -F':' '{if (NF == 2) {print $1 * 60 + $2} else {print $1 * 60 * 60 + $2 * 60 + $3}}'; }
Usage examples: to_sec 2:47 or to_sec 1:2:47 or $(to_sec 2:47) or MP4Box -splitx $(to_sec 2:47):$(to_sec 7:33) input.mp4 -out output.mp4


 

Overlay a Logo onto Video:

    1. Static graphic logo:
ffmpeg -i input.mp4 \
-i logo.png \
-filter_complex "X:Y" \  # set logo position
-codec:a copy \  # just copy audio
output.mp4
where X:Y is the horizontal and vertical pixel positioning.
    2. Animated graphic logo:
ffmpeg -i input.mp4 \
-ignore_loop 0 -i animated-logo.gif \  # do not ignore looping
-filter_complex "X:Y:shortest=1" \  # limit to input video length
-codec:a copy \
output.mp4
where :shortest=1 is required, and where X:Y is the horizontal and vertical pixel positioning. Without shortest, the video transcoding will not end.
X and Y may be static numerical values, or ffmpeg built-in variables and equations. Examples:
  • Top right with 10 pixel margin : main_w-overlay_w-10:10
  • Top left with 10 pixel margin : 10:10
  • Bottom left with 10 pixel margin : 10:main_h-overlay_h-10
  • Bottom right with 10 pixel margin : main_w-overlay_w-10:main_h-overlay_h-10

 

 

Trim First x Seconds off Audio File:

ffmpeg -ss x -i input.mp3 -codec:a copy output.mp3 , where x is a numerical value for seconds.

 

Add Audio to Video and Trim to Shortest Source:

ffmpeg -i input.mp4 -i audio.mp3 -codec copy -shortest output.mp4

 

Overlay Logo and Add Audio with One Command:

ffmpeg -i input.mov \
 -i logo.png \
 -filter_complex "overlay=main_w-overlay_w-10:10" \
 -i music.mp3 -codec:a copy \
 -shortest output.mov
As always, good luck!
~~~
  

July 12, 2016

Erase last BASH command

enter image description here
Ever accidentally type your password on the commandline?
Want something better than editing the .bash_history file?
(Especially when you use cssh, parallel-ssh, psonsole or similar)
Below are some options:
#erase last command (least efficient)
history -d $(history | tail -n 2 | head -n 1 | awk '{print $1}')

#erase last command (more efficient)
history -d $(history | awk 'END{print $1-1}')

#erase last command and self (best)
history -d $(($HISTCMD-2)) && history -d $(($HISTCMD-1))

#ultimately add alias to .bashrc
alias eraselastcmd='history -d $(($HISTCMD-2)) && history -d $(($HISTCMD-1))'

#clear current session history
history -c

#don't save session history starting now
unset HISTFILE

#delete lines containing SOMETEXT from ~/.bash_history
 sed -i '/SOMETEXT/d' ~/.bash_history
Related options that can be set in ~/.bashrc
export HISTCONTROL=ignoreboth         # ignore duplicates and commands with " " (space-prefixed)
export HISTSIZE=                      # unlimited history
export HISTFILESIZE=                  # unlimited history
shopt -s histappend                   # append to history, don't overwrite it
export HISTIGNORE="ls:pwd:exit:date"  # do not record specified commands
-
good luck


Please consider crypto tipping: