10 Basic Mac Terminal/Linux commands

10 Basic Mac Terminal/Linux commands

(in my experience)

ยท

5 min read

Welcome to my blog, dude! ๐Ÿ˜†

welcome

Today, we're going to take a look at some basic Mac Terminal/Linux commands in my experience.

So, don't roast me friends๐Ÿ˜… I'm a n00b at this stuff, so I haven't used shit like cat, grep, pbcopy or pbpaste yet.

embarrass

Without further ado, let's get fuckin started!!


1. pwd ๐Ÿ—บ๐Ÿ“

You can use the pwd command to find out your current location in the filesystem/name of the folder currently open in your terminal window.

The output of pwd will look something like this:

show `pwd` command

After executing the pwd command, the terminal tells us that we're in the folder called Yuri inside of the folder Users at root.


2. ls ๐Ÿ“

The ls command is used to list all the folders/files under the location specified, or if not specified, under the current location.

Here, we're listing all the directories/files inside ~

list all directories/files inside `~`

Also, we can add options/flags to our ls command, such as:

  • ls -l
  • ls -a

ls -l

-l is the lowercase letter L, and it stands for long. It lists all contents in a long list format.

Here, terminal will output more information about the listed files when we use the -l option.

long list format `ls` command

This is out the scope of this article, but the long format shows information, such as, permissions, file owner, file size, date, etc.

ls -a

The option a stands for 'all'. The ls -a command lists the all of the files inside the current folder/directory, including hidden files.

The photo below shows all of the files inside the ~ folder/directory:

show all files in `~` directory

As you saw on the photo above, there's a full-stop (period) at the beginning of certain files. Filenames with a full-stop at the beginning are hidden files.

You can put options/flags together: ls -la

This will produce the same result as doing each option alone, as we saw above.

However, combining two options/flags together outputs both results:

combine options `-a` and `-l` with `ls` command

On the photo above, terminal output a long list format with additional information for both regular files and hidden files.


3. mkdir ๐Ÿ“

The mkdir command stands for 'make directory'. This creates a new folder on your current location (current directory).

Use the mkdir command with the name of the new file you want to create:

make new directory called `for_twitter`

On the photo above, we made a new directory called for_twitter, then we checked if it was created by using the ls command.

You can also make multiple directories. If you want to add spaces in directory name, write between quotation marks:

make multiple directories


4. cd ๐Ÿ“‚ โžก๏ธ ๐Ÿ“‚

The cd command stands for 'change directory'. This allows you to change your current location (current directory) to another directory.

You use the cd command alongside the other file/directory name you want to change to.

Here, we changed from the ~ directory to the for_twitter directory:

`~` cd `for_twitter`


5. touch ๐Ÿ“„

The touch command creates a new empty file.

You type touch with the new name of the new file.

Check the terminal below:

create a new file with `touch`.png

There's a couple things going on in this image, let me walk you through it:

On the photo above, we change from the ~ directory to the for_twitter directory. Then, we created a new HTML file inside. Finally, we verify what's inside the for_twitter directory with the ls command.


6. rm, rmdir ๐Ÿ’ฃ

The rm command stands for 'remove'. rm removes a FILE from the system completely.

For example, check out the photo below:

remove html file with `rm` command

On the photo above, we're listing the contents inside the for_twitter directory, and we see that there's the index.html file. Then, we remove the index.html file with the rm command.

When we check the contents of for_twitter once again, we see that the index.html file is gone.

rmdir

The rmdir command stands for 'remove directory', and you guessed it, It removes an empty directory. It's very similar to the rm command. You type the name of the directory/folder you want to remove after the rmdir command and press enter.

rm -rf

Also, you can quickly delete a folder/directory and its contents within with the rm -rf command.

the r in -rf stands for 'recursively' & f stands for 'force.

So, be VERY careful with this command, as it's forcing deletion. Using this wrongly can cause system damage.

The example below removes dir1 and all of its contents without any warning.

`rm -rf` directory1


7. cp ยฉ

The cp command stands for 'copy', and it copies a file from one location to another.

You type cp with the name of the file you want to copy, then the name of the new file.

If you want to copy a directory/folder, use the -R option/flag as well.

On the example below, we copy the for_twitter directory into a new directory/folder called for_twitter_copy.

Screen Shot 2021-08-12 at 9.57.31 PM.png


8. mv ๐Ÿš™

The mv command stands for 'move'. The mv command moves a file to another directory/folder, or (if directory name doesn't exist), it renames the file.

Check this photo below: we moved the index.html file inside the folder dir2.

move html file to folder `dir2`

On the photo above, we first listed all the content inside the ~ using the ls command.

Then, we moved the index.html file inside the dir2 folder. We do this by using the mv command followed by the name of the html file we wanted to move, in this case, the index.html file, followed by the new location, in this case, dir2.

When we check the contents of dir2, we can see that we successfully moved the index.html file inside.


9. man ๐Ÿง”โ€โ™‚๏ธ

The man command stands for 'manual'. It displays all the information about commands that we can run on the terminal. Also, it shows all options/flags you can use.

Below, I typed man ls, and terminal shows me the manual of the ls command.

man command


10. sudo ๐Ÿ‘ฎ

Finally, the sudo command allows you to run programs with admin privileges. You'll be required to enter your personal password to execute these commands.


We're done! ๐Ÿฅณ ๐ŸŽ‰

Thank you!

You're probably tired AF reading this long ass post, but at least, you learned the 10 most basic terminal/Linux commands!

So that's it! Thank you for making it through this long ass post๐Ÿ˜†

Find me on Twitter!

ย