📜 ⬆️ ⬇️

Step 6: Brief introduction to the console

Brief introduction to the console


Let's take a quick look at the terminal - a console in Linux.

Console

A console for Linux is crucial. If you seriously decide to learn Linux, then you just need to be able to handle the console. At once I will say that the console in Linux is superior in functionality to the console (cmd.exe) in Windows, but, apparently, the console is a handy tool, so Microsoft is developing a new version of the console - PowerShell.

In this console, you can run various commands and programs. You can simply execute the application with arguments, for example:
')
cat ~ / 1.txt

So we output to the console the file 1.txt, located in the user directory, but the output can be redirected from the console to the files:

cat ~ / 1.txt> ~ / 2.txt

This command will read the contents of 1.txt and write it to the 2.txt file.
So we got to know cat and redirect the output to a file.
The commands in the console are:

(program) (argument1) (argument2) (argument3) ...

If the argument contains a space, it can be enclosed in double quotes (on single quotes later).
To interrupt the execution of the command - press Ctrl + C.
We will look at more complex commands in the following articles.

I do not want to duplicate a lot of manuals for working with the terminal, but only list those commands and techniques that, in my opinion, are the most necessary and interesting.

The console prompt accompanies us when working in the console. My invitation looks like this:

mdevils @ mdevils: ~ $

Let's sort the invitation:

(username) @ (computer name) :( current directory) $

The current directory is the directory in which we are in the console. This is a very useful simplification, allowing us not to write the full path each time a different command is executed. For example, the ls command lists all files and directories in the correct directory. If we just execute ls, then the contents of the current directory will be output to the console. If we execute ls myfolder, then the contents of the myfolder directory in the current directory will go to the console, and so on. The current directory also becomes the working directory of the applications being launched. It is important to note that in each directory there are two imaginary directories:

"." - this is a pointer to the current directory.
".." is a pointer to the parent directory.

This is also a convenient simplification. We can execute the ls ... command and the contents of the parent directory in relation to the current directory are displayed on the console.

The current directory is changed using the cd command. For example:

cd / tmp /

Basic file operations look very simple:

cp (what to copy) (where to copy)
mv (what to transfer / rename) (where to transfer / rename)
rm (which files / directories to delete, use very carefully in combination with sudo)
mkdir (the name of the directory to be created)
rmdir (the name of the empty directory to be deleted)

To edit files, you can use the nano editor:

nano (file name)

A very important program to remember well is man. It displays background information for many programs.

Example of use:

man cat

Device Files


In the / dev / folder there are device image files. A computer communicates with devices by transmitting and receiving information. Such a model does not contradict the model of work with stream files that can be read and written.

For example, work with the mouse is done through the file / dev / input / mice.

I want to give a very vivid example of working with devices. Take the device / dev / audio. This device is responsible for playing and recording sound. Anything written to such a file can be listened to. Everything that is pronounced into the microphone can be read from this file.

We collect:

cat / dev / audio> /tmp/my.sound

We take the microphone and speak several phrases into it, then press Ctrl + C.

cat /tmp/my.sound> / dev / audio

And the whole record sounds in the speakers.

Writing an iso image from a disk is also very simple:

cat / dev / cdrom> ~ / 1.iso

To keep abreast of my articles, you can subscribe to the RSS feed.

Now everyone can help the development of this series of articles, share their experiences. Welcome to: http://www.linuxman.ru . All changes to the wiki, I will eventually transfer to Habr.

Manual: Step Back , Step Forward , Content

Source: https://habr.com/ru/post/19547/


All Articles