Basic Linux commands for Beginners

Basic Commands for Linux Terminal Beginners

Basic Commands for Linux Terminal Beginners

If you run a Linux distribution, and you are only using the GUI, then you are missing. The Linux terminal is a very powerful tool that goes far beyond the GUI. The writing order may seem scary for beginners, but you will soon be hung on it. In this guide, you will get the most important Linux commands, use a pro-like terminal.

Basic Linux commands, however, are universal and should work on distributing any past and future. They will also work with non-Linux operating systems based on Unix, such as FreeBSD, or MacOS / OS X Terminal.



Important information about the Linux terminal


As far as we know, there is not a single Linux distribution, which does not have any type of terminal. In contrast, there are some distributions that do not have a GUI by default, and everything is done on the command line.

Quickly open the Terminal from GUI, Shortcuts Ctrl+Alt +T will work in most distribution and desktop environments.


This is the basic body composition of most Linux commands:

  [sudo] command [optional switch] [file or directory path]  


Which command will run through administrative authority using sudo. Most Linux commands work with system files and sudo wants to install/uninstall the programs.



linux commands are case-sensitive


It is important to remember that everything written in the terminal is case-sensitive. When the command is "sudo", then "Sudo", "SUDO" and "sUdO" will not work.

sudo command
Screenshot

Most Linux commands are lowercase letters, but capital switches such as "chown -R"


Files and directories are also case-sensitive. "File1" and "file1" are different files, even if they are in the same directory.



Beware of spaces


The difference is equally important. "chown-R" will return only one error. If we want to create / access / delete a file or directory in a file or directory that has a location in the file name, we can either put the whole filename under quotation marks ...

Beware of spaces
Screenshot

... or "escape" from space using the backslash "\".


Beware of spaces Screenshot 2
Screenshot

If we did not, special mkdir command, which creates a directory, will create two directories, "Folder" and "Name". Other Linux commands will simply fail.


Beware of spaces Screenshot 3
Screenshot


Finding the Last Linux Command


By pressing the keyboard Up key, we will use the latest Linux command to successfully complete the cycle. No failed commands will appear here.

Finding the Last Linux Command
Screenshot

We can use the command of the history to see the Linux commands that we have used in the terminal.



Invisible password


When we are asked for our password, example After using "subo", we will not show anything on the screen as soon as we type the password, no wire or point or anything. We just type the password and press Enter.

Invisible password
Screenshot

Use the tab to autocomplete


The tab button on the keyboard is a big time saver on the Linux command because it will automatically fill the names of files and directories.

If we want to delete a file named "myTerminaloutherFilefolder", then we just need to type "rm w" and pressing tab will automatically complete the rest filename.


If more than files started with the same letter, e.g. "myTerminaloutherFilefolder" and "myTermenalouther" will suppress common "myTerm" by pressing tabs on "rm w".


Use the tab to autocomplete
Screenshot

After this we need to type an extra character - "i" or "e" in the. example - and press tab to auto-complete to begin again.



Copying and pasting Linux commands


To copy or paste at the terminal, Ctrl+C and Ctrl+V will not work.

Instead, we need to use Ctrl+Shift+C and Ctrl+Shift+V. Or we can right-click and use commands from the context menu.


Copying and pasting Linux commands
Screenshot


Wildcards


When using the Linux command, the symbol "?" And "*" are wildcards.

"?" Will replace any single character. So, if we have two files test1file and test2file, then we can delete them with "rm test? file". But this will not erase test12file.


Wildcards
Screenshot

"*" Will replace any string of characters. "rm test*file" will remove test1file, test12file, testDESDESDESfile. This will also remove any other filename that starts with "test-" and ends in "-file", including the testfile.


Wildcards Screenshot 2
Screenshot

It is clear that we should be extremely careful while combining the removal commands with the wildcard. "rm *" will remove each file in the existing directory, and it will not use the trash.



Additional information about Linux commands


We can learn more with any Linux command [command] --help and man [command].

[Command] --help will use the command, and show available options and switch.


Additional information about Linux commands
Screenshot

man [Command] will show the command manual, which is an extended version of --help output.


Additional information about Linux commands Screenshot 2
Screenshot

However, not all Linux commands have the manual or a help option.


Additional information about Linux commands Screenshot 3
Screenshot


Basic Linux Command for Terminal


In this list, we have not included every possible command, only Linux commands that will be more useful for Linux beginners. In the future, we will prepare a separate guide with advanced Linux commands.

ls - List all the contents of the current work directory.

Make sure you read ls --help because there are several options on how to show directory content.

