Test file system type before further commands execution

DIR=. ; FSTYPE=$(df -TP ${DIR} | grep -v Type | awk '{ print $2 }') ; echo "${FSTYPE}"
Exclude 400 client hosts with NFS auto-mounted home directories. Easily modified for inclusion in your scripts.
Sample Output
DIR=. ; FSTYPE=$(df -TP ${DIR} | grep -v Type | awk '{ print $2 }') ; echo "${FSTYPE}"
ext3

1
By: unixhome
2009-12-22 14:01:50

These Might Interest You

  • You can use this in shell scripts to show which commands are actually run. Just prepend every "critical line" with "v˽". $TMP=/tmp echo "Let me create a directory for you" v mkdir $TMP/new In scripts this can be more useful than "set -x", because that can be very verbose with variable assignments etc. Another nice use is if you prepend every "critical" command with "v", then you can test your script by commenting out the actual execution. Show Sample Output


    -3
    v () { echo "$@"; "$@"; }
    hfs · 2011-10-13 11:33:19 1
  • I am using .bat commands to execute Curl commands for Twitter API Show Sample Output


    -34
    test.bat parm1 parm2 parm3
    lansa · 2009-03-25 12:27:18 3
  • Applies each file operator using the built-in test. testt /home/askapache/.sq /home/askapache/.sq -a True - file exists. -d True - file is a directory. -e True - file exists. -r True - file is readable by you. -s True - file exists and is not empty. -w True - the file is writable by you. -x True - the file is executable by you. -O True - the file is effectively owned by you. -G True - the file is effectively owned by your group. -N True - the file has been modified since it was last read. Full Function: testt () { local dp; until [ -z "${1:-}" ]; do dp="$1"; [[ ! -a "$1" ]] && dp="$PWD/$dp"; command ls -w $((${COLUMNS:-80}-20)) -lA --color=tty -d "$dp"; [[ -d "$dp" ]] && find "$dp" -mount -depth -wholename "$dp" -printf '%.5m %10M %#15s %#9u %-9g %#5U %-5G %Am/%Ad/%AY %Cm/%Cd/%CY %Tm/%Td/%TY [%Y] %p\n' -a -quit 2> /dev/null; for f in a b c d e f g h L k p r s S t u w x O G N; do test -$f "$dp" && help test | sed "/-$f F/!d" | sed -e 's#^[\t ]*-\([a-zA-Z]\{1\}\) F[A-Z]*[\t ]* True if#-\1 "'$dp'" #g'; done; shift; done } Show Sample Output


    2
    testt(){ o=abcdefghLkprsStuwxOGN;echo $@;for((i=0;i<${#o};i++));do c=${o:$i:1};test -$c $1 && help test | sed "/^ *-$c/!d;1q;s/^[^T]*/-$c /;s/ if/ -/";done; }
    AskApache · 2012-02-21 16:54:53 2
  • vix /tmp/script.sh Open a file directly with execution permission. Put the function in your .bashrc You can also put this in your vimrc: command XX w | set ar | silent exe "!chmod +x %" | redraw! and open a new file like this: vi +XX /tmp/script.sh


    2
    vix(){ vim +'w | set ar | silent exe "!chmod +x %" | redraw!' $@; }
    dooblem · 2010-05-27 21:12:48 3

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

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



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: