Terminal

Avi Gupta
hackerLog
Published in
7 min readJun 2, 2019

Before we start: the commands used here are only for the mac.

Oh my god.
Just checked the time on my last post.
ITS BEEN 5 MONTHS. 5. WHOLE. MONTHS. (Or something like that.)

So, I’d like to say shamelessly that I’m back with yet another blog post.

TERMINAL!

Terminal Logo. Courtesy of Macworld UK.

For my computer’s purposes, this is on macOS X Mojave, but the commands will be the same anyways.
When you open up terminal, it should look something like this if you are in dark mode:

The terminal in dark mode.

In default mode (or light mode in Mojave), it should look like this:

The terminal in light/default mode.

Here is how I will be writing the commands:

There will be a $ sign at the start of the line, marking the $ sign circled in red:

the $ sign.

After that, there will be the command that you can copy and paste. Anything in quotes will be what it represents, for example, "application" will mean that you should remove the quotes and put the name of an application on your computer here.
Sometimes, I will put [], which means that a number goes inside of []. For example, [number] means that you remove [ and ], and replace number with a real number, such as 9.

Now that that’s settled…

Here are some basic commands that you should know.

1: open

$ open "Directory"

This command will open any directory in the finder.

$ open -a "Application"

This command will open an application if it is closed, or take you to where that application is if the screen is already open.

$ open -n -a "Application"

This command will open a new window of an application.
If an application has a space in its name, such as “Google Chrome,” add a backslash right before a space character, like this: Google\ Chrome. You can add this to the $ open command, like this: $ open -a Google\ Chrome.

$ open -t "Text File"

This command will open a text file (.txt, .rtf, ._DOC, ._DOCX) in TextEdit, the default text-editing program on a MacBook Pro. There are many other ways to use $ open. If you want to find out all of them, just type in:

$ open

2: cd

$ cd "Directory"

This will navigate you through a directory, if you need to find a file directly from there.

3: rm

$ rm "File"

This command will remove any file that you want removed. Be careful when you use rm from the command line: unlike the Finder app, items deleted using rm DO NOT show up in the Trash: they’re gone forever! You cannot undelete items deleted using rm.

$ rm -a "Application"

This command will remove any application that you want removed.
However, Apple won’t let you remove some applications THAT WE DON’T. EVEN. USE. THAT. MUCH. Examples are:

  • Safari (Most of us just use Chrome, anyways)
  • News (Mojave)
  • Mail (Gmail has probably replaced that)
  • Home (Mojave)
  • Maps (Why do we even need this?)
  • Dashboard (This is just… useless)

Moving away from that tangent now.

4: ls

$ ls "Directory"

This command lists all files in that directory, but by the first sub directory. So if you have a folder in Pictures with all of your gaming screenshots, it will list the folder name of the screenshots, not the names of the screenshots.

To list things in a sub-directory, do this:

$ ls "Directory"/"Sub-directory"

There are some more commands that do, well, more… interesting things. Here are a few:

1: Caffienate

Let’s say that you are looking at a single page off of a computer screen, not doing anything to the computer. Then, suddenly, the computer goes to sleep. You probably have to unlock it again, or move your finger around the trackpad to wake it up again. To prevent that, type in this:

$ caffeinate 

To make your computer go back to sleep automatically, do control + c on your mac. It will appear as ^C on your terminal. This overrides any active process.

2: Ping

Doesn’t seem like fortnite.com is connecting correctly. What should you do? This terminal command will help you troubleshoot any website:

$ ping "Website Address"

Make sure it is the full website address. To ping fortnite.com, do this:

$ ping www.fortnite.com

A line will look something like this:

Request timeout for icmp_seq [sequence number]

If the website does not give you any info. Or it will look something like this:

[package size] bytes from [ip adress of website]: icmp_seq=[sequence number] ttl=54 time=[time it took to get info]

You can also ping a certain IP address, in the same way.

$ ping [IP adress]

3: Yes

Are you sure you want to do this command?

$ yes

Okay, but don’t say I didn’t warn you.

This command writes a bunch of y’s really fast, and this simple command can make your PC go into full load. This is called a stress test, and is used by technicians to find problems in your PC. To terminate the process, just use control + c (^C).

4: du

$ du

This command lists all of your files, line by line.

5: ditto

Want to copy your downloads into your documents? ALL OF THE CONTENTS? You could just drop n’ drag, or, use a simple terminal command:

$ ditto "from File" "to File"

For example, if I wanted to move my downloads to my pictures, I would just do this:

$ ditto Downloads Pictures

And If I wanted to see a command line for every file transferred, I could just do this:

$ ditto -V "from File" "to File"

6: arp

This command lets you list all devices on your network. Just type this in:

$ arp -a

and it will instantly give you a list of all the local IP addresses on your network.

7: whois

If you want info on a certain IP address, just type in this:

whois [ip adress]

and it will give you info on the IP address. This works for any device and any website.

Now you might be thinking “This is boring.” Well, let me tell you something:

Courtesy of KnowYourMeme.

Jobs didn’t leave terminal without a few easter eggs here or there. Here are some easter eggs that will leave you going “WHAAAAAAAA?”

1: Star Wars

If you are in MacOS Sierra and higher, use this command:

$ nc towel.blinkenlights.nl 23

If you are below MacOS Sierra, use this command:

$ telnet towel.blinkenlights.nl

Star Wars: A New Hope should play in plain ASCII text.

2: Banner

Get your message across via terminal! Just enter this simple command:

banner -w "font size here [number from 25 to 200] "message here"

3: Play snake on terminal!

Type in this:

$ emacs

Then, do esc + x, and type in “snake.” Look at the bottom of the screen. It should look like this:

M-x snake

Press enter, and you should be playing snake.

Snake on Terminal!

You can do the same for tetris: esc + x and then type in “tetris.”

M-x tetris

Wow!

Also, did you notice the shadow of my screenshots?

4: Disable Screenshot Shadows!

To do this, just type in this:

$ defaults write com.apple.screencapture disable-shadow -bool TRUE

let’s try it!

before command:

Screenshot with shadow…

aaaaand after command:

…Screenshot without shadow!

Notice how the screenshots are significantly bigger. This helps me a lot.

Don’t like the way your terminal looks? do command + i, and it will look something like this:

A list of all of the terminal profiles.

It will look something like this, which gives you a list of all of the terminal profiles, or themes. Click on a profile to make your terminal window have that profile.

You can edit properties of a profile by double-clicking it. A window like this should pop up:

The profile editor.

Soo… yeah. That’s what you can do with terminal. This simple program can do so many things that you want it to do. It really helps you out, in ways you would never think of.

Signing out,

Avi.

--

--

Avi Gupta
hackerLog

Named after the first 2 games I got on my xBox, Forza and Minecraft. Also, i have a blog. Real name is Avi.