Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. 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.


Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.
Hide

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:

Hide

News

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

cd up a number of levels

Terminal - cd up a number of levels
function ..(){ for ((j=${1:-1},i=0;i<j;i++));do builtin cd ..;done;}
2010-01-02 08:36:12
User: bhepple
Functions: cd
3
cd up a number of levels

Instead of typing "cd ../../.." you can type ".. 3". For extremely lazy typists, you can add this alias:

alias ...=".. 2" ....=".. 3"

- so now you can write just .... !!!

NB the .. function needs to be "source"d or included in your startup scripts, perhaps .bashrc.

Alternatives

There is 1 alternative - vote for the best!

Terminal - Alternatives

Know a better way?

If you can do better, submit your command here.

What others think

Nice idea!

However, I'm not sure to get the reason why you use 'j=${1:-1}'. Is this parameter expansion trick useful? Is the new variable j useful? Please help me to understand :-)

Comment by Josay 406 weeks and 5 days ago

That's quite fun.

Alternatively (not equivalent but simplistically) :

alias :="cd .." alias :.="cd ../.." alias ::="cd ../../.." alias ::.="cd ../../../.."

# repeat until bored :-)

-so now you can write just :: !!! :-)

Comment by mpb 406 weeks and 5 days ago
{VAR:-VAL} means use $VAR if it's non-null, otherwise use VAL - think of it as a default.
Comment by bhepple 406 weeks and 5 days ago

I _like_ ':.' etc, what a hoot.

Comment by bhepple 406 weeks and 5 days ago

Hmmm php ate my '$' - that should have been: ${VAR:-VAL} means use $VAR if it's non-null, otherwise use VAL - think of it as a default.

Comment by bhepple 406 weeks and 5 days ago

it might help to add 'o=$PWD' and 'OLDPWD=$o' at the beginning and end in order for 'cd -' to work as expected

Comment by patrix 406 weeks and 5 days ago

..() { cd "$(seq ${1:0} | sed '/.*/s,,../,' | tr -d '\n')"; }

This way, you also keep your "cd -" working.

Comment by taliver 406 weeks and 4 days ago

Actually make that:

..() { cd "$(seq ${1:-1} | sed '/.*/s,,../,' | tr -d '\n')"; }

Comment by taliver 406 weeks and 4 days ago

Taliver - good point! I actually use a function for cd which wraps pushd so I never rely on 'cd -'. I'll try and post it here in case it's of interest:

# do ". acd-func.sh" # acd-func 1.0.5, 10-nov-2004 # petar marinov, http:/geocities.com/h2428, this is public domain # http://linuxgazette.net//109/marinov.html ..() { for (( j=${1:-1},i=0; i<j; i++)); do # cd .. always succeeds (on linux, at least) even if we're at / builtin cd .. done pwd ls -CF } alias ...=".. 2" ....=".. 3" cd_func () { local x2 THE_NEW_DIR ADIR INDEX local -i CNT if [[ $1 == "--" ]]; then dirs -v return 0 fi THE_NEW_DIR=$1 [[ -z $1 ]] && THE_NEW_DIR=$HOME if [[ ${THE_NEW_DIR:0:1} == '-' ]]; then # # Extract dir N from dirs INDEX=${THE_NEW_DIR:1} [[ -z $INDEX ]] && INDEX=1 ADIR=$(dirs +$INDEX) [[ -z $ADIR ]] && return 1 THE_NEW_DIR=$ADIR fi # # '~' has to be substituted by ${HOME} [[ ${THE_NEW_DIR:0:1} == '~' ]] && THE_NEW_DIR="${HOME}${THE_NEW_DIR:1}" # # Now change to the new dir and add to the top of the stack pushd "${THE_NEW_DIR}" > /dev/null [[ $? -ne 0 ]] && return 1 THE_NEW_DIR=$(pwd) || builtin cd ${THE_NEW_DIR} || exit $? pwd ls -CF # # Trim down everything beyond 11th entry popd -n +11 2>/dev/null 1>/dev/null # # Remove any other occurence of this dir, skipping the top of the stack CNT=1 while [ "$CNT" -lt 10 ]; do x2=$(dirs +${CNT} 2>/dev/null) [[ $? -ne 0 ]] && return 0 [[ ${x2:0:1} == '~' ]] && x2="${HOME}${x2:1}" if [[ "${x2}" == "${THE_NEW_DIR}" ]]; then popd -n +$CNT 2>/dev/null 1>/dev/null CNT=$(($CNT - 1)) fi CNT=$(($CNT + 1)) done return 0 } if [[ $BASH_VERSION > "2.05" ]]; then alias cd=cd_func # ctrl+w shows the menu # but first make sure ^w doesn't get eaten by stty werase stty werase ^- bind -x '"\C-w": cd_func -- ;' fi
Comment by bhepple 406 weeks and 4 days ago

http://www.michaelkorsoutlet.co.uk

http://www.airjordanretro.us

http://www.nikecortez.com.co

http://www.adidasnmd.org.uk

http://www.seattleseahawksjerseys.us

http://www.outletmichaelkors.us.com

http://www.louis-vuitton-handbags.us.org

http://www.christianlouboutinshoesoutlets.us.com

http://www.fitflops.org.uk

http://www.pandorajewelryoutlet.name

http://www.michael-korshandbags.me.uk

http://www.yeezyboost-350.us.com

http://www.michaelkorsoutlets.us.com

http://www.goldenstatewarriorsjerseys.us

http://www.louboutin-paschers.fr

http://www.birkenstocksandals.name

http://www.red-bottoms.us.com

http://www.coach-outletonline.us.org

http://www.outletralphlauren.us.com

http://www.coach-outlet.in.net

http://www.cheapmlbjerseyswholesale.us.com

http://www.clarksshoes.us.com

http://www.cheapmontblancpens.org

http://www.adidas-shoes.me.uk

http://www.michaelkorsoutletvip.in.net

http://www.swarovskicrystal.name

http://www.yeezyboost-350.co.uk

http://www.coachfactory-outletonlines.us.com

http://www.detroittigersjerseys.us

http://www.fendihandbags.us

http://www.fitflopssaleclearanceofficial.us.com

http://www.toms.in.net

http://www.cheaprolexreplicawatches.us

http://www.nikeshoes.us.com

http://www.dolceandgabbanaoutlet.com

http://www.nikeoutletonline.us.com

http://www.timberlandbootsoutlet.us

http://www.nike-airmax90.me.uk

http://www.michaelkorsofficial.us

http://www.cheap-jordans.us

http://www.christianlouboutinshoes.in.net

http://www.monclerjackets-uk.co.uk

http://www.edhardy-outlet.name

http://www.ralphlaurensaleclearance.me.uk

http://www.true-religionjeansoutlet.in.net

http://www.kate-spadeoutlets.us.com

http://www.nikeoutletshoes.us

http://www.longchamp-handbags.us

http://www.bostoncelticsjerseys.us

http://www.cheapnfl-jerseyswholesale.us.com

http://www.sanfranciscogiantsjerseys.us

http://www.true-religionjeans.in.net

http://www.yeezyboost.org.uk

http://www.airmax-95.us

http://www.adidas-outlet.us.com

http://www.mont-blanc.in.net

http://www.ralphlaurenoutletonlines.us.com

http://www.airmaxoutletsaleus.com

http://www.oakleyvaultsunglassesoutlet.us.com

http://www.coachoutlet.in.net

http://www.pandora-uk.me.uk

http://www.coachoutletstoreinc.us.com

http://www.pandoracharms.name

http://www.true-religionjeansoutlet.us.com

http://www.airforce1-nike.fr

http://www.pradaoutlets.us

http://www.ralph-laurenuk.co.uk

http://www.coach-outletonlines.us.com

http://www.poloralph-lauren.in.net

http://www.clarks-shoes.us

http://www.losangelesdodgersjerseys.us

http://www.louisvuittonoutletus.us.com

http://www.coachoutletstoreonline.com.co

http://www.ralph-laurenoutlet.me.uk

http://www.nike-tn-pascher.fr

http://www.burberry-outlet-canada.ca

http://www.saclongchamppas-cher.fr

http://www.christianlouboutinsale.us.org

http://www.airmax90.org

http://www.michaelkorshandbags-outlet.us.org

http://www.nikeoutlet.us.com

http://www.montblanc-pens.net.co

http://www.toryburchoutlets.us

http://www.moncleroutlet.in.net

http://www.michaelkors-handbags.us.org

http://www.christianlouboutinoutlet.us

http://www.fake-rolex.us

http://www.officialcoachoutlet.us.com

http://www.sac-longchamp-pliage.fr

http://www.katespadehandbags.org.uk

http://www.michaelkorshandbagsuk.co.uk

http://www.adidasyeezyshoes.us.com

http://www.dallas-cowboysjerseys.us

http://www.birkenstocks.us

http://www.nfljerseyscheap.in.net

http://www.michael-korsoutletonlines.us.com

http://www.ultraboost.us

http://www.louboutin-shoes.us.com

http://www.hermesbag.us.com

http://www.mulberry-bags.me.uk

http://www.outletnike.us

http://www.nikefreerun.name

http://www.cheapjordans-shoes.us.com

http://www.pandoracharms.us.com

http://www.wwwlouisvuittonoutlet.us.com

http://www.adadassuperstar.com

http://www.cheapraybans.com.co

http://www.outletlongchamp.us

http://www.ralphlauren.net.co

http://www.longchampoutletstore.com

http://www.cheapjordans.com.co

http://www.cheapmlbjerseys.us

http://www.coach-outlets.us.com

http://www.mbtshoes.org.uk

http://www.michaelkorsoutletclearance.in.net

http://www.christian-louboutin.us.com

http://www.michael-korsoutlet.ca

http://www.coachoutletsstore.us.com

http://www.cheapjordanshoes.us.com

http://www.airmax90nike.us

http://www.yeezyboost350.me.uk

http://www.coachfactoryoutletstore.in.net

http://www.raybansunglassesdiscount.com.co

http://www.katespadehandbags.us.com

http://www.monclerjacketsuk.org.uk

http://www.coachhandbagsoutlet.us.com

http://www.longchampbags.uk

http://www.coachoutlets.us.org

http://www.nikehuarache.com.co

http://www.burberrysale.in.net

http://www.chaussurelouboutin-pascher.fr

http://www.true-religion.us.com

http://www.adidastrainersuk.org.uk

http://www.moncleroutletjackets.us

http://www.houstontexansjerseys.us.com

http://www.redbottomshoes.in.net

http://www.vansshoes.in.net

http://www.pandoracharms.com.co

http://www.nike-airmax90.me.uk

http://www.burberryoutletstore.us

http://www.greenbaypackersjerseys.us.com

http://www.nikeroshe.us

http://www.ralphlauren-outletonline.us.com

http://www.ralphlaurensaleclearance.co.uk

http://www.hermesbirkin.in.net

http://www.officialmichaelkors.us.com

http://www.todsoutlet.us

http://www.cheapjerseys.eu.com

http://www.coachfactoryoutlet-onlines.us.com

http://www.fredperrypoloshirts.us

http://www.yeezy-boost350v2.us.com

http://www.chicagobullsjerseys.us

http://www.stlouiscardinalsjerseys.us

http://www.nike-blazerlow.fr

http://www.louboutin.org.uk

http://www.miamiheatjerseys.us

http://www.coachoutletcanada.ca

http://www.sanfrancisco49ersjerseys.us.com

http://www.cheaprayban-sunglasses.com.co

http://www.texasrangersjerseys.us

http://www.yeezyboost.us.com

http://www.adidas-superstar.us.com

http://www.cheapjordan-shoes.in.net

http://www.kevindurantshoes.us

http://www.moncler-outlet.us.com

http://www.ralphlaurenuk.me.uk

http://www.jameshardenshoes.us.com

http://www.discountnikeshoessc.org

http://www.coachfactoryoutletsonlines.us.com

http://www.michaelkorsoutletofficial.us

http://www.todsoutlet.name

http://www.2017nikeairmax.us

http://www.350yeezyboost.us.com

http://www.mbtshoes.in.net

http://www.michaelkorshandbagsuk.org.uk

http://www.outletlouisvuitton.us.com

http://www.danskoshoes.us.com

http://www.fit-flopssaleclearance.us.com

http://www.longchamphandbags.me.uk

http://www.gucci--borse.it

http://www.rolexreplica-watches.us.com

http://www.bostonredsoxjerseys.us

http://www.tomsshoesoutlet.in.net

http://www.rolex-replicawatches.com.co

http://www.ralphlaurensaleclearance.org.uk

http://www.valentino.in.net

http://www.nikestoreuk.me.uk

http://www.chicagowhitesoxjerseys.us

http://www.pandora-outlet.us.com

http://www.newyorkyankeesjerseys.us

http://www.airjordan-uk.org.uk

http://www.pandorajewelryoutlet.in.net

http://www.toryburchoutletstores.in.net

http://www.nfl-jerseyscheap.us.com

http://www.adidasshoes.me.uk

http://www.louisvuitton-outlet-online.us.com

http://www.michaelkorsoutletmalls.us.com

