Bash is a unix environment, found most commonly in the Mac and Linux Terminal. The Windows DOS prompt or Powershell environments are generally similar, with different commands and capabilities. There are many alternatives. You can get git bash on Windows, or zshell or any number of others. Visual Studio Code has a built in shell environment.
There are lots of ways to get into the operating system's shell. On mac or linux, search for "terminal" and open it up. On Windows, you can search for "prompt" or "powershell". We discussed the terminal built into Visual Studio Code. On Mac, you can also turn on terminal services in preferences > keyboard > shortcuts > services > New Terminal at Folder. This allows a right click on a folder to open a terminal there. Sublime Text also has a terminal package that allows terminal to be opened at a file or folder.
However you need to, get into the shell.
When you open shell, you'll be in a directory. Who knows what one, but it will probably say it to the left of a typing prompt. List the contents of this directory.
Knowing the contents of your directories is important. Sometimes you need to know more, and bash and other command line environments will often have extra options. For instance,
ls -l will list off the files with lots more information,
ls -a will show files that might be hidden, and the two can even be combined into
This command would be
dir on a dos prompt.
Making a new directory is a common enough task. It's often easier to just do this from whatever file browser is available on the operating system, but it can be done from the shell as well.
Removing a directory is as easy as making one... sometimes. If a directory is empty,
rmdir will remove the directory straight away. Dealing with a full directory is probably easier to do in Finder or File Explorer.
But if you're following along don't actually delete that test folder quite yet.
Changing directories works with another simple command.
When working with directories, it's best to not give them code breaking characters like spaces or unicode. There are two simple directory shortcuts to know which is the
. is the code for "current directory", while
.. is the code for "parent directory".
cd . cd ..
/ character for folder separation. Use it at the beginning of a string to represent a root folder, or between folders to separate them. The
~ character will often represent a home directory. Put these symbols together to select all kinds of directory combinations.
cd ./test cd / cd /users cd ~ cd ~/Desktop
Let's get this out of the way, Vim is not my thing. It's cool if it's yours. It's a text editor you can use right in the shell. It's goofy the first time you use it, because it's a tool built around modes, and the initial mode of the tool is a command mode, and this will inevitably confuse the person who finds their way in there on accident.
If you would love to learn about Vim, there are many great places to learn, including OpenVim.
So let's figure out how to get OUT of vim. First of all, you'll know you're there, cuz it will take over the screen, you'll be totally confused, and nothing you do works. Pause. Relax. Hit
esc. This is because it's possible you've typed something that has gotten you into one of vim's modes. Hitting
esc will put you into normal mode from any other mode. At that point, type
:q! and then hit
enter. This will run the command quit, without question, and then exit the program.
And let us never speak of vim again...
But one more thing. If you ever find yourself stuck in the shell, or a command has paused, try using the cancel command
ctrl+c. Not cmd, ctrl. Try that, and it might cancel whatever command might have frozen the system. Otherwise, you might just need to close the shell completely.
If you just want to create a file without opening it, you can touch that file.
If f you want to delete a file, you can remove that file.
Nano is another shell text editor. It can be used to create and edit any files on your file system. Let's create a new file.
This will do one of two things. If that file exists, it will open it for editing. But if it doesn't exist yet, it will be created and opened up all the same. In this environment, all text files can be edited. When you are done with that process, you can close Nano with
ctrl+x. Now on Mac that's the super key, not cmd. Then type
y, and tap
enter to commit the file name and exit Nano.