DEV Community

Cover image for Get to Know the Command Line: Basic Commands

Get to Know the Command Line: Basic Commands

Tori Crawford on November 13, 2019

Two years ago, when I first started learning to code, I found myself intimidated of the command line. This is something that I feel a lot of beginn...
Collapse
 
abregman profile image
Arie Bregman

Great post :)

It's worth mentioning that you can create several nested directories with -p this way:

mkdir -p /dir1/dir2/dir3

Also, for creating multiple files you can use the following syntax:

touch file{1..3} which will create file1 file2 and file3

Collapse
 
torianne02 profile image
Tori Crawford

Thank you so much for adding these to the discussion!! I was not aware of these two little tricks.

Collapse
 
patricnox profile image
PatricNox

Something super useful but not widely known, is " cd - "

// ~/
$ cd docks/proj/src/component

// ~/docks/proj/src/component
$ (something useful)

// ~/
$ cd -

Also, just "cd" is same as "cd ~" which brings you to the home dir.✔️

Collapse
 
torianne02 profile image
Tori Crawford

As I stated in the other comment, I had no idea cd - was a thing before reading the discussion. I can think of multiple different times I accidentally cded somewhere when I didn't want to and had to type everything out again. This is going to be a nice time saver!

Collapse
 
bennypowers profile image
Benny Powers 🇮🇱🇨🇦

Great intro, I will definitely share this when asked.

Now if you want to go back to the directory you were in before ~/Development, you can use the command cd ... This command navigates up one directory.

TIL you can cd - to go back

cd Documents
pwd 
/Users/bennyp/Documents
cd
pwd
/Users/bennyp
cd ..
pwd
/Users

cd
cd Documents
pwd 
/Users/bennyp/Documents
cd
pwd
/Users/bennyp
cd -
pwd
/Users/bennyp/Documents
Collapse
 
torianne02 profile image
Tori Crawford

I had no idea this existed! This is awesome. Thank you for sharing.

Collapse
 
bennypowers profile image
Benny Powers 🇮🇱🇨🇦

Yeah I literally looked it up today.

There's pushd and popd also, but I wanted something that works like the back button even if I hadnt pushed.

Google brought me to unix.stackexchange.com/questions/8...

Collapse
 
martinfeineis profile image
Martin Feineis

One of my favourite aliases is hi=history | grep
makes it super easy to get the commands I know have a certain string, be it the name of the command, a substring of a hostname or an argument to a command.

Collapse
 
tam360 profile image
Mirza

You can also use ! to execute specific command from the history list like !1986 where 1986 is the command ID Using history with grep and !

Collapse
 
torianne02 profile image
Tori Crawford

I'm planning on covering aliases in another blog post for this series! They are actually something relatively new to me, so thank you for introducing this one to me and adding to the discussion.

Collapse
 
jochemstoel profile image
Jochem Stoel

Thank you for the article, Victoria. You and those who read this article might benefit from explainshell, a website where you can enter a shell command (with optional arguments) and it will explain to you what everything means.

Try it out by entering some command with arguments. :)

Collapse
 
torianne02 profile image
Tori Crawford

That link is absolutely amazing! I wish I would have known about it earlier. I'm going to edit the article and add it. Thank you so much for adding this to the discussion.

Collapse
 
fidelve profile image
FidelVe

cd and ls are by far the two commands I use the most, especially ls -la

Collapse
 
sinteticwizard profile image
Ramon Ramirez

Excelent introduction to cmd