Commands by Xk2c (10)


  • 2
    bashrc-reload() { builtin exec bash ; }
    Xk2c · 2016-04-30 10:37:38 11

  • 9
    command systemctl --no-page --no-legend --plain -t service --state=running
    Xk2c · 2016-04-30 10:35:05 18
  • some people on the net already use a cd(), but most of them break 'cd -' functionality, that is "go back where you have been previosly", or 'cd' which is "go back home". This cd() copes with that. Also when given a file name, go to the directory where this file is in. cd() { if [[ -n ${*} ]] then if [[ s${*}e == s-e ]] then builtin cd - elif [[ ! -d ${*} ]] then builtin cd "${*%/*}" else builtin cd "${*}" fi else builtin cd ~ fi ls -la }


    -6
    cd(), do a ls (or whatever you can imagine) after a cd, func to long please refer to description
    Xk2c · 2015-01-01 20:50:19 9
  • many have aliases like: alias ...="cd ../../" alias ....="cd ../../../" and so furth. ..() mitigates to need for those aliases, see sample output for an example # .. -> go up 1 directory # .. 4 -> go up 4 directories ..() { local DIR='' declare -i NUM=0 if [[ ${1} =~ ^[1-9][0-9]*$ ]] then while (( ${NUM} < ${1:-1} )) do DIR="${DIR}../" NUM=$(( ${NUM} + 1 )) done else DIR=.. fi cd "${DIR}" } Show Sample Output


    -4
    [ ~/temp/foo/bar/baz ] $ .. 3
    Xk2c · 2015-01-01 20:41:17 10
  • Thanks to the great grml team for this func! You really should look at their shell configs for further usefull things! http://git.grml.org/?p=grml-etc-core.git;a=blob_plain;f=etc/grml/script-functions;h=4d6bcea8f9beae83abd08f44155d299ea54a4a9f;hb=HEAD # {{{ check for availability of program(s) # usage example: # check4progs [-s,-q,--quiet,--silent] arg [arg .... argn] # # with option given either of: # -s,-q,--quiet,--silent # # check for available progs but produce no output check4progs() { [ -n "${ZSH_VERSION}" ] && emulate -L sh local RTN=0 local oldifs="${IFS}" local ARG d found local VERBOSE=1 case ${1} in -q | -s | --quiet | --silent) VERBOSE=0 shift 1 ;; *) ;; esac while [ $# -gt 0 ] do ARG="$1" shift found=0 IFS=: for d in $PATH do if [ -x "${d}/${ARG}" ] then found=1 break fi done IFS="${oldifs}" # check for availability if [ ${found} -eq 0 ] then if [ ${VERBOSE} -eq 1 ] then printf "%s: binary not found\n" "${ARG}" >&2 fi RTN=1 fi done # return non zero, if at least one prog is missing! return $RTN } # }}} Show Sample Output


    -6
    $ if check4progs cp foo mv bar rsync; then echo "needed progs avail, lets do funky stuff"; else echo "oh oh better abort now"; fi
    Xk2c · 2015-01-01 16:16:00 8
  • shopt-set() { declare -i RTN=0 local ARG='' while (( ${#} > 0 )) do ARG="${1}" shift 1 if ! builtin shopt -s "${ARG}" 1>/dev/null 2>&1 then RTN=1 fi done return ${RTN} } Show Sample Output


    -6
    shopt-set() ... func to long, please refer to description
    Xk2c · 2015-01-01 03:20:52 10
  • Actually your func will find both files and directorys that contain ${1}. This one only find files. ..and to look only for dirs: finddir() { find . -type d -iname "*${*}*" ; }


    -4
    findfile() { find . -type f -iname "*${*}*" ; }
    Xk2c · 2015-01-01 03:15:51 8
  • David thanks for that grep inside! here is mine version: psgrep() { case ${1} in ( -E | -e ) local EXTENDED_REGEXP=1 shift 1 ;; *) local EXTENDED_REGEXP=0 ;; esac if [[ -z ${*} ]] then echo "psgrep - grep for process(es) by keyword" >&2 echo "Usage: psgrep [-E|-e] ... " >&2 echo "" >&2 echo "option [-E|-e] enables full extended regexp support" >&2 echo "without [-E|-e] plain strings are looked for" >&2 return 1 fi \ps -eo 'user,pid,pcpu,command' w | head -n1 local ARG='' if (( ${EXTENDED_REGEXP} == 0 )) then while (( ${#} > 0 )) do ARG="${1}" shift 1 local STRING=${ARG} local LENGTH=$(expr length ${STRING}) local FIRSCHAR=$(echo $(expr substr ${STRING} 1 1)) local REST=$(echo $(expr substr ${STRING} 2 ${LENGTH})) \ps -eo 'user,pid,pcpu,command' w | grep "[${FIRSCHAR}]${REST}" done else \ps -eo 'user,pid,pcpu,command' w | grep -iE "(${*})" fi }


    -10
    psgrep() ... func to long, please look under "description"
    Xk2c · 2015-01-01 02:58:48 8
  • hgrep() { if [[ ${#} -eq 0 ]] then printf "usage:\nhgrep [--nonum | -N | -n | --all-nonum | -an | -na] STRING\n" return 1 fi while [[ ${#} -gt 0 ]] do case ${1} in --nonum | -N | -n | --all-nonum | -an | -na) builtin history | sed 's/^[[:blank:]]\+[[:digit:]]\{1,5\}[[:blank:]]\{2\}//' | grep -iE "(${*:2})" break ;; *) builtin history | grep -iE "(${*})" break ;; esac done } 'hgrep -n' helps in using full grep support, e.g. search for _beginning_ of specific commands, see example output Show Sample Output


    -1
    hgrep() { ... } longer then 255 characters, see below
    Xk2c · 2014-04-02 16:40:36 10
  • Simply sourcing .bashrc does not function correctly when you edit it and change an alias for a function or the other way round with the *same name*. I therefor use this function. Prior to re-sourcing .bashrc it unsets all aliases and functions.


    4
    bashrc-reload() { builtin unalias -a; builtin unset -f $(builtin declare -F | sed 's/^.*declare[[:blank:]]\+-f[[:blank:]]\+//'); . ~/.bashrc; }
    Xk2c · 2014-03-02 14:24:18 9

What's this?

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.

Share Your Commands


Check These Out

Quickly re-execute a recent command in bash
! will expand to the last time you ran , options and all. It's a nicer alternative to ^R for simple cases, and it's quite helpful for those long commands you run every now and then and haven't made aliases or functions for. It's similar to command 3966, in some sense.

Look for English words in /dev/urandom
* to get the English dictionary: wget http://www.mavi1.org/web_security/wordlists/webster-dictionary.txt

HTTP GET request on wireshark remotly

Find out if a module is installed in perl
Shows the path if the module is installed or exit quietly (to simply avoid the 'No documentation found' msg).

diff the same file in two directories.
This is useful when you're diffing two files of the same name in radically different directory trees. For example: Set $ path1='/some/long/convoluted/path/to/all/of/your/source/from/a/long/dead/machine' then $ path2='/local/version/of/same/file' then run the command. Much easier on the eyes when you're looking back across your command history, especially if you're doing the same diff over and over again.

connects to db2 database instance/alias "stgndv2" user "pmserver" using password "xxxxxxx"
db2 => ? connect CONNECT [USER username [{USING password [NEW new-password CONFIRM confirm-password] | CHANGE PASSWORD}]] CONNECT RESET CONNECT TO database-alias [IN {SHARE MODE | EXCLUSIVE MODE [ON SINGLE DBPARTITIONNUM]}] [USER username [{USING password [NEW new-password CONFIRM confirm-password] | CHANGE PASSWORD}]]

blktrace - generate traces of the i/o traffic on block devices
blktrace is a block layer IO tracing mechanism which provide detailed information about request queue operations up to user space. blkparse will combine streams of events for various devices on various CPUs, and produce a formatted output the the event information. It take the output of above tool blktrace and convert those information into fency readable form.

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

Multiple variable assignments from command output in BASH
No command substitution but subshell redirection

files and directories in the last 1 hour
added alias in ~/.bashrc alias lf='find ./* -ctime -1 | xargs ls -ltr --color'


Stay in the loop…

Follow the Tweets.

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

Subscribe to the feeds.

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: