Everything You Need to Know About $PATH in Bash

Sdílet
Vložit
  • čas přidán 13. 06. 2024
  • How does PATH work in Linux? How does Linux know where to look for the commands that you type at the command-line? In this video you'll learn how the $PATH variable works in Linux. Specifically, we'll look at how this value is looked up in bash, and how you can modify it.
    I'll also introduce you to the `which` command, which you can use to check which filepath bash is using for a given name (executable).
    To modify PATH for
    -a single user (normal or root): /home/username/.bash_profile
    -all users except root: /etc/profile
    My step-by-step project-based Linux course for beginners: www.udemy.com/course/hands-on...
    Free Linux Sysadmin Course Playlist: • The Linux Basics Cours...
    DigitalOcean referral link: m.do.co/c/0380a1db56a6
    Patreon: / tutorialinux
    Official Site & e-mail list: tutorialinux.com/
    Twitter: / tutorialinux
    Facebook: / tutorialinux
    Podcast: kernelpanicpodcast.com
  • Věda a technologie

Komentáře • 114

  • @DamienzTheBand
    @DamienzTheBand Před 6 lety +45

    Thanks! Finally a video where someone speaks english, not bash!

  • @dawid_dahl
    @dawid_dahl Před 2 lety +1

    Behold-understanding of that bloody PATH thingy has finally entered into my brain!
    Thank you! 🙏🏻

  • @lewiscobb7817
    @lewiscobb7817 Před 7 lety +3

    I just finished watching and making notes on every video in your Linux Basics Course. It was not an afternoon's work! Knowing nothing about Linux and recently getting an ARM board to work with (Beaglebone Black) these videos were perfect and got me going, gave me a sense of what is going on, and the confidence to know where or how to dig up additional info as I need it.
    Thanks so much for the effort you put into these. Actually it may not have been much effort for you as it looks like a true labor of love and if you find a job that you really love, you will never actually work a day in your life.....
    Cheers and thanks from up here in Canada....

  • @phil.4688
    @phil.4688 Před 7 lety +2

    Learning software devlopment, these videos are invaluably useful to me for their practicality and real-world use cases. They make GREAT "just-in-time learning" material. Please keep up the good work, it's really helping! (description is very good too for later reference, nice touch)

  • @PoeLemic
    @PoeLemic Před 4 lety +4

    Thank you for teaching us this. It really helps me to understand how this works. I love how you walk-through it, and you also give the big picture. You are an awesome teacher of Linux materials.

  • @user-il6sw7ib8g
    @user-il6sw7ib8g Před 7 lety +2

    Hello from Korea, I'm watching your video quite often and it's actually really helpful. Thank you for great quality of the video.
    Take care!

  • @lrosales2753
    @lrosales2753 Před 4 lety +1

    Finally a Linux tutorial where I can actually understand the speaker ! Thank you for this!!! ;-)

  • @stevenspakowitz
    @stevenspakowitz Před 4 lety +2

    Thank you for the explanation on this, I failed to fully grasp $PATH until your video.

  • @brainplot
    @brainplot Před 4 lety

    What you did at 1:48 blew my mind. I've been using Linux for over 5 years I never knew you could transpose words like that! This is why I'm compelled to always watch your videos :)

  • @user-ve1gj3pm5g
    @user-ve1gj3pm5g Před 7 lety +15

    hope you see this, thank you!!! I'm learning so much from you and on my way to becoming a linux sysadmin!

    • @tutoriaLinux
      @tutoriaLinux  Před 7 lety +8

      That's awesome, glad to hear it! Remember to use all this stuff for practical projects; you'll learn 10 times faster that way (and have more fun). Enjoy!

    • @user-ve1gj3pm5g
      @user-ve1gj3pm5g Před 7 lety +2

      tutoriaLinux I just bought your Self-Hosted WordPress project based course, and so far it's awesome. really looking forward to your upcoming rhcsa course as well, you have a longtime subscriber/viewer/customer right here! Continue the good work man!

    • @tutoriaLinux
      @tutoriaLinux  Před 7 lety +3

      Thanks James, hugely appreciated!

  • @usingvancedplzdontban1128

    This was a BRILLIANT tutorial, thank you so much for doing this! :D

  • @conceptualTriad
    @conceptualTriad Před 3 lety

    Thanks so much for explaining this in a simple and easy-to-understand way. Super helpful!

  • @lwa.dev74
    @lwa.dev74 Před 4 lety +1

    Great resource of information... bought your course... reading your recommendations on books for Linux sys admin...this is helping me with some Laravel $Path issues I’m having but your explanations are so on point!!!! Thankyou for creating this course👨🏽‍💻📚

  • @huntercoleman1347
    @huntercoleman1347 Před 7 lety +3

    Another great and informative tutorial. Thanks!

  • @ivan.romaniv
    @ivan.romaniv Před 6 lety

    Video is simply brilliant! Thanks !

  • @OGBhyve
    @OGBhyve Před 7 lety

    Thanks! I was just thinking about how I didn't remember how to do this the other day.

  • @itpugil
    @itpugil Před 6 lety +1

    been working with Linux servers for a long while now, never got to understand what PATH is for, thanks for your tutorial now i understand its importance!

    • @tutoriaLinux
      @tutoriaLinux  Před 6 lety +2

      Yeah, PATH and DNS (and maybe caching) are the two (or three) things that make up 80% of weird behavior that you have to troubleshoot as a sysadmin. Once you get it, everything is just so much easier.

  • @tatianazihindula8762
    @tatianazihindula8762 Před 7 lety +29

    I loved your Russian accent 😂😂😂😍

    • @CrushOfSiel
      @CrushOfSiel Před 4 lety

      I was gonna say, " I think that was a Dracula accent." But then he said it was Russian... haha.

  • @DanielTateNZ
    @DanielTateNZ Před 7 lety

    Awesome tutorials man.

  • @sergeiiakovlev5285
    @sergeiiakovlev5285 Před rokem

    Very good video, thanks!

  • @1Cborders
    @1Cborders Před 4 lety

    Super useful, thank you!

  • @tarunsolanki9610
    @tarunsolanki9610 Před 4 lety

    Thanks a lot. That was really helpful.

  • @portentouslad5051
    @portentouslad5051 Před 7 lety

    thanks, I was wondering about the absolute paths to commands.

  • @livingroomc
    @livingroomc Před 5 lety

    Very helpful. Thanks!!!!!

  • @qrubmeeaz
    @qrubmeeaz Před 4 lety

    Nicely done!

  • @prashantgupta3263
    @prashantgupta3263 Před 6 lety

    Very helpful .thanks

  • @jokakilla2011
    @jokakilla2011 Před 4 lety

    Thanks for that video.
    I was wondering if compatibility is an issue when using absolute paths. Let's say my script should work on Debian and Red Hat. Will the usual binaries like sudo, grep etc. be in the same absolute path? Would I need to add checks? How would you handle that?

  • @tee141
    @tee141 Před 8 měsíci

    Hi, Dave. Thanks for your course. Why does the command "which ll" returns nothing, though it works pretty well?

  • @ankiewicz
    @ankiewicz Před 4 lety

    love these videos

  • @robinkohrs8097
    @robinkohrs8097 Před 4 lety

    Thank you so much!! Only two quick questions: Is it better to create a .bash_profile if I have none (because until now I always modified PATH in my -bashrc)? And how could I remove a directory from path? Like your /root-directory in this video for example?

  • @Gstech1000
    @Gstech1000 Před 4 lety

    Very helpful!

  • @faroukmokhtar6900
    @faroukmokhtar6900 Před 4 lety

    beautiful! thanks man

  • @valentin7773
    @valentin7773 Před 4 lety +1

    HI, in the end of your video i tried to open the .bash_profile files and they were different, and hard coding the path didn't work, maybe the structure got updated ?

  • @user-bx1or2rr6e
    @user-bx1or2rr6e Před 7 lety

    Awesome tutorials

  • @asramogal688
    @asramogal688 Před 5 lety

    sir!!can u make a video on how doe sthe mkdir command work??what are the inode numbers for . and .. after mkdir completes??

  • @kajsaerikssonrosenqvist5999

    I wanted to add to the PATH for all users, but when I looked in etc/profile there is no usage of PATH at all. Where could it be set instead?

  • @lingjiezhu3222
    @lingjiezhu3222 Před 7 lety

    Thanks so much, though How wound you remove the /root directory from your path, :::P

  • @justwanderin847
    @justwanderin847 Před 3 lety

    THanks for the videos.... would you explain the difference (and how it is afffected by PATH) these two commands...
    . run.this.file and . ./run.that.file
    thanks

  • @edufontes5484
    @edufontes5484 Před 6 lety

    Thank you!

  • @maceo2
    @maceo2 Před 6 lety

    Apologies if this is a dumb question, but I'm new to learning all of this. In regards to prepending to a path, did you place sudo within the root directory prior to prepending the root directory?

    • @tutoriaLinux
      @tutoriaLinux  Před 6 lety

      Sorry, I'm not sure what you mean by "place sudo" -- could you clarify? Follow along with the video in your own environment and let me know if anything doesn't make sense; happy to help.

  • @sadiqyusufilu7954
    @sadiqyusufilu7954 Před 5 lety

    Thank you very much...

  • @mistaecco
    @mistaecco Před 7 lety +6

    While messing with linux and learning stuff, I've been running a set of automatic youtube downlaod scripts to archive interesting and useful channels that I'd like to have for the future. You made the cut, but this video broke the file management, haha. "du -h" on my archive drive makes this one split into 17 different files called:
    everything you need to know about
    everything you need to know about /usr
    everything you need to know about /usr/local
    everything you need to know about /usr/local/sbin:
    everything you need to know about /usr/local/sbin:/usr
    and this keeps going until
    everything you need to know about /usr/local/sbun:/usr/local/bin:/usr/sbin:/usr/bin:sbin:/bin:/usr/local/games:/usr

    • @mistaecco
      @mistaecco Před 6 lety

      Yep. Wasn't my code in this case, though. Was just an automated script going through the channel, naming and saving each. I've tried to replicate the glitch, as it'd potentially be a way to run commands on my linux box remotely, which could also potentially let someone set up a reverse shell (upload a youtube video with the code required to start a reverse shell, upload to a channel I download, wait and voila). No luck so far, but I'll update here if I manage to get it to work again.

    • @HallucinVIII
      @HallucinVIII Před 6 lety

      xkcd.com/327/

  • @nagiostest2460
    @nagiostest2460 Před 6 lety +1

    Tip: Always use "su - root", never "su root". With 'su - root' you will get the environment variables of root, with "su root" you keep the environment variables of the current user. Or even more secure use "/sbin/su - root"

  • @jacob2763
    @jacob2763 Před 4 lety

    I loved it alll

  • @homes24
    @homes24 Před 7 lety

    Deus Ex lol.
    In your particular career do what type of work do yo do most, like maintaining apache/nginx servers or something more like intranets and cloud services.... or even the core system running any of that stuff. Also which one do you like more.

  • @radio_electronics4047
    @radio_electronics4047 Před 3 lety

    For me it is the command "whereis sudo" or "whereis shutdown" that shows the path for that command, "which sudo" outputs nothing.

  • @local.interloper
    @local.interloper Před 3 lety

    The refrence is from the original Deus Ex, the line is also used as an audio test sample.

  • @andrewstallard6927
    @andrewstallard6927 Před 5 lety

    I tried the command subversion trick earlier in the video with both my virtual (Ubuntu) and my main (Centos 7.0) machines.
    I changed the $PATH variable on the command line by placing /root in the front. When echo-ing $PATH, the /root directory does in fact appear first. Then, I created a script called clear that just echoes a short line. It didn't work; the screen simply cleared as normal. Then I tried changing the .bash_profile in my Centos 7.0 machine and did the same thing. The clear command just cleared the screen as usual.
    What is happening?

  • @dario2rnr
    @dario2rnr Před 4 lety +1

    Is not usr "universal system resource" and not "user"?

  • @TNsturmtcd
    @TNsturmtcd Před 7 lety

    hi man , i'm new user of Linux but i want to learn , please if i want
    to copy a lot of mp3 files at same time to another folder , what
    command i use ? (using wild cards )

    • @LukeOfWales
      @LukeOfWales Před 7 lety +1

      cp *.mp3 /path/to/new/folder/
      cp will copy/paste - you can use mv to cut/paste instead
      *.mp3 - wildcard to include every file in this folder ending in .mp3
      /path/to/new/folder/ - this will be your destination, where you want the mp3 files to go.
      Shouldn't have too many issues - if you do - there are LOADS of good resources on Google, here is a good site if you get stuck: www.cyberciti.biz/faq/copy-command/

  • @basquiatttt
    @basquiatttt Před 4 lety

    Valeu consagrado!

  • @nathaniellough5153
    @nathaniellough5153 Před 7 lety +1

    At 7:41, 7:50, and 8:06 I swear I hear some sort of custom sound effects. Do you have something going on?

    • @tutoriaLinux
      @tutoriaLinux  Před 7 lety

      Hah, because I recorded this in a PuTTY terminal window, that sound is the 'bell' that Windows randomly chose for me. You hear it when I try to scroll past the end of a buffer and do other things that make the Windows 'error' bell play.

  • @PhucNguyen-pf3qb
    @PhucNguyen-pf3qb Před 5 lety +1

    you are sooo funny with that accent, really. I laughed

  • @andrewstallard6927
    @andrewstallard6927 Před 5 lety

    There is no .bash_profile on my Ubuntu (virtual) machine. Are there any other ways to change the $PATH variable?

    • @tutoriaLinux
      @tutoriaLinux  Před 5 lety

      Is there a ~/.bashrc file? You can just do it there instead, if it exists.

  • @shivan2418
    @shivan2418 Před 4 lety

    Nice Deus Ex reference

  • @mikailakintunde3699
    @mikailakintunde3699 Před 5 lety

    i didn't get anything about this . i need help

  • @willrun4fun
    @willrun4fun Před 7 lety

    You've watched golden eye to much. "I am invincible!"

  • @hv3300
    @hv3300 Před 4 lety

    Don't see .bash_profile in Ubuntu 18.04 or /etc/profile

  • @user-vx5oq3xw9w
    @user-vx5oq3xw9w Před 4 lety

    Отличное видео и хороший русский акцент!
    p.s. Из России с любовью

    • @vitall789
      @vitall789 Před 3 lety

      Это изращенный американский акцент! )))

  • @piaoingrou
    @piaoingrou Před 5 lety

    There's no ~/.bash_profile in my ubuntu 18.04. But there is a ~/.profile
    here it is:
    *****@*******:~$ cat .profile
    # ~/.profile: executed by the command interpreter for login shells.
    # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
    # exists.
    # see /usr/share/doc/bash/examples/startup-files for examples.
    # the files are located in the bash-doc package.
    # the default umask is set in /etc/profile; for setting the umask
    # for ssh logins, install and configure the libpam-umask package.
    #umask 022
    # if running bash
    if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
    fi
    # set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
    fi
    # set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
    fi

  • @yuranikolaev
    @yuranikolaev Před 4 lety

    damn! that was a perfect russian accent man!

  • @epowouid6715
    @epowouid6715 Před 6 lety

    I don't have a *.bash_profile* just a *.profile* , on Ubuntu 16.04 😀

  • @thengakola6217
    @thengakola6217 Před 3 lety

    I prepended a local directory.... Should i be worried

    • @tutoriaLinux
      @tutoriaLinux  Před 3 lety

      Haha nope, you're fine. That just means your directory will now be searched first.

    • @thengakola6217
      @thengakola6217 Před 3 lety

      @@tutoriaLinux will that reduce speed??? just asking.....

  • @abczyx
    @abczyx Před 7 lety

    If someone has permission to modify PATH for the root user, they necessarily must already have root permission on the machine. Hard-coding executable paths in scripts seems like false security.
    Everything else sounds good :)

    • @tutoriaLinux
      @tutoriaLinux  Před 7 lety

      Absolutely true, but the majority of cron jobs I run in production are being run by unprivileged processes in a non-login shell. Most of the $PATH munging you do will (or at least should) not be for the root user. The 'absolute paths to executables' thing is more of a threat if you can trick and admin into running your evil executable with 'sudo.' Also, in a lot of web-app scenarios set up by amateurs, you'll find some webapp-specific directory (writable by non-root users) prepended to root's $PATH for convenience. Sigh. Obviously this is gold for an attacker.

    • @abczyx
      @abczyx Před 7 lety

      Yikes.

  • @wtmyps
    @wtmyps Před 4 lety

    5:53 pidr

  • @cMaXeJIJIo
    @cMaXeJIJIo Před 7 lety

    What game IS that from? It's on the tip of my tongue, but I just can't remember exactly haha

    • @TheZekei
      @TheZekei Před 7 lety

      Deus Ex maybe?

    • @RohitRajanEapen
      @RohitRajanEapen Před 7 lety

      Deus Ex, Gunther Herman

    • @tutoriaLinux
      @tutoriaLinux  Před 7 lety

      Very close :-D. It's that weird russian sailor in one of the bars in the original Deus Ex.

    • @OGBhyve
      @OGBhyve Před 7 lety

      tutoriaLinux Honestly, I had no idea. It's an easy guess considering how often you mentioned it in your older videos though.

    • @cMaXeJIJIo
      @cMaXeJIJIo Před 7 lety

      I completed the game in September 2015. Somehow it passed me by when it
      was released, but, again, thanks to you, I got to it! Yay! Crap, I still
      can't remember that character. I guess I was enjoying the chinglish in
      Hong Kong too much lol.

  • @mosesgelberg
    @mosesgelberg Před 2 lety

    5:53 Oh, it was Russian?! Actually you sounded like an Italian mafia boss from The Godfather! :))

  • @modern__ninja
    @modern__ninja Před 7 lety

    Did you switch to Fedora?😛

    • @tutoriaLinux
      @tutoriaLinux  Před 7 lety

      This one is actually shot in a PuTTY terminal on Windows. Normally I shoot in an Ubuntu VM on Windows. My Work/Dev machines are Arch, FreeBSD, and OS X.

    • @modern__ninja
      @modern__ninja Před 7 lety

      Yeah, I remember you always (or almost always) use Windows host with Ubuntu. This time it was unexpected to see Fedora. I like it more :)
      By the way, it would be great to see something about FreeBSD!

  • @ALexJelly
    @ALexJelly Před 7 lety +1

    can I recognize tht video game? hah! I wanted orange! it gave me lemon lime! or something like that. twas too long since I played it

    • @tutoriaLinux
      @tutoriaLinux  Před 7 lety +1

      Boom! You win 10 internets. May you Deus Ex in peace!

  • @pinyinxingming1821
    @pinyinxingming1821 Před 4 lety

    how to remove path

  • @donaldkagunila801
    @donaldkagunila801 Před 4 lety +3

    You are using the "root " account, you do not have to write sudo before your commands.

  • @pixelPlex
    @pixelPlex Před 5 lety

    Reference to Deus Ex quote in the script ( czcams.com/video/rJMFxIbDe-g/video.html )

  • @imveryhungry112
    @imveryhungry112 Před rokem

    i hate it when you install something with pip, and then it installs it in a path thats not in your shell PATH. Like why does the system do that? and if it does why cant it add it to your path automatically? Its like these systems are still stuck in the 90s lol

  • @christophercarr5865
    @christophercarr5865 Před 6 lety +1

    I understand that "sudo" is Super User Do [du], but I just can't abide it being pronounced like "sue-doo", rather than like "pseudo." It just sounds stupid.
    But then I'm easily annoyed.

    • @tutoriaLinux
      @tutoriaLinux  Před 5 lety +3

      I used to pronounce it the other way but then the CZcams pronunciation police came and pointed out that technically, it's pronounced sue-doo (super user DO some stuff). So I'm 100% with you, in spirit. My battered, abused spirit that has been battered and abused by CZcams commenters over the years ;-).

  • @20thcenturyfoxyoutube
    @20thcenturyfoxyoutube Před 5 lety

    4:40 the evil

  • @ChinSamatov
    @ChinSamatov Před 6 měsíci

    привет, ты русский да ?

  • @dangnabbit1379
    @dangnabbit1379 Před 7 lety

    lol Castilian slavic

  • @albertrannetsperger3788
    @albertrannetsperger3788 Před 7 lety +1

    Mate, ur a sysadmin definitely worth his salt... I'll give u that. But it's SUDO!!.. Not SUDU :)

    • @tutoriaLinux
      @tutoriaLinux  Před 7 lety +3

      You know, I used to pronounce it that way too, it just seems more natural. But then I switched, because I worked with people that pronounced it that way and when I thought about it, I realized that it's something you want to *do* as a *superuser*. So it just sort of makes sense to pronounce it "su-duu"...even though I like su-dough better.

    • @albertrannetsperger3788
      @albertrannetsperger3788 Před 7 lety

      You're right, it is actually "superuser do" so in actual fact you're pronouncing it correctly and I'm an idiot. I don't even know why I made that comment -- probably cuz I work with a bunch of guys who say su-doh. Either way, you're a good sysadmin and I love your videos. Keep it up!

    • @christophercarr5865
      @christophercarr5865 Před 6 lety

      No, you're not an idiot. PLENTY of Linux sysadmins pronounce it like "pseudo."

  • @vkb967
    @vkb967 Před 3 lety

    Funny is that he's actually running this on Windows 🤣

  • @gurogiri9909
    @gurogiri9909 Před rokem

    I did the hard code using export PATH=PATH:$PATH and I am trying to reset it but not getting any useful info on how to do it