20 Common SSH Commands You Should Be Using Today


Secure Shell, or SSH, is one of the most popular and highly trusted brands in cyber security. This is the network protocol that allows remote connections between two devices to occur. And there are a ton of handy SSH commands you can use to improve that experience.

Most SSH commands are designed to help you quickly find what you are looking for, or in other words, they exist to save you time.

Today, I will share 20 SSH remote commands that you should be using.

What Are SSH Commands?

SSH commands are executable commands that allow network administrators to locate and move files from one device to another.

While locating, moving, and even editing files are some of the most common commands, there are many others that are far more technical. For instance, it is actually possible to start an SSH service (connection) with a command.

Other commands include the ability to download files directly from the internet onto a remote device. And this is just scratching the surface.

The following 20 commands are some of the most useful in an SSH environment. Of course, what is useful to one person, may not be to another, so when it comes to usability, results may vary.

The Most Useful SSH Commands You Should Be Using

1. Copy Command, or cp

There is no doubt in my mind that every person that uses SSH will need to copy a file at one point or another. And that’s exactly what you can do with the Copy Command cp.

cp [source] [destination]

So for example, let’s say you want to copy a file on your desktop called MyFile and paste it into another directory with a different name. This is what the command would look like:

cp MyFile Directory2/NewFileName

It is important to note that if you do not specify the source location, it will search the directory you are currently in for the file. You can use this command to copy an individual file or an entire folder.

2. Change Directory, or cd

Arguably the most important command in SSH, the change directory command allows you to switch between directories. Most commands rely on being in the correct directory to work. In fact, that’s especially true about the copy command we just talked about.

Luckily, the command couldn’t be simpler:

cd [directory name]

That’s it. So, if you wanted to go to a directory named recipes, it would look like so:

cd recipes

Of course, you can get very specific if the directory you want to visit is found within other directories. In this case, you would just add the path after the directory name like so:

cd directory1/directory2/recipes

This basically tells the system to go into directory 1, then into directory 2, and finally, open up the recipes directory.

3. List Files, or ls

When network administrators have to take a look at other devices, it can be annoying to find where certain files are being stored. The List Files command exists to solve this very problem because it displays all of the files and directories on a device.

And to be honest, there’s not much to this command it is simply:

ls

This will display all of the files and directories that don’t require further digging.

Now, this command can be quite versatile outside of the simple two-character entry. You can actually add a ton to this simple command to get more results or to help you find more specific file types.

For example, if you use this command:

ls -a

This will actually display all of the hidden files that are not normally visible. Another useful command is:

ls -R

This command will display all of the files and folders within the current directory. There’s a wide variety of things you can do with the List Files command.

4. Move File, or mv

The Move file command operates similarly to the cut command you might be used to using on your computer. It will essentially take a file in one location and move it to another. It’s very basic and works similarly to the copy file command.

mv [source] [destination]

So for example, let’s say we want to move TestFile from the home directory to the TestFolder within the home directory. The command would look like so:

mv /home/TestFile.txt /home/TestFolder

It’s an incredibly useful command, to say the least. You can use the list file command afterward to make sure everything is in the correct location.

5. Current Path, or pwd

Have you ever forgotten where you are in a directory? Odds are you have, and the good news is that there is a really simple command to tell you exactly where you are. Just enter the following:

pwd

You will see the full path as a result. There are no other additions to this command, and it’s really as simple as typing pwd into the line.

6. Delete Command, or rm

There’s a high chance you will need to delete a file at some point. In fact, I would go as far to say it is unavoidable. The good news is that you can do it with an SSH command in seconds, simply enter the following line:

rm [file name]

The file in the current directory will be deleted. You can also use the pathing for the file to be more exact or if you are in a different directory. Of course, this command is not limited to files, you can also use it for directories.

In that case, the command will look like this:

rm -r home/Testfolder

The -r is what separates the two commands, so make sure to use it when it is necessary. Deleting the wrong file or directory can have catastrophic consequences.

7. Create File, or touch

Copying and moving files will only get you so far. Eventually, you will probably need to create a new file within a directory, and you can easily do that. Simply use the following line to create a file in the current directory:

touch [file name]

This command is exclusively for creating files. If you want to create the file in a different location, include the pathing information. Again, this is one of the more straightforward commands.

8. Create Directory, or mkdir

If you were looking for a way to create a new directory, don’t worry, there is a command for that. In this case, to create a new directory within the command will look like this:

mkdir [directory name]

Similar to all of the other commands, you can use the pathing information to create a directory outside of the current one. It’s identical to the previous command but is for directories instead of files.

9. Concatenate, or cat

Let’s get into actually opening files. The most common way to do this is with the concatenate command, or cat. This command will open the file in question so you can view all of the content within.

