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 search for "string" in all files under the given path "." and provide a listing of the files with their relative locations. Show Sample Output
Saves all the "cut" hacks
'booklet' is the name they'll give it in fineprint windows alternative. It's a postscript file prepared to be printed dual side, one page per sheet, and, once finished you can place staples in the middle of the print, fold, and read it like a book.
All Linux Systems I try also have an empty line per cpu in /proc/cpuinfo... little shorter then... Show Sample Output
Full output in one single git command, no pipes nor other process invocations. Will also work under cmd on Windows, with MSysGit, and can be aliased, simply add [alias] branch-rel = "for-each-ref --sort=-committerdate --format='%1B[32m%(committerdate:iso8601) %1B[34m%(committerdate:relative) %1B[0;m%(refname:short)' refs/heads/" to your .gitconfig file. Show Sample Output
Recursively list all files in the current directory & get their md5sum, even if the filename has bad characters. Show Sample Output
Edit the YOURPROJECTHERE and YOURPACKAGEHERE and you're done. This is pretty simple but every time I forget how to do it, so let's stick it here.
Requires ImageMagick to be installed; mogrify is the lesser-known sibling to convert -- it overwrites your original images, but allows you to work on batches of files without resorting to a loop.
I use this on Debian to rename files that exist in directories but do not have the year in the file name. The directory has the year but the files inside don't. How I explain how this runs: The dir variable grabs the name of the folder. Using rename, substitute the name of the first file and remove the extension, then rename it to the directory name. To test this before you run it, change -v to -vn. Show Sample Output
This assumes you have an ssh key already held with putty agent (pageant) for authentication or it will prompt for password. You can add on multiple tunnels to multiple hosts accessible by the remotehost by simply adding in further -L bindport:host:hostport. In essence plink can basically use much the same syntax as openssh. I have included -C for compression -P for ssh port 22 and -N to not create a shell and -v for verbose output Show Sample Output
Using GNU Grep with perl regexp (works on newer Ubuntus) Show Sample Output
Hides the process "your_command" from showing with ps, displaying some other random process name already running for a better camouflage. Show Sample Output
The first version printed:
tr: empty string2
The second version printed:
sed: -i may not be used with stdin
Maybe I misunderstood the orginal problem.
This is the command to configure "cobbler reposync" to use a specific proxy setting to mirror locally the content of a specific remote repository.
This mapping function is called RANDOM bash and enter a number between 1 and 100 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: