{"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 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 A 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 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 ( 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 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 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 The\u00a0 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 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 To create folders in the shell, you use the\u00a0 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 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 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 The\u00a0 To use the You can also copy entire directories by using the recursive flag:<\/p>\n\n\n\n Remember that in Linux, folders end with a forward slash ( The 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 You can also supply the absolute path of the folder:<\/p>\n\n\n\n There are some tricks to the\u00a0 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 You use the To use this command, you\u2019d type its name with the source and destination files:<\/p>\n\n\n\n To utilize absolute paths, you\u2019d use:<\/p>\n\n\n\n \u2026where You also can use You can use the To delete a regular file, you\u2019d type:<\/p>\n\n\n\n If you want to delete an empty directory, you can use the recursive ( 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 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 Another basic Linux command is\u00a0 To see the manual page of the You could even refer to the The For example, to set As you can see, the If you want to list all the aliases you have in your shell session, you can run the As the name suggests, the\u00a0 The\u00a0 One of the most common use cases for You use this to make scripts executable, allowing you to run them directly by using the\u00a0 Maybe the For instance, with this command, you can run a\u00a0Python script\u00a0or a program only available in .run format, like\u00a0XAMPP. When running an executable, make sure it has executable (x) permissions, which you can modify with the\u00a0 Here\u2019s a simple Python script and how we would run it with the Here\u2019s how we\u2019d convert the script into an executable and run it:<\/p>\n\n\n\n The\u00a0 Command: <\/strong><\/p>\n\n\n\n Output:<\/strong><\/p>\n\n\n\n The\u00a0 Command: <\/strong><\/p>\n\n\n\n Output:<\/strong><\/p>\n\n\n\n We first used the\u00a0rm\u00a0<\/strong>command to delete the file and then used\u00a0locate\u00a0<\/strong>command to find the file in the database which in return has given the output with a\u00a0-e<\/strong>\u00a0as the file was removed.<\/p>\n\n\n\n The\u00a0 The\u00a0 Command:<\/strong><\/p>\n\n\n\n Output:<\/strong><\/p>\n\n\n\n Here we used mkdir <\/strong>to create two directories and then we used ln <\/strong>with an -s<\/strong> to create a soft link in it.<\/p>\n\n\n\n The\u00a0 Command:<\/strong><\/p>\n\n\n\n Output:<\/strong><\/p>\n\n\n\n The\u00a0What are Linux commands?<\/strong><\/a><\/span><\/h2>\n\n\n\n
-h<\/code>. Most of the time, flags are optional.<\/p>\n\n\n\n
-<\/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
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
<\/figure><\/div>\n\n\n
2. pwd command<\/strong><\/h3>\n\n\n\n
pwd<\/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
<\/figure><\/div>\n\n\n
3. mkdir command<\/strong><\/h3>\n\n\n\n
mkdir<\/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
root@ubuntu:~# mkdir <folder name><\/code><\/pre>\n\n\n\n
mkdir BusinessYield<\/code><\/pre>\n\n\n\n
4. cp command<\/strong><\/h3>\n\n\n\n
cp<\/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
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
cp -r dir_to_copy\/ new_copy_dir\/<\/code><\/pre>\n\n\n\n
\/<\/code>).<\/p>\n\n\n\n
5. cd command<\/strong><\/h3>\n\n\n\n
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
cd Videos<\/code><\/pre>\n\n\n\n
cd \/home\/BusinessYield\/Documents\/Videos<\/code><\/pre>\n\n\n\n
cd<\/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
6. mv command<\/strong><\/h3>\n\n\n\n
mv<\/code> command to move (or rename) files and directories through your file system.<\/p>\n\n\n\n
mv source_file destination_folder\/\n\nmv command_list.txt commands\/<\/code><\/pre>\n\n\n\n
mv \/home\/kinsta\/BestMoviesOfAllTime .\/<\/code><\/pre>\n\n\n\n
.\/<\/code> is the directory you\u2019re currently in.<\/p>\n\n\n\n
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
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
rm file_to_copy.txt<\/code><\/pre>\n\n\n\n
-r<\/code>) flag:<\/p>\n\n\n\n
rm -r dir_to_remove\/<\/code><\/pre>\n\n\n\n
rm -rf dir_with_content_to_remove\/<\/code><\/pre>\n\n\n\n
8. man command<\/strong><\/a><\/span><\/h3>\n\n\n\n
man<\/code>. It displays the manual page of any other command (as long as it has one).<\/p>\n\n\n\n
mkdir<\/code> command, type:<\/p>\n\n\n\n
man mkdir<\/code><\/pre>\n\n\n\n
man<\/code> manual page:<\/p>\n\n\n\n
man man<\/code><\/pre>\n\n\n
9. alias command<\/strong><\/a><\/span><\/h3>\n\n\n\n
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
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
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
alias<\/code> command without argument.<\/p>\n\n\n\n
alias<\/code><\/pre>\n\n\n
10. unalias command<\/strong><\/a><\/span><\/h3>\n\n\n\n
unalias<\/code>\u00a0command aims to remove an\u00a0
alias<\/code>\u00a0from the already defined aliases. To remove the previous\u00a0
ls<\/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
chmod<\/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
\n
chmod<\/code> is to make a file executable by the user. To do this, type
chmod<\/code> and the flag
+x<\/code>, followed by the file you want to modify permissions on:<\/p>\n\n\n\n
chmod +x script<\/code><\/pre>\n\n\n\n
.\/<\/code>\u00a0notation.<\/p>\n\n\n\n
12.
.\/<\/code>\u00a0Command<\/strong><\/a><\/span><\/h3>\n\n\n\n
.\/<\/code> notation isn\u2019t a command itself, but it\u2019s worth mentioning in this list. It lets your shell run an executable file with any interpreter installed in your system directly from the terminal. No more double-clicking a file in a graphical file manager!<\/p>\n\n\n\n
chmod<\/code>\u00a0command.<\/p>\n\n\n\n
.\/<\/code> notation:<\/p>\n\n\n\n
\n#! \/usr\/bin\/python3\n\n# filename: script\n\nfor i in range(20):\n\nprint(f\"This is a cool script {i}\")<\/code><\/pre>\n\n\n\n
chmod +x script\n\n.\/script<\/code><\/pre>\n\n\n\n
13. uname command<\/strong><\/h3>\n\n\n\n
uname<\/code> command\u00a0is used to check the complete OS information of the system. Check out the command and the output below<\/p>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
14. locate command<\/strong><\/h3>\n\n\n\n
locate<\/code> command\u00a0is generally used to locate the files in the database. Use an asterisk (*) to search for content that contains two or more words. As an example:\u00a0locate first*file.\u00a0<\/strong>This command will search the database for the files that contain these two names\u00a0first\u00a0<\/strong>and\u00a0file.<\/strong><\/p>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
15.
exit<\/code>\u00a0Command<\/strong><\/a><\/span><\/h3>\n\n\n\n
exit<\/code>\u00a0command does exactly what its name suggests: With it, you can end a shell session and, in most cases, automatically close\u00a0the terminal\u00a0you\u2019re using:<\/p>\n\n\n\n
exit<\/code><\/pre>\n\n\n\n
16. ln command<\/strong><\/h3>\n\n\n\n
ln<\/code> command\u00a0is used to create a shortcut link to another file. This is among the most important Linux commands to know if you want to operate as a Linux administrator.<\/p>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
17. cat command<\/h3>\n\n\n\n
cat<\/code> command\u00a0is the simplest command to use when you want to see the contents of a particular file.\u00a0The only issue is that it simply unloads the entire file to your terminal. If you want to navigate around a huge file, you can use\u00a0
less<\/code>\u00a0<\/strong>command alternatively.<\/p>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
18. touch command<\/strong><\/h3>\n\n\n\n
touch<\/code> command\u00a0creates an empty file when put in the terminal in this format as touch\u00a0