The command looks like this:

cat [file name]

However, this is only scratching the surface of this command. The real use is for merging multiple files into a new one. That command would look like so:

cat [file name 1] [file name 2] > [new file name]

Essentially, it will take the information stored in the two files and combine them into a new file. It’s quite handy when the need arises.

10. Open An Editor: Vi, Nano & Vim

If you want to edit a file, you have quite a few options. For example, if you want to open a file in Vi, just type the following command:

Vi [file name]

Another popular option is to use Nano. The command is quite similar:

Nano [file name]

Yet, another option you could use is Vim:

Vim -file name]

Obviously, you do need these editors installed before you can access them, and there are plenty of other options available.

11. History Command, or history

If you work in a team environment, which is common for IT departments, you may need to assist your coworkers from time to time. And when something does go wrong, one of the best ways to see the problem is to identify what commands they have entered.

And you can do that with the history command. All you need to do is enter the number of commands you would like to see and a list will be displayed:

history 5

The command above would show you the last 5 commands that were used. Overall, it can be a very useful tool when something goes awry.

12. Clear Terminal clear & reset

Sometimes, it can be hard to read everything on a terminal screen, thus you may want to clear the terminal for more readability. And there are two commands that can really help you do that.

The first is the clear command, which will clear all of the text on the screen.

clear

And the second is the reset command, which will reset the terminal completely.

reset

13. File Permission, or chmod

It’s extremely common to limit access to important files, and you can do that easily by setting the permissions. And as you might expect, there is a command that will do just that:

chmod [permission] [file name]

And like always, you can use the file pathing information in the file name portion of the command. Just make sure to not lock the wrong people out of a file.

If you need help setting permissions, there are some great tools that can help you.

14. Zip Files

Transferring large files over the internet can be a very slow process, especially since not everyone has Google Fiber. Instead, it’s always a good practice to compress, or zip, your files before you move them:

zip [file name].zip [file name]

In this example, the first [file name].zip is what you want the file to be called while the second is the file you want to compress. You can also add more files to the zip by putting a space in between each when entering the command.

15. Unzip Files

And as you might have guessed, you will need a way to unzip the files you receive from other devices or online. Yes, there is a command for that very purpose:

unzip [filename].zip

16. Find Command, or find

While you can use the list files command to see everything in a directory, that can be a nightmare when there are hundreds of them. Instead, a better way to search for a specific file is to use the find command.

This command allows you to search for files based on specific criteria. The basic syntax of this command is as follows:

find [starting directory] [options] [search term]

You may be wondering what options mean. In simple terms, this is an argument that helps you find what you are looking for. Or in other words, a filter option. The acceptable options include:

  • -use: Searches for a file by a specific user.
  • -size: Search for files that are a specific size.
  • -name: Search for files with a specific name.

This might sound confusing since you can also use a search term. For instance, if you made your search term wp, it would locate any file that contains wp. It’s an incredibly useful command for quickly finding the file you need to use.

17. Find String, or grep

What if you are looking for a specific piece of information within a file? You can actually search for an individual string within a file by using the following command:

grep [string term] [file name]

18. Download Files Online, or wget

There will definitely come a time when you need to download a file from an online source. And you can do that directly from the command line with this command:

wget http://websiteurl/filename.ext

This will download it into the current directory, so make sure to be in the right place.

19. Check Memory Usage, or free

If you notice that your terminal is taking long to respond or just sluggish overall, you might be using too much memory on your device. One way to check is by using this command:

free

20. Exit

Last, but not least, is a command you should be using every time you need to close the terminal: the exit command. This command is straightforward as it will close the current terminal and return you to your local device.

exit

Do I Need to Be Good At Coding to Use SSH Commands?

This is actually a pretty tricky question.

On one hand, all of the commands are pretty simple, thus, just reading them online and what they do will let you use them effectively. However, reading the results of what you get and understanding some of the implications of commands is often difficult.

A simple syntax error could result in the wrong SSH command being used, as some are just differentiated by a single letter. Thus, due to the amount of damage you could cause by using the wrong command, I would highly recommend having a basic understanding of the command line.

Speed Up Your Workflow With SSH Commands

The entire point of using SSH commands is to speed up your work process. They offer shortcuts for everything…and I mean everything. The 20 commands I have listed are only the beginning, and to be honest, most of these have a ton of modifiers.

Thus, even for what’s listed, we are only scratching the surface.

What SSH commands do you use the most? Do you find them intuitive to use?

We will be happy to hear your thoughts

Leave a reply

DealsFlip
Logo
Enable registration in settings - general
Compare items
  • Total (0)
Compare
0
Shopping cart