{"id":15605,"date":"2023-11-24T20:18:53","date_gmt":"2023-11-24T20:18:53","guid":{"rendered":"https:\/\/businessyield.com\/tech\/?p=15605"},"modified":"2023-11-24T20:18:56","modified_gmt":"2023-11-24T20:18:56","slug":"20-basic-linux-commands-with-examples-a-beginners-guide","status":"publish","type":"post","link":"https:\/\/businessyield.com\/tech\/technology\/20-basic-linux-commands-with-examples-a-beginners-guide\/","title":{"rendered":"20 Basic Linux Commands With Examples: A Beginner’s Guide","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"\n

As a beginner, you must be familiar with basic Linux commands to complete an operation. This is because, while performing a task, we all need shortcuts. Shortcuts help us to complete a task quickly. <\/p>\n\n\n\n

Linux comes with such commands which are one to two words. Using these commands, you can perform several operations in no time. <\/p>\n\n\n\n

According to a\u00a0StackOverflow survey<\/a>, Linux is the most-used operating system by professional developers, with an impressive 55.9% market share. It\u00a0isn\u2019t just a coincidence. 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. You also have access to a powerful package manager and a bunch of development tools.<\/p>\n\n\n\n

What are Linux commands?<\/strong><\/a><\/span><\/h2>\n\n\n\n

A Linux command is a program or utility that runs on the command line. A\u00a0command line\u00a0is an interface that accepts lines of text and processes them into instructions for your computer.<\/p>\n\n\n\n

Any graphical user interface (GUI) is just an abstraction of command-line programs. For example, when you close a window by clicking on the \u201cX,\u201d there\u2019s a command running behind that action.<\/p>\n\n\n\n

flag <\/strong>is a way we can pass options to the command you run. Most Linux commands have a help page that we can call with the flag -h<\/code>. Most of the time, flags are optional.<\/p>\n\n\n\n

An argument <\/strong>or parameter is the input<\/strong> we give to a command so it can run properly. In most cases, the argument is a file path, but it can be anything you type in the terminal.<\/p>\n\n\n\n

You can invoke flags using hyphens (-<\/code>) and double hyphens (--<\/code>), while argument execution depends on the order in which you pass them to the function.<\/p>\n\n\n\n

Linux commands are a type of Unix command or shell procedure. They are the basic tools used to interact with Linux on an individual level. Linux operating system is used on servers, desktops, and maybe even your smartphone. It has a lot of command line tools that can be used for virtually everything on the system. <\/p>\n\n\n\n

All users should be familiar with most of these commands as they are required for most operating system tasks and computer programming. Linux commands are used to perform a variety of tasks, including displaying information about files and directories.<\/p>\n\n\n\n

Top 20 basic Linux commands for beginners<\/strong><\/h2>\n\n\n\n

1.\u00a0Is\u00a0command<\/strong><\/h3>\n\n\n\n

ls<\/code>\u00a0is 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.<\/p>\n\n\n\n

The\u00a0ls command\u00a0is commonly used to identify the files and directories in the working directory. This command is one of the many often-used Linux commands that you should know.<\/p>\n\n\n\n

This command can be used by itself without any arguments and it will provide us the output with all the details about the files and the directories in the current working directory. There is a lot of flexibility offered by this command in terms of displaying data in the output. <\/p>\n\n\n\n

Check the below image for the output.<\/p>\n\n\n

\n
\"Ls<\/figure><\/div>\n\n\n

As you can see in the above image, using the command by itself without any arguments will give us an output with all the files and directories in the directory. The command offers a lot of flexibility in terms of displaying the data in the output.<\/p>\n\n\n\n

2. pwd command<\/strong><\/h3>\n\n\n\n

The\u00a0pwd<\/code>\u00a0command stands for \u201cprint working directory,\u201d and it outputs the absolute path of the directory you\u2019re in. For example, if your username is \u201cjimmy\u201d and you\u2019re in your Documents directory, its absolute path would be:\u00a0\/home\/jimmy\/Documents<\/code>.<\/p>\n\n\n\n

This command is mostly used to print the current working directory on your terminal. It is also one of the most commonly used commands.\u00a0<\/p>\n\n\n

\n
\"Pwd<\/figure><\/div>\n\n\n

Now, your terminal prompt should usually have the complete directory anyway. But in case it doesn\u2019t, this can be a quick command to see the directory that you\u2019re in. Another application of this command is when creating scripts where this command can allow us to find the directory where the script has been saved.<\/p>\n\n\n\n

3. mkdir command<\/strong><\/h3>\n\n\n\n

To create folders in the shell, you use the\u00a0mkdir<\/code>\u00a0command. Just specify the new folder\u2019s name, ensure it doesn\u2019t exist, and you\u2019re ready to go.<\/p>\n\n\n\n

This\u00a0mkdir command\u00a0allows you to create fresh directories in the terminal itself. The default syntax is mkdir <directory name> and the new directory will be created.<\/p>\n\n\n\n

root@ubuntu:~# mkdir <folder name><\/code><\/pre>\n\n\n\n

For example, if you want to create a directory as\u00a0\u201cBusinessYield\u201d<\/strong>\u00a0then the basic syntax would be: <\/p>\n\n\n\n

mkdir BusinessYield<\/code><\/pre>\n\n\n\n

In case you want to create another directory inside the main directory BusinessYield to store projects, you can use the following command to do so.\u00a0mkdir BusinessYield\/projects<\/strong><\/p>\n\n\n\n

4. cp command<\/strong><\/h3>\n\n\n\n

The\u00a0cp<\/code> command\u00a0of Linux is equivalent to copy-paste and cut-paste in Windows.\u00a0It\u2019s so easy to copy files and folders directly in the Linux terminal that sometimes it can replace conventional file managers.<\/p>\n\n\n\n

To use the cp<\/code> command, just type it along with the source and destination files:<\/p>\n\n\n\n

cp file_to_copy.txt new_file.txt<\/code><\/pre>\n\n\n\n

You can also copy entire directories by using the recursive flag:<\/p>\n\n\n\n

cp -r dir_to_copy\/ new_copy_dir\/<\/code><\/pre>\n\n\n\n

Remember that in Linux, folders end with a forward slash (\/<\/code>).<\/p>\n\n\n\n

5. cd command<\/strong><\/h3>\n\n\n\n

The cd<\/code> command is highly popular, along with ls<\/code>. It refers to \u201cc<\/strong>hange d<\/strong>irectory\u201d and, as its name suggests, switches you to the directory you\u2019re trying to access.<\/p>\n\n\n\n

For instance, if you\u2019re inside your Documents directory and you\u2019re trying to access one of its subfolders called Videos<\/strong>, you can enter it by typing:<\/p>\n\n\n\n

cd Videos<\/code><\/pre>\n\n\n\n

You can also supply the absolute path of the folder:<\/p>\n\n\n\n

cd \/home\/BusinessYield\/Documents\/Videos<\/code><\/pre>\n\n\n\n

There are some tricks to the\u00a0cd<\/code>\u00a0command that can save you a lot of time when playing around with it:<\/p>\n\n\n\n

1) Go to the home folder<\/strong><\/a><\/h5>\n\n\n\n
cd<\/code><\/pre>\n\n\n\n
2) Move a level up<\/strong><\/a><\/h5>\n\n\n\n
cd ..<\/code><\/pre>\n\n\n\n
3) Return to the previous directory<\/strong><\/a><\/h5>\n\n\n\n
cd -<\/code><\/pre>\n\n\n\n

The\u00a0cd command<\/strong>\u00a0is used to navigate between directories. It requires either the full path or the directory name, depending on your current working directory. If you run this command without any options, it will take you to your home folder. Keep in mind that it can only be executed by users with\u00a0sudo\u00a0privileges.<\/p>\n\n\n\n

6. mv command<\/strong><\/h3>\n\n\n\n

You use the mv<\/code> command to move (or rename) files and directories through your file system.<\/p>\n\n\n\n

To use this command, you\u2019d type its name with the source and destination files:<\/p>\n\n\n\n

mv source_file destination_folder\/\n\nmv command_list.txt commands\/<\/code><\/pre>\n\n\n\n

To utilize absolute paths, you\u2019d use:<\/p>\n\n\n\n

mv \/home\/kinsta\/BestMoviesOfAllTime .\/<\/code><\/pre>\n\n\n\n

\u2026where .\/<\/code> is the directory you\u2019re currently in.<\/p>\n\n\n\n

You also can use mv<\/code> to rename files while keeping them in the same directory:<\/p>\n\n\n\n

mv old_file.txt new_named_file.txt<\/code><\/pre>\n\n\n\n

7. rm command<\/strong><\/h3>\n\n\n\n

You can use the rm<\/code> command to remove files and directories. Be careful while using it, though, because it\u2019s very difficult (yet not impossible) to recover files deleted this way.<\/p>\n\n\n\n

To delete a regular file, you\u2019d type:<\/p>\n\n\n\n

rm file_to_copy.txt<\/code><\/pre>\n\n\n\n

If you want to delete an empty directory, you can use the recursive (-r<\/code>) flag:<\/p>\n\n\n\n

rm -r dir_to_remove\/<\/code><\/pre>\n\n\n\n

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

rm -rf dir_with_content_to_remove\/<\/code><\/pre>\n\n\n\n

The\u00a0rm command\u00a0is used to delete permanently an empty directory. To perform this command the user running this command must have\u00a0sudo\u00a0privileges in the parent directory.\u00a0<\/p>\n\n\n\n

8. man command<\/strong><\/a><\/span><\/h3>\n\n\n\n

Another basic Linux command is\u00a0man<\/code>. It displays the manual page of any other command (as long as it has one).<\/p>\n\n\n\n

To see the manual page of the mkdir<\/code> command, type:<\/p>\n\n\n\n

man mkdir<\/code><\/pre>\n\n\n\n

You could even refer to the man<\/code> manual page:<\/p>\n\n\n\n

man man<\/code><\/pre>\n\n\n
\n
\"\"
The manual page of \u201cman.\u201d<\/figcaption><\/figure><\/div>\n\n\n

9. alias command<\/strong><\/a><\/span><\/h3>\n\n\n\n

The alias<\/code> 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.<\/p>\n\n\n\n

For example, to set ls<\/code> to have color without typing the --color<\/code> flag every time, you would use:<\/p>\n\n\n\n

alias ls=\"ls --color=auto\"<\/code><\/pre>\n\n\n\n

As you can see, the alias<\/code> command takes one key-value pair parameter: alias NAME=\"VALUE\"<\/code>. Note that the value must be inside quotes.<\/p>\n\n\n\n

If you want to list all the aliases you have in your shell session, you can run the alias<\/code> command without argument.<\/p>\n\n\n\n

alias<\/code><\/pre>\n\n\n
\n
\"\"
The alias command.<\/figcaption><\/figure><\/div>\n\n\n

10. unalias command<\/strong><\/a><\/span><\/h3>\n\n\n\n

As the name suggests, the\u00a0unalias<\/code>\u00a0command aims to remove an\u00a0alias<\/code>\u00a0from the already defined aliases. To remove the previous\u00a0ls<\/code>\u00a0alias, you can use:<\/p>\n\n\n\n

unalias ls<\/code><\/pre>\n\n\n\n

11. chmode command<\/strong><\/a><\/span><\/h3>\n\n\n\n

The\u00a0chmod<\/code>\u00a0command lets you change a file’s\u00a0mode\u00a0(permissions) quickly. It has a lot of options available with it. The basic permissions a file can have are:<\/p>\n\n\n\n