Commands using unset (14)

  • this will cause any commands that you have executed in the current shell session to not be written in your bash_history file upon logout


    18
    unset HISTFILE
    grokskookum · 2009-05-20 14:46:18 19
  • Unset TMOUT or set it to 0 in order to prevent shell autologout. TMOUT is the number of seconds after which the present shell will be killed if it has been idle for that long.


    7
    unset TMOUT
    sharfah · 2009-05-20 14:57:50 12
  • Unsetting HISTFILE avoid getting current session history list saved.


    6
    unset HISTFILE
    Delian · 2010-11-15 09:16:11 7
  • works on all unices. Show Sample Output


    4
    function nowrap { export COLS=`tput cols` ; cut -c-$COLS ; unset COLS ; }
    mobidyc · 2009-09-11 15:07:00 13
  • 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
  • First argument: string to put a box around. Second argument: character to use for box (default is '=') Same as command #4962, cleaned up, shortened, and more efficient. Now a ' * ' can be used as the box character, and the variables get unset so they don't mess with anything else you might have. They marked c++ as a function for this command, but I'm not sure why. Must be a bug. Show Sample Output


    2
    box(){ c=${2-=}; l=$c$c${1//?/$c}$c$c; echo -e "$l\n$c $1 $c\n$l"; unset c l;}
    mightybs · 2010-02-26 17:14:52 3
  • pushd and popd are your friends, but sometimes they're just incompatible with the way one works... Two shell functions: bm bookmarkname - "bookmarks" the current directory, just 'cd $BMbookmarkname' to return to it. forget bookmarkname - unsets the 'bookmarkname' variable. It isn't mandatory, they cease to exist when the session ends. Show Sample Output


    2
    bm() { export BM${1?"bookmark name missing"}="$PWD" ; }; forget() { unset BM${1?"bookmark name missing"} ; }
    unefunge · 2010-11-19 12:15:11 12

  • 1
    MYSQL="mysql -h HOST -u USERNAME -pPASSWORD -D DB_NAME" ; $MYSQL -BNe "show tables" | awk '{print "set foreign_key_checks=0; drop table `" $1 "`;"}' | $MYSQL unset MYSQL
    gadget00 · 2009-12-01 17:42:38 7
  • make, find and a lot of other programs can take a lot of time. And can do not. Supppose you write a long, complicated command and wonder if it will be done in 3 seconds or 20 minutes. Just add "R" (without quotes) suffix to it and you can do other things: zsh will inform you when you can see the results. You can replace zenity with other X Window dialogs program.


    1
    alias -g R=' &; jobs | tail -1 | read A0 A1 A2 cmd; echo "running $cmd"; fg "$cmd"; zenity --info --text "$cmd done"; unset A0 A1 A2 cmd'
    pipeliner · 2010-12-13 17:44:36 2

  • 1
    echo 'set term dumb; unset border; unset xtics; unset ytics; p "< seq 10 | shuf" u 1:(rand(0)) w l notitle' | gnuplot
    kev · 2011-11-30 02:08:53 4

  • 1
    unset HISTFILE
    aysadk · 2017-09-01 09:12:11 19
  • unsets variables used by the one-liner sets up the IFS bash variable to not be affected by whitespace and disables extra glob expansion uses read to slurp the results of the find command into an array selects an element of the array at random to be passed as an argument to mplayer


    0
    unset files i; set -f; O=$IFS; while IFS= read -r -d $'\0' files[i++]; do :; done < <(find . -name '*.avi' -print0) && IFS=$O; set +f && echo "Running: mplayer \"${files[ $(( $RANDOM % ${#files[@]} )) ]}\""
    DEinspanjer · 2009-02-18 16:53:57 5
  • If I type 'man something', I want it to find the manpage in the same order as my PATH. You can add something like this to your .bashrc # # Add my MacPorts, my personal utilities and my company utilities to my PATH. export PATH=$PATH:/opt/local/bin:$HOME/bin:/our_company_utils/bin/ # Now set the manpath based on the PATH, after man(1) parses man.conf # - No need to modify man.conf or manually modify MANPATH_MAP # - Works on Linux, FreeBSD & Darwin, unlike /etc/manpaths.d/ # Must unset MANPATH first. MANPATH is set on some systems automatically (Mac), # which causes manpath to ignore the values of PATH like /opt/local/bin (MacPorts). # Also MANPATH may be deprecated. See "SEARCH PATH FOR MANUAL PAGES" in man(1) unset MANPATH # manpath acts differently on Solaris, FreeBSD, MacOSX & GNU. This works everywhere. manpath >/dev/null # Note that MacOSX, FreeBSD & Linux have fancier ways to do some of this. (e.g. 'man --path' or 'man -q'), but this command is more universal and should work everywhere. Show Sample Output


    0
    unset MANPATH; manpath >/dev/null
    StefanLasiewski · 2010-07-02 19:45:27 3
  • The given file may contain any kind of characters. This is compatible for most simple mathematical operation. For the first number found, it will be replaced by the result of a factor operation of 1000. To change the filename or multiplactor or number regular expression, change the first fixed values. Show Sample Output


    0
    n=1000;f="test.csv";r='([0-9]+.{0,1}[0-9]*)';echo -n "" > new_${f};cat $f | while read l;do val=`echo $l | egrep -o $r` ; if [ ! -z $val ];then newval=`echo $val \* $n | bc -l`;l=`echo $l | sed "s/$val/$newval/"`;fi;echo $l >> new_${f};unset val;done
    s333 · 2017-04-26 18:04:07 19

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

Happy Days
AFAIR this is the wording ;)

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

Visit wikileaks.com
Who needs a DNS server

resume other user's screen session via su, without pty error
Normally, if you su to another user from root and try to resume that other user's screen session, you will get an error like "Cannot open your terminal '/dev/pts/0' - please check." This is because the other user doesn't have permission for root's pty. You can get around this by running a "script" session as the new user, before trying to resume the screen session. Note you will have to execute each of the three commands separately, not all on the same line as shown here. Credit: I found this at http://www.hjackson.org/blog/archives/2008/11/29/cannot-open-your-terminal-dev-pts-please-check.

Place the NUM-th argument of the most recent command on the shell
After executing a command with multiple arguments like cp ./temp/test.sh ~/prog/ifdown.sh you can paste any argument of the previous command to the console, like ls -l ALT+1+. is equivalent to ls -l ./temp/test.sh ALT+0+. stands for command itself ('ls' in this case) Simple ALT+. cycles through last arguments of previous commands.

Get your external IP address without curl
Curl is not installed by default on many common distros anymore. wget always is :) $ wget -qO- ifconfig.me/ip

Null a file with sudo

power off system in X hours form the current time, here X=2

list block level layout

awk date convert
Convert readable date/time with `date` command


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: