There's more to learn about the "cd" command. Lil' Linux Lesson!
Ғылым және технология
The "cd" command, "change directory", is a critical part of navigating in a Linux or UNIX based system.
In today's Lil' Linux Lesson, we'll dive into the cd command, some intermediate usage bits, and then speculate about some POSIX reasons why certain choices were made. We'll span the gamut from beginner to advanced in one video. I hope you enjoy!
This video was not sponsored - if you want to help me do more videos like this one, please help support the channel!
Buy my shirt directly from my merch store: vkc.sh/merch
Become a member and support the channel: support.linux.mom
Chapters and whatnot:
0:00 How well do YOU know the cd command?
0:14 What does the cd command actually do?
0:51 Basic usage of the cd command on Linux
2:01 Going up the directory tree with the cd command
2:34 Going to a previous directory with the cd command
2:51 Navigating back to the home directory using cd
3:05 Navigating to absolute paths with the cd command
3:31 Want to know more about the cd command? Use the man builtins page!
3:42 Why isn't there a manpage for cd?
#linux #terminal #homelab
Пікірлер: 141
Don't forget the lovely functionality of hitting the TAB key while cd'ing around.. saves alot of typing
I've been using Linux since 2002 and I didn't know about "-". Yay learning! Linux is awesome, and so are you.
I missed the "...and so are you!" Part at the end😢❤ great vid. Always comforting to watch one of these
Not related specifically to `cd`, but using Alt-. (hold alt, tap period) is fantastic when navigating the shell. If I've just done `mkdir -p /some/long/path/name`, I can then go to the newly created directory by typing `cd ` , pressing Alt-. to insert the last word of the last command, and then enter. If it's from several commands ago, I just keep pressing Alt-. Then there's also `pushd .` and `popd` if you wanna get fancy.
@SlyPearTree
Жыл бұрын
Alt-. does not seem to work in vi mode. After some googling I found that adding the following to ~/.inputrc will do it: set editing-mode vi set keymap vi-insert "\e.":yank-last-arg Those who do not have a ~/.inputrc can just create it. Up to now I simply used !$ but Alt-. has the advantage of going back in history when pressed repeatedly.
@ludwig2345
Жыл бұрын
Oh, that's nice. It's like a fancier "cd !!" I hope it works on my non english keyboard.
@ThatNateGuy
10 ай бұрын
Huh. Interesting. I come from a Windows background but have absolutely loved PowerShell. The more I learn about UNIX shells and commands, the more I see the roots of what I'm more familiar with. I want to be better on Linux, so I'll keep learning to do it the Linux way !
when I saw this video was published, I thought, "I'll bet I manage to learn something new". And I did. Never knew about "cd -". Awesome!
Was thinking.. oh cute the 'cd' command. I will watch for fun. And then BAM! Veronica hits me with the cd - It's been something like 42 years and I did not know (remember) that. Thank you!
Your videos have a @Technology Connections vibe. So comforting to watch.
One of the things that I both love and hate about Linux is that even though I've been using it for years, I still learn new things about even basic stuff all the time. I love that there's all that depth, but hate that it's all kind of secret knowledge. The only tip I would add to this, btw, is how helpful tab autocomplete can be when using CD. For example, if you were in ~/Downloads/songs/RockyHorror and wanted to get to Absolute Treasures but couldn't quite remember how to escape spaces, you could always type "cd Abs" and then the tab key and it'll complete all the escaping for you. Sure it's lazy, but it's also very very safe.
I totally never knew about man builtins, and I've been using this stuff for decades!
@VeronicaExplains
Жыл бұрын
It's a good one!! :)
Just a quick comment on the question raised at the end of why cd is a shell built-in. It's a function of the chdir system call. That system call changes the working directory of the process that calls it. But when running an external program, the shell forks a child process. So a chdir call made there would only change the working directory of the child, not of the shell process itself. As a result you can't really have an application program that changes the working directory of the interactive user, short of starting a new shell and killing the parent process. Another interesting tidbit is that the behavior of things like '-' and the '~' notation are actually implement in the shell, and not the kernel. I.e., you can't expect them to work if you write a program that calls chdir to change the directory the program is running in. On the other hand '..' is implemented in the OS and in most file system implementations is literally stored in the directory data structures on the disk. (Okay, that wasn't as quick as I intended.)
here's a thing I tripped over in my early linux days: there has to be a space between "cd" and ".." unlike in DOS, where it works without the space. this may not be a common problem anymore though :)
@eliminmax
Жыл бұрын
alias cd..='cd ..'
I made an mdc alias, which stands for make directory then change into that directory. Very handy!
sudo pronounced as "Sue Dough" made my day. Any other way of saying it grates on my ears. Veronica is a treasure.
@theherk
7 ай бұрын
It isn’t asking Sue to make dough but the Super User (context) to DO something. So I suppose it makes sense either way.
@Thankz4sharing
7 ай бұрын
Being consistently rational is not one of my strong points. Fortunately I am now retired and have fewer occasions to pronounce ‘nix commands in my head. These days I’m more likely to think “Ess ewe dee oh? What’s that?”
@theherk
7 ай бұрын
@@Thankz4sharing A great old Phil Collin’s tune, by the sound of it. 😂 Enjoy retirement.
This is great. Really appreciate how seriously you treat a topic that some folks would dismiss as being obvious. I grew up with DOS, but there are adults now that have only ever used a touchscreen. We all start somewhere, and some folks are most assuredly starting here!
My favourite part of this video was when you said, "kind of like opening a different folder in a file browser." Amiga Workbench!!!!! 😀
@VeronicaExplains
Жыл бұрын
I was tempted to say "drawer" but I was worried folks wouldn't get it. :)
WOW! Love the explanation. You think you know linux 'CD' commands, but there is always something new to learn. Thanks Veronica! Your Awesome.
Just found out this channel, and it has become one of my favorites so far
Glad ppl like you exist
I paid a certification for a low value course and I feel like HACKERMANS writing comments on how the video did not show them - and ../chain tricks! Bummed the views do not reflect the quality of these videos, but I really hope you don't stop making them. You explain things really well (pun not intended) without adding things that could be confusing and you also don't leave out things like these that could be actually very useful. I'm learning AND having fun. Take that, high school teachers! (and college teachers...)
Loving this channel. Can’t wait to see more videos about Linux and I’m just getting started learning it.
Over 25 years using linux and I never encountered cd - Thanks for the tip. Keep up the great videos.
@m1k1a1
Жыл бұрын
The comment section is just as good! 30 years using unix-like systems and I never knew Alt-. (ALT + period) inserts the last word of previous command.
best retro vibe's from 2010 i love it
props for using amiga workbench for your example. Soooo cool.
Love these little nugget lessons. Great info!
Thank you Veronica love these videos!
Love these, thank you so much!
That was very helpful because I learnt 2 new things in under 5 minutes so Thank You Very Much Veronica :)
I'm just happy to hear someone else pronounce sudo like "pseudo" or "judo". All jokes aside, I like the Lil Linux Lesson series, very informative.
"cd" is one of those very important commands in the shell. Plus it allows me to go places in my computer and sometimes I can go on an adventure in my system. OK I know I'm a nerd.
OK I've been using Unix since the early 90s, I watched this just for fun expecting to learn nothing cause it's like the a-b-c's, and damned if I didn't actually learn something! I never knew about "cd -"! Nice!
I actually learned multiple things new to me here, thank you! :)
Wow, honestly I've been using Linux for years but I did not know all of those cool tricks! Keep up the good work and thank you for making this video.
Love to see more videos like this.
pro tip: cd /us it autocomplete the name
This was really good, thanks
》You see, Veronica, in my classes, I always speak about the importance of DEC PDP series (minicomputers) as they were deeply used during the initial development of C programming language, original UNIX OS and then, even indirectly, TCP/IP. I tell them that almost EVERYTHING we have nowadays comes from these 70s' technologies.
@JarrydNielsenLMAO
Жыл бұрын
This is why I recently picked up a DEC J-11. Mostly to touch and look at, but I would like to put some electricity through it at some point :D
@brunosouza2918
Жыл бұрын
@Jarryd Nielsen 》That’s awesome, Jarry, there’s quite a lot of useful stuff ("grabbed" from KZread videos) you can take a look at in order to repair your computer, the other day, I myself watched a complete disassembly.
3:46 LOL. Takes me back to my CP/M days where EVERYTHING was a program!
Great video!
Thank you always learn something new with your Explanations!!! 😉
Good video. Using aliases you can go to your most used folders typing a single world like "Downloads". I created aliases for all my most used folders so I can move between them really fast.
I didn't know the thing about spaces in folder names, I've been confused by that before so I'm glad to know what was happening. I try to avoid the terminal if possible as I'm not as comfortable using it so these videos are really helpful for when I need to use it.
This is such based Linux content! Glad to discover more content creators that seem inclusive and passionate about the subject! 🎉
Good video. CD is familiar to me because of the similarity to the DOS CD command, and I was quite a DOS wizard many years ago. My big stumbling block has been learning to navigate through different drives, given that Linux treats every thing as one big directory structure. There's always more to learn...
I actually somehow didn't know about the "-" trick, and it will improve my life quite a bit, thank you!
@abodabalo
Жыл бұрын
Same here, after decades of cd‘ing. Thank You!
@meiowalot7570
Жыл бұрын
Same here! I’ve used Unix since DEC Ultrix in college in 1990. Now it makes sense why there is a “git switch -“
Wholesome content on Linux
Ha! I didn't expect it, but I learned something new.
Thanks Veronica. A lot of the CLI commands like this make sense for me (as DOS 6.22 was my first operating system and all of them made sense) because their initials actually stand for what they do (CD, Change Directory, MkDir (or MD) Make Directory, etc,) but what about some of the commands that don't do this like (PWD, which I thought was for password, but, no, and the Touch command, not a clue.) I hope that you carry on with this series. Thanks Veronica.
Awesome!
Love the 'Linux' refrigerator magnets from the 80's 😁
I love these mini tutorials. Have you noticed that you're like the video version of the TLDR command?
Loved this lesson. I learned Unix a long long time ago in another galaxy far far away, And I still learned so much, thank you. And we still use COBOL? I vaguely remember it and JCL. Cool!
good video. I saw your cat on Learn Linux TV :)
bloody mary - I would NEVER expect a video about "cd"... - omg!;-)
wow... learnt ../.. and - today. I was feeling pretty smug up till then.
U Amazing!!! Thx for explained.
Very nicely explained as always ! A video about 'grep' could be interesting for the next Lil'Linux Lesson
@VeronicaExplains
Жыл бұрын
That's on my radar! I'm trying to work my way from "most beginner" to more complex as I release these. :)
@TheCodeTinkerer
Жыл бұрын
@@VeronicaExplains yes that is what I thought and I think that grep would be the next logical step
You can configure some shells so they treat entering a directory name as an implicit cd to that directory: bash: shopt -s autocd zsh: setopt autocd tcsh: set implicitcd fish: default, but requires a trailing / or leading / or ./ nushell: default, but requires a leading / or ./
@gabrielgian6207
11 ай бұрын
Discovered this by accident using fish but I can't really get over the habit of typing cd
》(that's because of it you still have to apply backslash before an empty space, just like you'd do in C coding)
You rock, Veronica! Love the Amiga Workbench screenshot. I am horrified to admit that as a UNIX user off and on since about 1990, I only learned about cd - about a year ago. I never liked using pushd/popd, they seemed a little too clunky for me.
I love the shirt! Ethernet twisted pair? :D
I am a windows user and I would like to start using the linux subsystem. Considering this channel talks about a varied number of distributions of linux, I would like to suggest making about about wsl. For example, I still don't know if it is fully compatible with a standalone installation of linux, or if it performs better or worse... It would be interesting to have a video on that. But I do understand that viewers might not want to know about windows hehe
In Bash, to get help about each builtin, use the "help" builtin: e.g. `help cd`. This is something Z shell overlooks. In general, I find zsh man pages divided in an unintuitive way, as opposed to bash's single page that you can easily `/`-search through.
I didn't know about cd -. I don't do a whole lot of navigation on the bash prompt, though. I prefer using vifm for directory and file navigation. Once you're there, it's easy to open a shell if you want.
hi there, nice vid, i like: alias ..='cd ..' yay
Regardless I known for a whiiiile cd command is really good to hear from you. Regards!!
Great video. Any thoughts on the use of the word folder vs. the word directory? For some reason, I seem to have emotions attached the topic.
@VeronicaExplains
Жыл бұрын
I tend to go with either one. I also go with "drawer" from Amiga stuff, so my mind is pretty flexible on it. If I think about it, I imagine I call it "directory" more from the terminal and "folder" more from a GUI.
Thank you for the series Lil' Linux Lesson! Quick question about the BASH-BUILTINS(7) what the (7) for IP(8) has (8) any help explaining it would be most helpful.
Fun little fact, the dot is used as a symbol for the current directory by the cd command. Also when you specify an absolute path, the cd command starts at the root of your files system, then it switches to relative mod, then it starts reading the path directory by directory, you can see that by trying something like cd /home/user/Pictures/../Desktop/RandomDirectoryOnMyDesktop which is equivalent to run cd /home/user/Desktop/RandomDirectoryOnMyDesktop
About the /usr/bin/cd file, I would guess that is is to support the use of other shells that don't have cd builtin, without the need to make (and maintain) a separate binary for the command.
cd ~ cd `pwd -P` Are useful additions
Seems like I've skipped a few docs because after a decade with Linux I learnt today 'cd -' -command.
happy cd'ing! (shelling?) going to go see the wyse video now (:
@VeronicaExplains
Жыл бұрын
Thanks! That one was my very first video, go easy on me! :)
Thank god i was wondering when i saw the video .. Am i up te sratch? i was .. i knew all of this .. I have to admid this is good tutorial for the new unix friends among us! (welcome you all)
akthulally this is Lil' GNU/Linux lesson!
You can use `help cd` rather than man built-ins and scrolling. The built-ins have entries under `help`
Was waiting for `cd -` to yell "I KNEW THAAAT!!" but I didn't know why it worked. I also use cd without args to get to home a lot these days since getting a tilde and then pressing Enter is rather uncomfortable on a de_DE keyboard.
to correct you ed is actually a UNIX program that came from the Official UNIX system nd its not on Linux as that is a kernel its on GNU.
TAB-Key is your best friend! Can you make a little COBOL - Tutorial?
Would love to see actual linux tutorials not the most basic commands we ve been using since msdos
@VeronicaExplains
Жыл бұрын
Not everyone knows what you know. I'm making things at multiple skill levels.
For bash builtins, the help command is a bit more sensible than the manpage I never knew I could find (at least under Debian, don't know in RedHat world) help cd
Single dot refers to the current directory (which is usually 100% redundant when using cd) and double dot means one directory up. I think it's sad that the pattern doesn't continue. Triple dot for two levels up, and so on.
Nice! I always just type the two dots '..' to go up a directory, instead of 'cd ..' I'm not sure if this works everywhere, as I am using zsh as my shell.
@posiputt1476
Жыл бұрын
nice, I didn't know that! I'm using zsh, too. and I tried it out in bash, but there ".." does nothing.
@Mitsunee_
Жыл бұрын
that's definitely a zsh-thing, on bash you need to set up an alias for this first: alias ..='cd ..'
@RedSaint83
Жыл бұрын
In DOS I used to do "cd.." with no space at all, so it seems like there's different flavours from OS to OS.
@qwfp
Жыл бұрын
But wait, there's more! You can add more dots to go even higher up. So '...' would be equal to 'cd ../..'. You can use up to 6 dots. And it works with cd too! 'cd ...'. But that's still a zsh feature.
@mulad
Жыл бұрын
"cd.." (no space) could definitely be set up as an alias if you wanted, and I imagine ".." is a default alias on some distros. I imagine the "cd ..." (3 dots) in zsh was done for people who remembered using that trick in DOS/Windows. In the broadest case, "cd .." works because there is literally a directory named ".." in most paths, which you can see with "ls -l", but "..." (3 dots) isn't really there. There isn't a ".." directory in the root (/) directory, so some shells or programs could throw an error if you tried to go up a directory from that path
There is no manual entry for builtins on Void Linux.
I've a question that you could even do a video about :D What company will be the first to make an AI operating system? Do you think it will just be a regular OS with AI capability or a completely new kind of OS that runs off the back of an AI? What would it even look like or be like??
Great lesson, but I am so distracted by the bashtop output over your shoulder. What has got that machine so loaded down? Whatcha Dooin'?
@VeronicaExplains
Жыл бұрын
Haha! I was probably transcoding video. I've been setting up a Jellyfin server and ripping old DVDs!
@locnar1701
Жыл бұрын
@@VeronicaExplains That, as they say, will do it...
@theherk
7 ай бұрын
@@VeronicaExplains is it bashtop? Looks more like clementtsang/bottom to me.
👍
3:59 - wait, what? Really? Does that even work?!? Because unlike some builtins, cd necessarily must actually be run as a builtin… which… makes me surprised to hear about this, and…. Curious how (if) it actually works. I guess I’ll have to poke around on a system that has it, and see what the deal is. Fascinating.
In bash: CTRL-X CTRL-E to edit your command in $EDITOR
@VeronicaExplains
Жыл бұрын
This is an underappreciated tool! Thanks for sharing!
this gave me Windows 3.1 flashbacks
TIL cd - and cd
After watching almost all videos I have a recommendation. Can you leave important text a little bit longer on screen. I almost can never read everything and have to rewind the video. For jokes gags and other kind of potentially vimy humor it's OK obviously. 😊
The cd command is also very useful with combining them with other shell commands, such as 'ls [directory] -al' to view all hidden files and the permissions assigned to them, such as 'cd /bin && ls -al', where the '&&' operator allows a second command specified right after the first. One way to familiarise with all the built-in shell commands and individual app commands, is through installing Arch Linux, Gentoo, Void Linux or some distribution in where you can manually install the OS.
@theherk
7 ай бұрын
`;` allows a following command in most shells, where `&&` is a condition that will only execute the next command if those preceding return 0. Using this in the case of combining `cd` with `ls` is actually more keystrokes than just using the return key. But other examples work well for combination with `cd` like `find … -exec cd {}; … && cd -`.
nEXt uSe HypErlAnd
If you will unset the executable bit on a directory, you wont be able to cd into it.
So it doesn't have anything to do with cd roms );
@eDoc2020
Жыл бұрын
It depends on what the filesystem is backed by ;)
What else there's to know about cd? cd ~ ; cd $HOME; I wonder
》🐧 😉
I didn't learn anything 😢