Basic bash commands for beginners on Linux

Bash is a fast and powerful interface on linux, but unfortunately it is not easily understood by novice users. If you are just starting out learning linux, read these basic commands carefully and carefully to avoid losing or damaging your data.

The name bash is derived from the expression Bourne-again shell. It is a pun based on the name of Bourne (sh), an old but important Unix shell written by Stephen Bourne around 1978, and the classic concept of rebirth (born again). Bash was created in 1987 by Brian Fox.

In today's linux versions, the user now has a graphical interface with windows and commands given by clicking on an icon. Something like the Windows environment. But there are times when the program is required to open and start typing commands. That is, to write everything his computer wants to do. The true linux user should know how to handle terminal and bash commands.

Let's go see his basic commands bash of linux.

DIRECTION ORDERS

CD
It comes from the Change Directory and to go to a specific point on the disc. Compile by first typing cd and then the path to a directory. This path should be complete, i.e. it should show all the folders you should go through until you reach the desired location. Folders are separated by a right slash (/). For folder names that contain spaces, you can either put the entire path in quotes or add a backslash (\) before the space.

B.C.
cd path / where / you want / to / go

All routes are meant from your current to-do list. To specify a path that is not in a subfolder in the current worksheet, you must either navigate to the original folder of that path or use a fully written path. Such a "full address" of a file on your system starts with the root unit (denoted by /) and ends with the directory or destination file.

The cd command in bash uses some abbreviations for fast directory navigation. For example, the right vertical dash (/) indicates the "root" directory, which is the boot unit of your system. The tilde symbol (~) indicates the home directory of the current user. A dot (.) Indicates the current folder and two dots (..) indicate the parent folder of the current task list. The parent folder is a folder before the one you are at all times.

The left vertical hyphen (\) is very special. It is called "escape character" and indicates that everything after it should be handled specifically. In this case, it indicates that the space is part of the file path and not a space between two different commands.

LS
Use the ls command in the bash to see the contents of a directory. The name comes out of the list. The command shows all the files and directories in the current directory. Its most useful functions are accessible via "flags", which are short additional commands attached to the main command to change the results or extend the functionality. Flags are written with one or two dashes (-) at the beginning, usually followed by a letter.

E.g. ls

There are a number of really useful flags for ls. The ones you will usually need are:

-a shows hidden files and dotfiles (folders symbolized as dots)
-h displays file sizes with human-readable units
-S sorts by file size, larger first (make sure S is uppercase)
-t sorts according to the modification time, the newest first

If you want to use multiple flags, just place them all together. For example, if you want to see hidden files in a folder, each file placed in a row, with human-readable file sizes, you could run ls -lah.

PWD
The pwd command shows the full path of the folder you are in at any given time. The name is an acronym for Present Working Directory.

e.g. pwd

Whatever order you give will be executed automatically in the present directory that you are in at any time. For example, the command mkdir (make directory = create a folder) will create a new folder in your current work directory. To make the command run elsewhere, you must use a complete path, which starts with / to indicate the root directory of the system.

MAN
Displays the help page (manual page) for a specified command. For example, man chmod will display the man page for the "chmod" command in your terminal window. These pages display usage information, banner definitions, and examples. If you want to know more about what a command does or what options are available, always start by reading the command man page.

A fairly comprehensive version of the help, for each command, you can get if you type the command followed by two dashes and the word help. Example chmod –help.

CAT
The cat command in bash is a general reader for any file type. Run it in a text file to display the contents of the file. The cat will show you the contents of almost any file, but its result may not always be easy for humans to read or make sense to you. Therefore, it is rarely used by Unix professionals, but beginners will find it useful, as they will stumble around unknown files.

 

WORK WITH ARCHIVES AND CATALOGS

CP
Creates a copy of a file in another location with a different name. That is, the file "name.doc" is copied to "path / for / the / new / location / new-name.doc". You can consider it as copying and pasting (Copy - Paste). If the new file name already exists, the copy operation will not be completed.

e.g. cp foo.doc /root/home/newfoo.doc

