This is a bit of a bash hack to catch STDERR and append a log level to it. So for example, if your script has pseudo loglevels like so: echo "INFO - finding files" [ -f ${files} ] || echo "WARN - no files found" Any subcommands that write to STDERR will screw that up Adding 2> >(fb=$(dd bs=1 count=1 2>/dev/null | od -t o1 -A n); [ "$fb" ] && err=$(printf "\\${fb# }"; cat) && echo "ERROR - $err") to the command does the following: 2> Redirect STDERR >( Spawn a subshell (STDERR is then redirected to the file descriptor for this subshell) fb=$(....) get the first byte of input [ "$fb" ] test if there's a first byte && err=$(printf....) save the output to the $err variable && echo "ERROR - $err" append your pseudo loglevel and the error message Heavily borrowed from https://unix.stackexchange.com/questions/33049/check-if-pipe-is-empty-and-run-a-command-on-the-data-if-it-isnt Show Sample Output
This will use tput to place the command (date %T in this case) in the upper right corner of the terminal
Very useful to get rid of backup files or wrong extension files that lure in your folders In this example first I do two searches for all filenames of the two extensions .jpg and .png, then delete the extension and only output the now duplicate files. I loop with these results and print a log and delete the file with the extension I dislike. Show Sample Output
the part after sed is optional. if you want, omit the last dot(.) yourself.
I wanted to count and display the top directories containing JavaScript files in some of my project. Here it is. Maybe it can be written to more simply syntax by using find -exec...
Use yes to repeat (it will continue until the pipe breaks) https://en.wikipedia.org/wiki/Yes_(Unix) head -n5 to repeat the piped command n times. https://en.wikipedia.org/wiki/Head_(Unix) Show Sample Output
Using zsh parameter expansion Show Sample Output
Trying to check for an open port and missing netcat or nmap? This is the lowest common denominator way to verify a port is accessible from one server to another. This will give you a pretty quick return of 0 if it works. If it fails, it will just hang and takes awhile to timeout. I usually ctrl+c the command. "echo ?$" will give you an exit code other then 0 after you exit. Show Sample Output
Waits URL, then converts. Show Sample Output
Here is an alternative that support unicodes, using echo:
It is using the \c flag, meaning no new line for the echo option -e.
You can replace the = with any unicode character.
Or to do the same into a PHP bash script:
shell = system("tput cols");
for( $i= 0 ; $i < $shell ; $i++ ){ echo "█"; }
Show Sample Output
Get the total RESIDENT memory used by processes of a specific name. This means this is the MINIMUM used by a process, but some memory could be paged out to swap. Show Sample Output
Using to count all sentences in CoNLL data format
Removed grep and simplified if statement. -- Friday is the 5th day of the week, monday is the 1st. Output may be affected by locale. Show Sample Output
I couldn't find movie library on any of the SQLlite Stremio databases, but on ~/.config/stremio/backgrounds2 the background image filenames corresponds to IMDB URL. So I foreach files and wget HTML title of each movie and save it to a file. This will retrieve all movie names, not just the Library.
Pluralize a word, aka change from single to multiple; text formatting.
echo hamburgler | pluralize
Show Sample Output
Disabling Gradle daemon can sometimes improve build reliability.
example or test, basic awareness on app state, mostly for copy-paste reasons, requires auditd (ausyscall), rekt echoing (everything here is rekt) Show Sample Output
This command sent the Python version to a file. This is intended to be used in scripts. For some reason, simple redirections didn't work with "python -V" Show Sample Output
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for: