Everything You Need to Know About $PATH in Bash

Ғылым және технология

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

Пікірлер: 114

  • @DamienzTheBand
    @DamienzTheBand6 жыл бұрын

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

  • @SUNNySINGh-if6jd

    @SUNNySINGh-if6jd

    4 жыл бұрын

    lol

  • @linuxd

    @linuxd

    Жыл бұрын

    been looking for a long time for this info

  • @user-il6sw7ib8g
    @user-il6sw7ib8g7 жыл бұрын

    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!

  • @lewiscobb7817
    @lewiscobb78177 жыл бұрын

    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.46887 жыл бұрын

    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
    @PoeLemic4 жыл бұрын

    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.

  • @dawid_dahl
    @dawid_dahl2 жыл бұрын

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

  • @lrosales2753
    @lrosales27534 жыл бұрын

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

  • @usingvancedplzdontban1128
    @usingvancedplzdontban11284 жыл бұрын

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

  • @brainplot
    @brainplot4 жыл бұрын

    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 :)

  • @stevenspakowitz
    @stevenspakowitz4 жыл бұрын

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

  • @conceptualTriad
    @conceptualTriad3 жыл бұрын

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

  • @huntercoleman1347
    @huntercoleman13477 жыл бұрын

    Another great and informative tutorial. Thanks!

  • @lwa.dev74
    @lwa.dev744 жыл бұрын

    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👨🏽‍💻📚

  • @user-ve1gj3pm5g
    @user-ve1gj3pm5g7 жыл бұрын

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

  • @tutoriaLinux

    @tutoriaLinux

    7 жыл бұрын

    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

    7 жыл бұрын

    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

    7 жыл бұрын

    Thanks James, hugely appreciated!

  • @ivan.romaniv
    @ivan.romaniv6 жыл бұрын

    Video is simply brilliant! Thanks !

  • @DanielTateNZ
    @DanielTateNZ7 жыл бұрын

    Awesome tutorials man.

  • @tatianazihindula8762
    @tatianazihindula87627 жыл бұрын

    I loved your Russian accent 😂😂😂😍

  • @CrushOfSiel

    @CrushOfSiel

    4 жыл бұрын

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

  • @itpugil
    @itpugil6 жыл бұрын

    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

    6 жыл бұрын

    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.

  • @1Cborders
    @1Cborders4 жыл бұрын

    Super useful, thank you!

  • @OGBhyve
    @OGBhyve7 жыл бұрын

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

  • @sergeiiakovlev5285
    @sergeiiakovlev5285 Жыл бұрын

    Very good video, thanks!

  • @tarunsolanki9610
    @tarunsolanki96104 жыл бұрын

    Thanks a lot. That was really helpful.

  • @livingroomc
    @livingroomc5 жыл бұрын

    Very helpful. Thanks!!!!!

  • @qrubmeeaz
    @qrubmeeaz4 жыл бұрын

    Nicely done!

  • @faroukmokhtar6900
    @faroukmokhtar69004 жыл бұрын

    beautiful! thanks man

  • @ankiewicz
    @ankiewicz4 жыл бұрын

    love these videos

  • @prashantgupta3263
    @prashantgupta32636 жыл бұрын

    Very helpful .thanks

  • @Gstech1000
    @Gstech10004 жыл бұрын

    Very helpful!

  • @user-bx1or2rr6e
    @user-bx1or2rr6e7 жыл бұрын

    Awesome tutorials

  • @portentouslad5051
    @portentouslad50517 жыл бұрын

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

  • @edufontes5484
    @edufontes54846 жыл бұрын

    Thank you!

  • @sadiqyusufilu7954
    @sadiqyusufilu79545 жыл бұрын

    Thank you very much...

  • @jacob2763
    @jacob27634 жыл бұрын

    I loved it alll

  • @basquiatttt
    @basquiatttt4 жыл бұрын

    Valeu consagrado!

  • @PhucNguyen-pf3qb
    @PhucNguyen-pf3qb5 жыл бұрын

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

  • @jokakilla2011
    @jokakilla20114 жыл бұрын

    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?

  • @robinkohrs8097
    @robinkohrs80974 жыл бұрын

    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?

  • @tee141
    @tee1419 ай бұрын

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

  • @asramogal688
    @asramogal6885 жыл бұрын

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

  • @valentin7773
    @valentin77734 жыл бұрын

    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 ?

  • @nagiostest2460
    @nagiostest24606 жыл бұрын

    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"

  • @local.interloper
    @local.interloper4 жыл бұрын

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

  • @mistaecco
    @mistaecco7 жыл бұрын

    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

    6 жыл бұрын

    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

    6 жыл бұрын

    xkcd.com/327/

  • @lingjiezhu3222
    @lingjiezhu32227 жыл бұрын

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

  • @homes24
    @homes247 жыл бұрын

    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.

  • @maceo2
    @maceo26 жыл бұрын

    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

    6 жыл бұрын

    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.

  • @kajsaerikssonrosenqvist5999
    @kajsaerikssonrosenqvist59996 жыл бұрын

    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?

  • @shivan2418
    @shivan24184 жыл бұрын

    Nice Deus Ex reference

  • @justwanderin847
    @justwanderin8473 жыл бұрын

    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

  • @TNsturmtcd
    @TNsturmtcd7 жыл бұрын

    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

    7 жыл бұрын

    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/

  • @yuranikolaev
    @yuranikolaev4 жыл бұрын

    damn! that was a perfect russian accent man!

  • @willrun4fun
    @willrun4fun7 жыл бұрын

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

  • @nathaniellough5153
    @nathaniellough51537 жыл бұрын

    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

    7 жыл бұрын

    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.

  • @andrewstallard6927
    @andrewstallard69275 жыл бұрын

    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?

  • @andrewstallard6927

    @andrewstallard6927

    5 жыл бұрын

    Never mind, I just had to change permissions

  • @user-vx5oq3xw9w
    @user-vx5oq3xw9w4 жыл бұрын

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

  • @vitall789

    @vitall789

    3 жыл бұрын

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

  • @dario2rnr
    @dario2rnr4 жыл бұрын

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

  • @radio_electronics4047
    @radio_electronics40473 жыл бұрын

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

  • @andrewstallard6927
    @andrewstallard69275 жыл бұрын

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

  • @tutoriaLinux

    @tutoriaLinux

    5 жыл бұрын

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

  • @abczyx
    @abczyx7 жыл бұрын

    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

    7 жыл бұрын

    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

    7 жыл бұрын

    Yikes.

  • @wtmyps
    @wtmyps4 жыл бұрын

    5:53 pidr

  • @mikailakintunde3699
    @mikailakintunde36995 жыл бұрын

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

  • @20thcenturyfoxyoutube
    @20thcenturyfoxyoutube5 жыл бұрын

    4:40 the evil

  • @epowouid6715
    @epowouid67156 жыл бұрын

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

  • @mosesgelberg
    @mosesgelberg3 жыл бұрын

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

  • @piaoingrou
    @piaoingrou5 жыл бұрын

    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

  • @ALexJelly
    @ALexJelly7 жыл бұрын

    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

    7 жыл бұрын

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

  • @hv3300
    @hv33004 жыл бұрын

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

  • @thengakola6217
    @thengakola62173 жыл бұрын

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

  • @tutoriaLinux

    @tutoriaLinux

    3 жыл бұрын

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

  • @thengakola6217

    @thengakola6217

    3 жыл бұрын

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

  • @pixelPlex
    @pixelPlex6 жыл бұрын

    Reference to Deus Ex quote in the script ( kzread.info/dash/bejne/pH6BqNqCkqfLXco.html )

  • @modern__ninja
    @modern__ninja7 жыл бұрын

    Did you switch to Fedora?😛

  • @tutoriaLinux

    @tutoriaLinux

    7 жыл бұрын

    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

    7 жыл бұрын

    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!

  • @pinyinxingming1821
    @pinyinxingming18214 жыл бұрын

    how to remove path

  • @donaldkagunila801
    @donaldkagunila8014 жыл бұрын

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

  • @cMaXeJIJIo
    @cMaXeJIJIo7 жыл бұрын

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

  • @Zekei1234

    @Zekei1234

    7 жыл бұрын

    Deus Ex maybe?

  • @RohitRajanEapen

    @RohitRajanEapen

    7 жыл бұрын

    Deus Ex, Gunther Herman

  • @tutoriaLinux

    @tutoriaLinux

    7 жыл бұрын

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

  • @OGBhyve

    @OGBhyve

    7 жыл бұрын

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

  • @cMaXeJIJIo

    @cMaXeJIJIo

    7 жыл бұрын

    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.

  • @imveryhungry112
    @imveryhungry112 Жыл бұрын

    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
    @christophercarr58656 жыл бұрын

    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

    6 жыл бұрын

    I used to pronounce it the other way but then the KZread 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 KZread commenters over the years ;-).

  • @dangnabbit1379
    @dangnabbit13797 жыл бұрын

    lol Castilian slavic

  • @vkb967
    @vkb9673 жыл бұрын

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

  • @ChinSamatov
    @ChinSamatov7 ай бұрын

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

  • @albertrannetsperger3788
    @albertrannetsperger37887 жыл бұрын

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

  • @tutoriaLinux

    @tutoriaLinux

    7 жыл бұрын

    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

    7 жыл бұрын

    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

    6 жыл бұрын

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

  • @gurogiri9909
    @gurogiri9909 Жыл бұрын

    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

Келесі