http://www.adidasyeezyboost-350.us

http://www.coachoutlets.in.net

http://www.marcjacobshandbag.us.com

http://www.cheapoakleysunglassesofficial.us.com

http://www.swarovski-crystal.uk

http://www.philadelphiaphilliesjerseys.us

http://www.coachfactory-outletstore.us.com

http://www.salomonshoesoutlet.us

http://www.michaelkorsoutletonlineclearance.in.net

http://www.adidassuperstar.me.uk

http://www.coach-factoryoutlet-online.us.com

http://www.nike-store.us.com

http://www.oakleysunglassesonlinesale.us.com

http://www.officialcoachfactoryoutlet.eu.com

http://www.oakleysunglassessonlines.com

http://www.michaelkors-outlet.ca

http://www.pandora-bracelet.us

http://www.guccioutlets.us.org

http://www.versaceshoes.in.net

http://www.sanantoniospursjerseys.us

http://www.coachfactoryonlineoutlet.com.co

http://www.raybansunglasses.net.co

http://www.denverbroncosjerseys.us

http://www.raybans.org.uk

http://www.doudounemonclerpascher.fr

http://www.polooutlet.in.net

http://www.chicagocubsjerseys.us

http://www.birkenstockshoes.us.com

http://www.coachoutletsonlines.us.com

http://www.onlinecoachfactoryoutlet.us.com

http://www.hermes-handbags.us

http://www.fitflopssaleclearancewholesale.us.com

http://www.yeezy-boost350v2.us

http://www.longchamphandbags.us

http://www.clevelandcavaliersjerseys.us

http://www.tomsoutletstore.in.net

http://www.coachoutletstore-online.us.com

http://www.oakley--sunglasses.us.org

http://www.mbtshoes.name

http://www.hollisterclothingstore.us

http://www.adidasoutlet.us.com

http://www.ralphlaurenoutlet.us.org

http://www.michaelkors-bags.me.uk

http://www.polo-ralphlauren.us.com

http://www.kate-spadehandbags.us

http://www.celineoutlet.us

http://www.discountoakleysunglassessale.us.com

http://www.outletmichaelkorsoutlet.us.com

http://www.air-jordans.us.com

http://www.adidasshoes.name

http://www.adidas-nmd.us.com

http://www.hermesoutletonline.us

http://www.nikefreeflyknit.name

http://www.saclongchampsolde.fr

http://www.fredperry.us.com

http://www.pandora.us.com

http://www.stephcurry-shoes.us

http://www.coachoutletonlineinc.us.com

http://www.edhardyukclothing.me.uk

http://www.michaelkorsoutletonlineclearance.us.com

http://www.levisjeans.name

http://www.jimmychoo.in.net

http://www.cheapjordans.us.com

http://www.pandoracharmssaleclearance.com

http://www.kate-spadeoutlet.us.com

http://www.poloralphlauren-outlet.us.org

http://www.chiflatiron.in.net

http://www.coachoutletcoachfactoryoutletonline.us.com

http://www.nikeair-max.org.uk

http://www.fitflopssalesclearance.us.com

http://www.pandoracharmssaleclearance.me.uk

http://www.houstonrocketsjerseys.us

http://www.mulberryoutlet.org.uk

http://www.newenglandpatriots-jerseys.us

http://www.adidasnmd.us.org

http://www.birkenstocksandals.org.uk

http://www.adidas-shoes.us.com

http://www.katespadeoutletonline.us.com

http://www.mulberryhandbags.me.uk

http://www.christianlouboutinshoes.us.org

http://www.adidasnmd-shoes.us

http://www.cheapoakleysunglassesonsale.us.com

http://www.salomon-shoes.name

http://www.oakley.nom.co

http://www.oklahomacitythunderjerseys.us

http://www.adidasshoes.us

http://www.coachoutletstoreonlineclearances.in.net

http://www.mlbjerseys-cheap.us.com

http://www.rolexreplicawatches.name

http://www.adidas-nmd.me.uk

http://www.fitflopssandals.us.com

http://www.chaussure-louboutin.fr

http://www.coachoutletonlinecoachfactoryoutlet.us.com

http://www.michaelkors-outlet.co.uk

http://www.losangeleslakersjerseys.us

http://www.ralph-lauren-pas-cher.fr

http://www.jordan-femmepascher.fr

20170608yueqin

Comment by 20170608yueqin 19 weeks and 1 day ago

Your point of view

You must be signed in to comment.