DEV Community

Cover image for Bookmark This: The 10 Most-Used Linux Commands You Should Know
Kinsta
Kinsta

Posted on • Updated on • Originally published at kinsta.com

Bookmark This: The 10 Most-Used Linux Commands You Should Know

Linux is free and open-source, has better security than its competitors, and boasts a powerful command line that makes developers and power users more effective.

Whether you’re an experienced Sysadmin or a Linux newcomer, you can take advantage of this guide. Many of these have multiple options you can string to them, so make sure to check out the commands’ manual.

But first, make sure to fire up a terminal. In most Linux distributions, you would use Ctrl + Alt + T to do so. If this isn’t working, search in your application panel for “terminal.”

Let’s begin!

1. ls Command

ls is probably the first command every Linux user typed in their terminal. It allows you to list the contents of the directory you want (the current directory by default), including files and other nested directories.

ls
Enter fullscreen mode Exit fullscreen mode

It has many options, so it might be good to get some help by using the --help flag. This flag returns all the flags you can use with ls.

For example, to colorize the output of the ls command, you can use the following:

ls --color=auto
Enter fullscreen mode Exit fullscreen mode

The colorized ls command.

Now the ls command output is colorized, and you can appreciate the difference between a directory and a file.

But typing ls with the color flag would be inefficient; that’s why we use the alias command.

2. alias Command

The alias command lets you define temporary aliases in your shell session. When creating an alias, you instruct your shell to replace a word with a series of commands.

For example, to set ls to have color without typing the --color flag every time, you would use:

alias ls="ls --color=auto"
Enter fullscreen mode Exit fullscreen mode

As you can see, the alias command takes one key-value pair parameter: alias NAME="VALUE". Note that the value must be inside quotes.

If you want to list all the aliases you have in your shell session, you can run the alias command without argument.

alias
Enter fullscreen mode Exit fullscreen mode

The alias command.

3. unalias Command

As the name suggests, the unalias command aims to remove an alias from the already defined aliases. To remove the previous ls alias, you can use:

unalias ls
Enter fullscreen mode Exit fullscreen mode

4. pwd Command

The pwd command stands for “print working directory,” and it outputs the absolute path of the directory you’re in. For example, if your username is “john” and you’re in your Documents directory, its absolute path would be: /home/john/Documents.

To use it, simply type pwd in the terminal:

pwd

# My result: /home/kinsta/Documents/linux-command
Enter fullscreen mode Exit fullscreen mode

5. cd Command

The cd command is highly popular, along with ls. It refers to “change directory” and, as its name suggests, switches you to the directory you’re trying to access.

For instance, if you’re inside your Documents directory and you’re trying to access one of its subfolders called Videos, you can enter it by typing:

cd Videos
Enter fullscreen mode Exit fullscreen mode

You can also supply the absolute path of the folder:

cd /home/kinsta/Documents/Videos
Enter fullscreen mode Exit fullscreen mode

6. cp Command
It’s so easy to copy files and folders directly in the Linux terminal that sometimes it can replace conventional file managers.

To use the cp command, just type it along with the source and destination files:

cp file_to_copy.txt new_file.txt
Enter fullscreen mode Exit fullscreen mode

You can also copy entire directories by using the recursive flag:

cp -r dir_to_copy/ new_copy_dir/
Enter fullscreen mode Exit fullscreen mode

Remember that in Linux, folders end with a forward slash (/).

7. rm Command
Now that you know how to copy files, it’ll be helpful to know how to remove them.

You can use the rm command to remove files and directories. Be careful while using it, though, because it’s very difficult (yet not impossible) to recover files deleted this way.

To delete a regular file, you’d type:

rm file_to_copy.txt
Enter fullscreen mode Exit fullscreen mode

If you want to delete an empty directory, you can use the recursive (-r) flag:

rm -r dir_to_remove/
Enter fullscreen mode Exit fullscreen mode

On the other hand, to remove a directory with content inside of it, you need to use the force (-f) and recursive flags:

rm -rf dir_with_content_to_remove/
Enter fullscreen mode Exit fullscreen mode

Info: Be careful with this — you can erase a whole day of work by misusing these two flags!

8. mv Command
You use the mv command to move (or rename) files and directories through your file system.

To use this command, you’d type its name with the source and destination files:

mv source_file destination_folder/

mv command_list.txt commands/
Enter fullscreen mode Exit fullscreen mode

To utilize absolute paths, you’d use:

mv /home/kinsta/BestMoviesOfAllTime ./
Enter fullscreen mode Exit fullscreen mode

…where ./ is the directory you’re currently in.

You also can use mv to rename files while keeping them in the same directory:

mv old_file.txt new_named_file.txt
Enter fullscreen mode Exit fullscreen mode
  1. mkdir Command To create folders in the shell, you use the mkdir command. Just specify the new folder’s name, ensure it doesn’t exist, and you’re ready to go.

For example, to make a directory to keep all of your images, just type:

mkdir images/
Enter fullscreen mode Exit fullscreen mode

To create subdirectories with a simple command, use the parent (-p) flag:

mkdir -p movies/2004/
Enter fullscreen mode Exit fullscreen mode

10. man Command

Another essential Linux command is man. It displays the manual page of any other command (as long as it has one).

To see the manual page of the mkdir command, type:

man mkdir
Enter fullscreen mode Exit fullscreen mode

You could even refer to the man manual page:

man man
Enter fullscreen mode Exit fullscreen mode

The manual page of “man.”

Summary
It can take some time to learn Linux, but once you master some of its tools, it becomes your best ally, and you won’t regret choosing it as your daily driver.

One of the remarkable things about Linux is that even if you’re an experienced user, you’ll never stop learning to be more productive using it.

Check out our full library of web development deep dives right here: https://kinsta.com/web-development

Top comments (0)