blog-image

Aug 09, 2019

22 min read

13 basic Linux commands for beginners

Written by

Vippy The VPS
About 90% of the Internet is powered by Linux servers. And if you want to manage or deploy applications on a Linux server (like a VPS), you'll need to know some basic Linux commands. For Linux beginners, the Linux terminal (otherwise known as the shell) can be daunting. There's a veritable ocean of Linux terminal commands to learn and understand. We can't cover them all today, but let's take a look at some of the basic Linux commands you'll need to begin navigating the shell.

1. PWD command

The pwd is short for Present Working Directory. It's a command-line utility tool that returns the path to the directory you're in at that moment. The output contains the full system path of the current working directory. By default, pwd ignores the symbolic links but with a proper option, you can look at the full physical path of the current working directory.
$ cd /home/dd/Pictures
$ pwd
/home/dd/Pictures
Use the P switch to find the full physical path if you have traversed inside a directory which is symbolically linked. $ pwd -P /home/dd/Pictures/test_dir [cta_inline]

2. CD command

The cd command stands for “change directory,” and it allows you to navigate from one directory to another. To navigate to a particular folder with cd command, pass the folder path as the parameter, like so
$ cd /home/dd/Documents
$ pwd
/home/dd/Documents
With no options, the cd command changes the working directory to the user’s home directory.
$ cd
$ pwd
/home/dd
Another way of doing the same i.e to navigate to the home directory quickly is to use the ~ switch.
$ cd ~
$ pwd
/home/dd
You may want to navigate to the previous working directory without typing the entire folder path again. cd - does exactly that.
$ cd /home/dd/Documents
$ pwd
/home/dd/Documents
$ cd -
$ pwd
/home/dd

3. MV Command

The mv command is a utility command that moves files and folders from one location to another. The mv command can move a single file, multiple files, and directories. To move a single file using mv, pass the name of the file that needs to be moved as a first parameter and the new file name as a second parameter. In this case mv commands renames the filename.
$ mv a.txt b.txt
// renames the file a.txt to b.txt
$ mv some_directory new_directory
// renames the folder some_directory to new_directory
To move a group of files to a folder, pass the name of the files followed by the destination folder name with cd command.
$ mv a.txt b.txt c.txt some_directory
          OR
$ mv *.txt some_directory
By default the mv command overwrites the destination file. To prompt before overwriting the destination file, use the -i option.
$ mv -i a.txt b.txt
mv: overwrite 'b.txt' ?

4. RM Command

The rm command is short for "remove." It's used to delete files and directories. Be cautious when you use the rm command because once a file or directory is deleted, you cannot recover it later. To delete a single file, just pass the name of the file along with the rm command.
$ rm file.txt
It is also possible to delete multiple files at one go.
$ rm file1.txt file2.txt image.png
To delete a directory, use the -r switch, which means to delete all files and folders recursively.
$ rm -r some_directory
To perform deletion safely and interactively, use the -i switch, which prompts before each delete action is performed.
$ rm -i file.txt
rm: remove regular file ‘file.txt’? y

5. MKDIR command

mkdir command is "make a directory." To create a directory, pass the name of the directory along with mkdir command.
$ mkdir test_directory
Sometimes, you need to create a nested directory structure. Rather than creating directories one by one, use the -p option to create an entire directory structure.
$ mkdir -p dir1/dir2/dir3
$ tree dir1
dir1
└── dir2
    └── dir3
If you want mkdir to give details of what operation it is performing in the process of creating directories, use the -v switch.
$ mkdir -v -p dir_1/dir_2/dir_3
mkdir: created directory 'dir_1'
mkdir: created directory 'dir_1/dir_2'
mkdir: created directory 'dir_1/dir_2/dir_3'

6. LS Command

ls is the list command in Linux, and it shows full list of files or contents of a directory. Just type ls and press the Enter key. The entire contents of the directory will be shown.
$ ls
Use the -l switch to show the list of files of the current directory in a long list format.
$ ls -l
In Linux, hidden files start with a . (dot) symbol and are invisible to the regular directory. The -a switch will list entire contents of current directory including the hidden files.
$ ls -la
Sometimes you may want to get the details of a directory rather than its content. To get the details of a directory, use -d option. For example, if you use ls -l /home, it will display all the files under /home directory. But if you want to display the information about the /home directory then use -ld option as
Continue reading this article
by subscribing to our newsletter.
Subscribe now

A note about tutorials: We encourage our users to try out tutorials, but they aren't fully supported by our team—we can't always provide support when things go wrong. Be sure to check which OS and version it was tested with before you proceed.

If you want a fully managed experience, with dedicated support for any application you might want to run, contact us for more information.

Leave a Reply