cd [directory] - change directory


pwd - Print the full path to the current work directory. It stands for "Printing directory"


find [file or directory] - search for a specific file or directory inside the current work directory

We can use it with the wildcard, like find*.png

locate [file or directory] - Locate a specific file or directory everywhere on the file system, and return all the paths included in it.

We can use it with wildcards, like locate*.png

mkdir [directory name] - create a new directory.


To make it anywhere on the disk, we can include a complete path to the directory, e.g. mkdir ~ / public / dir1 

If we create a directory with sudo mkdir, then we will not be able to create files or directories without administrative rights.

touch [file name] - create an empty file.


This is especially useful with the "echo" command, which you will find in the next section of the guide. If the file already exists, the touch will not erase its contents, it will only change the last access time for the last time.

cp [file1] [file2] - Copy file 1 and create a new file named File 2. Copy -> Paste equal.


In command to copy the directories and their contents, we need to use cp -r [dir1] [dir2].

We can include full paths for both files or directories to copy and paste from different parts of the disk, e.g. cp ~ / file1 ~/public/file2.

mv [/dir1/file1] [/dir2/file1] - Move file 1 from dir1 to dir2. Cut -> Paste equal. 
mv will also work for directories without the need for additional switches. The mv command is the only way to rename file/directory using Linux commands. To rename file1 in file2, we just type mv file1 file2.

rm [file] - delete a file.

To remove the directory and all its contents, we need to use rm -r[dir]rm command will delete any files/directories immediately without using the trash. So, be careful, especially if you are using wildcards. sudo rm system will remove files and folders.

ln -s [file] [link] - create a symbolic link for the file or folder

A symbolic link is another powerful version of shortcuts created on Windows. There are some differences which we will be involved in a separate guide.

zip [archive.zip] [file] - creates a zipped folder that has a compressed file.

Using wildcard, we can compress everything in the directory with zip archive.zip *.

unzip [archive.zip] - unzips a compressed folder

By default, unzip will extract all files in the working directory.

tar -cf [archive.tar] [file] - creates a compressed folder that contains a compressed file, using a different algorithm from the zip.

By using wildcards, we can compress everything in the directory with tar -cf archive.tar *.

tar -xf [archive.tar] - Decompresses a .tar archive

By default, tar -xf will extract all files in the working directory. With tar -zxf [archive.tar.gz] we can extract tar.gz archives.

gzip [file] - replaces the file with a .gz archive file.

zip and tar both maintain the original file, but gzip will only leave the .gz archive, and will delete the original file.

gzip -d [archive.gz] - Reduces a .gz archive.

By default gzip -d will extract all files in the working directory.

unrar e [archive.rar] - decompresses a .rar archive

Most of the distributions have not already been installed to create a rar archive and can install it only as a trial version, for which a payment registration is required. However, we will find unrecognizable preinstalls on almost all distributions, however, to decompress .rar archives.

echo "text"> [file.txt] - creates a file in which the "text" we wrote with the command. 
The echo just prints "text" on the screen. Using redirection character ">" Result of Result has been redirected to file.txt

careful! If file.txt already exists, then echo "text"> file.txt will overwrite it, remove its previous content.

echo "text" >> [file.txt] - adds "text" at end of file.txt content.

This is a safe way to run resonance. If the file.txt file exists, echo "text" >> file.txt will only add "text" under the contents of the file without overwriting the previous content.

The file.txt and >> file.txt sections of the command can be used with all Linux commands which print on the results screen, such as ls, address, etc. This will redirect the result to a file.

cat [text file] - Display all the contents of a text file on the terminal.


For larger files, we can use the cat [text file] | more and the cat [text file] | less, Similarly, we have ls or locating output pipes.

We can also use the head [text file] to display the last ten lines, to show only the first ten rows, and the tail [text file].

grep "pattern" [File] - Search for a particular text pattern inside a text document. If the pattern is found, then the command prints a line of pattern on the terminal.


We can also use a grep -r "pattern" [dir] to search for a pattern in all the files in the directory.

nano [text file] - Nano is a relatively user-friendly terminal text editor. To create a new text file, we can run the nano without any parameters.


Just remember that the commands given below do all the work with Ctrl, e.g. Press Ctrl + X to exit, press Ctrl + G to get help.

sort [text file] - The sorted text will print lines of files.


wc [text file] - In this order, a word will count for a text file, print the number of newlines, words, and bytes.


If you want know more about Linux Terminal commands Then, of course, tell us through the comment.

Post a Comment

1 Comments

  1. Niece post of Linux command.
    I very help for this article.

    ReplyDelete