MV
The mv (move) command moves a file to a new location with a different name. You can think of this command as crop and paste. We also use mv to rename files, since we can "transfer" them to the same place with a new name. Note that the mv command deletes the original version of the file after the write process is complete.

e.g. mv foo.txt /root/home/bar.txt (delete foo.txt and copy it to the / root / home folder with the new name bar.txt)

RM
Removes the contents of the directory and all the files contained in it. The name rm comes from remove. The -r flag causes the rm command to delete folders and is usually accompanied by the -f flag which executes the command by skipping each confirmation dialog. The most powerful version of this command is sudo rm -rf and should be used with extreme caution. It can delete the boot unit without any warning.

e.g. rm -rf / root / home / dimitris / (deletes the dimitris folder and the subfolders in / root / home / dimitris)

TOUCH
The touch command in bash changes the date and time of modifying a file to the current time. If the file with the specified name exists, its modification time will change to the current time. If the file does not exist, an empty file with the same name will be created immediately.

e.g. touch iguru.txt

MKDIR
Creates a directory with the specified name in the location you are in (MaKeDIRectory). To create a directory in another location, along with all the parent directories you want, use the -p flag. This will create all the parent directories you need to fulfill your command, allowing you to create a multi-level directory hierarchy on a single line.

e.g. mkdir directory

RMDIR
Removes the directory in the specified path (ReMoveDIRectory).

e.g. rmdir directory

ORDER MODIFIERS
Modifiers customize existing commands to force them to do more things or do things differently than normal.

Sudo
The sudo command stands for “super user do”, and does nothing by itself. Instead, it gives the following command administrative privileges. When you type sudo before a command, you temporarily elevate yourself to have it of the root user, giving you the power to do things you wouldn't normally do.

But with super-power comes responsibility. It also gives you the power to mess up your OS pretty badly, so be careful while learning. Make sure you fully understand each part of the command you are running, especially if you found the command in .

If you use the sudo command, you will also need to enter the administrator password.

e.g. sudo !!

The above command asks for the last command to be executed again, but this time with root administrator privileges. The “bang bang” command (!!) is the shortcut to repeat the previous command.

>
It is called "redirect". The right arrow sends the output of a command to a file. this output should be plain text. For example, ls> filelist.txt will send the output from the ls command to the "filelist.txt" file. If this file does not exist, it will be created.

|
It is called "pipe". This symbol is like a redirect but only for commands. Sends the output of one command to the input of another.

 

MODIFICATION OF LICENSES
Permissions affect which users can view, edit, and execute specific files. Files and folders have an owner, who is usually the user who created it, and modes, which control the users who access the file and what they can do with it.

These commands are the first commands you will use to use sudo. Remember that sudo makes you superuser, giving you temporary administrator privileges. This is usually necessary when dealing with file permissions, as not all files are likely to belong to the current user.

Chmod
The chmod command in bash means "change modes" and regulates the permissions on files and folders. Like the chown (permissions for a specific user), can be executed in a single file or if you put the -R flag to be executed in all the contents of a directory.

e.g. sudo chmod 775 file

File permissions can be represented in several ways, but the "numeric function" used above (775) is the most common.

e.g. sudo chown -R mitsos foo / bar

Change the owner of each file in the given directory, and set the user as "mitsos". You can run this command for the current worksheet using the period (.) In place of foo / bar.

In conclusion
To quickly learn these commands, use the bash from the linux terminal, even when you do not need it. Instead of using drag-and-drop to move a directory, try using the mv command. The more you really use these commands, the faster your skills will improve.

iGuRu.gr The Best Technology Site in Greecefgns

every publication, directly to your inbox

Join the 2.082 registrants.

Written by Dimitris

Dimitris hates on Mondays .....

Leave a reply

Your email address is not published. Required fields are mentioned with *

Your message will not be published if:
1. Contains insulting, defamatory, racist, offensive or inappropriate comments.
2. Causes harm to minors.
3. It interferes with the privacy and individual and social rights of other users.
4. Advertises products or services or websites.
5. Contains personal information (address, phone, etc.).