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
Thanks! Finally a video where someone speaks english, not bash!
@SUNNySINGh-if6jd
4 жыл бұрын
lol
@linuxd
Жыл бұрын
been looking for a long time for this info
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!
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....
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)
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.
Behold-understanding of that bloody PATH thingy has finally entered into my brain! Thank you! 🙏🏻
Finally a Linux tutorial where I can actually understand the speaker ! Thank you for this!!! ;-)
This was a BRILLIANT tutorial, thank you so much for doing this! :D
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 :)
Thank you for the explanation on this, I failed to fully grasp $PATH until your video.
Thanks so much for explaining this in a simple and easy-to-understand way. Super helpful!
Another great and informative tutorial. Thanks!
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👨🏽💻📚
hope you see this, thank you!!! I'm learning so much from you and on my way to becoming a linux sysadmin!
@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
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
7 жыл бұрын
Thanks James, hugely appreciated!
Video is simply brilliant! Thanks !
Awesome tutorials man.
I loved your Russian accent 😂😂😂😍
@CrushOfSiel
4 жыл бұрын
I was gonna say, " I think that was a Dracula accent." But then he said it was Russian... haha.
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
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.
Super useful, thank you!
Thanks! I was just thinking about how I didn't remember how to do this the other day.
Very good video, thanks!
Thanks a lot. That was really helpful.
Very helpful. Thanks!!!!!
Nicely done!
beautiful! thanks man
love these videos
Very helpful .thanks
Very helpful!
Awesome tutorials
thanks, I was wondering about the absolute paths to commands.
Thank you!
Thank you very much...
I loved it alll
Valeu consagrado!
you are sooo funny with that accent, really. I laughed
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?
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?
Hi, Dave. Thanks for your course. Why does the command "which ll" returns nothing, though it works pretty well?
sir!!can u make a video on how doe sthe mkdir command work??what are the inode numbers for . and .. after mkdir completes??
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 ?
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"
The refrence is from the original Deus Ex, the line is also used as an audio test sample.
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
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
6 жыл бұрын
xkcd.com/327/
Thanks so much, though How wound you remove the /root directory from your path, :::P
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.
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
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.
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?
Nice Deus Ex reference
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
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
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/
damn! that was a perfect russian accent man!
You've watched golden eye to much. "I am invincible!"
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
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.
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
5 жыл бұрын
Never mind, I just had to change permissions
Отличное видео и хороший русский акцент! p.s. Из России с любовью
@vitall789
3 жыл бұрын
Это изращенный американский акцент! )))
Is not usr "universal system resource" and not "user"?
For me it is the command "whereis sudo" or "whereis shutdown" that shows the path for that command, "which sudo" outputs nothing.
There is no .bash_profile on my Ubuntu (virtual) machine. Are there any other ways to change the $PATH variable?
@tutoriaLinux
5 жыл бұрын
Is there a ~/.bashrc file? You can just do it there instead, if it exists.
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
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
7 жыл бұрын
Yikes.
5:53 pidr
i didn't get anything about this . i need help
4:40 the evil
I don't have a *.bash_profile* just a *.profile* , on Ubuntu 16.04 😀
5:53 Oh, it was Russian?! Actually you sounded like an Italian mafia boss from The Godfather! :))
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
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
7 жыл бұрын
Boom! You win 10 internets. May you Deus Ex in peace!
Don't see .bash_profile in Ubuntu 18.04 or /etc/profile
I prepended a local directory.... Should i be worried
@tutoriaLinux
3 жыл бұрын
Haha nope, you're fine. That just means your directory will now be searched first.
@thengakola6217
3 жыл бұрын
@@tutoriaLinux will that reduce speed??? just asking.....
Reference to Deus Ex quote in the script ( kzread.info/dash/bejne/pH6BqNqCkqfLXco.html )
Did you switch to Fedora?😛
@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
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!
how to remove path
You are using the "root " account, you do not have to write sudo before your commands.
What game IS that from? It's on the tip of my tongue, but I just can't remember exactly haha
@Zekei1234
7 жыл бұрын
Deus Ex maybe?
@RohitRajanEapen
7 жыл бұрын
Deus Ex, Gunther Herman
@tutoriaLinux
7 жыл бұрын
Very close :-D. It's that weird russian sailor in one of the bars in the original Deus Ex.
@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
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.
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
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
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 ;-).
lol Castilian slavic
Funny is that he's actually running this on Windows 🤣
привет, ты русский да ?
Mate, ur a sysadmin definitely worth his salt... I'll give u that. But it's SUDO!!.. Not SUDU :)
@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
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
6 жыл бұрын
No, you're not an idiot. PLENTY of Linux sysadmins pronounce it like "pseudo."
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