WorldOfTopics.com

Linux Commands (Topic)

World Of Topics » Linux » Linux Commands

Linux Commands

Image

An overview of popular Linux commands, a description of how to work with the console and terminal.

Modern personal computer users are accustomed to the graphical interface. However, sometimes you have to use the command line interface, that is, enter certain commands manually. For example, in the absence of a graphical shell, when restoring and configuring the system, etc. Moreover, using the command line, some actions are faster and more convenient than using the usual graphical interface.

Command Line is a very powerful system management tool. Some novice users are afraid to work in the console, believing that it is too difficult and incomprehensible. In fact, this is not the case, it is enough to master some working techniques and a few simple commands, and it will be much easier to figure out the rest of the commands. The graphical interface became widespread not so long ago - at the end of the last century. Before that, all computer users worked with the command line.

In any case, Linux users should learn how to work in the console, these skills will definitely come in handy in the future. In this article, we will look at working with the console and terminal, as well as the main frequently used Linux commands, without pretending to be complete, since their complete description with examples may take more than one volume.

To access the console while in graphical mode, press the key combination Ctrl + Alt + F1 . Next, you will need to enter a username and password, as when booting the system. You can open multiple consoles using the key combinations Ctrl + Alt + F2 , Ctrl + Alt + F3 , etc. (up to F6) and run different programs in them at the same time. To return to the graphical environment, press Alt + F7 , while the consoles remain open and the programs running in them will continue to work.

To work with the command line directly in the graphical mode, there are special programs - terminal emulators. There are many similar programs: gnome-terminal - standard terminal in GNOME, konsole - standard terminal in KDE, xterm , tildaetc. To open a standard terminal in Ubuntu Linux, press the Ctrl + Alt + T key combination, or click on the terminal icon on the panel. In other systems, you may have to launch the terminal program through the menu; for convenience, you can install the terminal launch icon on the panel or desktop. To get remote access to the computer through the terminal, you can use the programs telnet orssh , which will be discussed below. And on Windows, the PuTTY program, which can be downloaded from here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

Fig. 1. Konsole terminal emulator.

Fig. 1. Konsole terminal emulator

Commands in Linux consist of several parts: the command itself, keys (options) and parameters, which may be required or optional. For example, in the command ls -la / var / www (hereinafter the commands will be highlighted in bold): ls is a command, la are the keys, which are most often separated by a minus sign "-", and the parameter in in this case, the directory is / var / www. Keys can be short or long: short ones consist of one letter and are separated by one minus "-", long keys are separated by two minus "-". Short keys can be combined into one, for example the commands ls -l -a -t -r and ls -latr are identical. The most popular long options are --help and --version. By typing the --help switch after any command (for example, ls --help), we will get a brief help about it.

Please note that commands, keys, filenames in Linux are case sensitive. That is, LS and ls are different commands, if you type LS instead of ls , the effect will be unexpected. It is convenient to type long commands using the “Tab” key, which is used for autocompletion, just type the first letters of the command name and press this key. If there are several commands that begin with the entered characters, they will be displayed on the screen, in this case, you need to type one or more characters and press "Tab" again. Similarly, the "Tab" key can be used to quickly type parameters, long file names, etc. Using the arrow keys, you can view and edit the commands already entered.

You can also use the following keyboard shortcuts:

Ctrl + C - interrupt the program (note that in the graphical environment the same key combination is used for copying).

Ctrl + Shift + C - copy the selected information to the clipboard, you can use the mouse to select.

Ctrl + Shift + V - paste information from the clipboard. It is also convenient to use the middle mouse button (scroll wheel) to insert text, after selecting the text.

Ctrl + S - pause output to the terminal.

Ctrl + Q - resume output to the terminal. Although usually you can use any key for this. Sometimes it helps if the terminal is frozen.

Ctrl + Z - stop the program. To continue, you need to type the command fg (or bg to continue the program in the background).

Ctrl + D - exit the terminal, close the console, disconnect the connection with the remote computer.

Now let's go directly to the discussion of Linux commands.

Information Commands

man command - displays detailed information about Linux command, keys, etc. For example: man date .

Unfortunately, not all manuals have been translated into USA, you may need some basic knowledge of English.

date - displays the current date and time.

uname -a - displays information about the system.

who - displays a list of users who are currently logged into the system. Do not be alarmed if several users are found on a personal computer, this does not mean that hackers have hacked it. Pay attention to their names. Each open terminal, including the graphical one, is considered a separate user by the system.

w - similarly to who , it shows users in the system, but, in addition, it displays additional information - what commands users are executing and how much processor is loaded.

free - displays information about RAM.

top - displays information about processes, processor load, memory allocation.

df -h - displays information about hard drives.

uptime - displays system uptime, number of users, processor load.

pwd - shows the current directory.

time - measures the running time of the program, for example time ls .

echo - Outputs a line of text to standard output. echo Hello - displays the word "Hello", echo * - displays a list of files in the current directory. echo $ [2 + 3] - displays the sum of numbers 2 and 3.

Commands for working with files

ls - Lists files in the current directory. To display a list of files in any directory, type the path to the directory after the command, for example: ls / usr / bin . Some ls command options:

-a - show hidden files;

-s - specify the size of files in blocks;

-t - sort by file modification time, new files first;

-X - sorting by extension, filenames, files without extension are displayed first;

-l - extended output format: shows attributes, file owners and group, size, date and time of their creation;

-r - reverse the sort order. For example, the command

ls -lat / etc will display the contents of the / etc directory in an expanded format and sorted by file creation time.

cp - copy files. cp doc1 doc2 - will create a copy of the doc1 file named doc2.

rm - delete files. rm doc - will delete the doc file. rm * - will delete all files in the current directory. rm * doc - will remove all files ending in doc. The -i switch is used to confirm deletion of each file, the -r switch is used to delete directories and files within those directories.

rmdir - deleting a directory. rmdir alex - removes the alex directory.

You need to be very careful with therm andrmdir commands, especially in superuser mode, as you can remove not only your own files, but also system files, which can lead to a system crash.

pwd - displays the current directory.

mkdir - create a new directory. mkdir alex - will create alex directory.

mv - move or rename files. mv new old - Rename file new to old.

cat - concatenate files or output files to standard output. cat doc - will output the doc file.

cat / proc / cpuinfo - will give detailed information about the processor, cat / proc / version - about the Linux kernel version.

touch - creates an empty file.

touch doc - will create a doc. find - search for files. find / -name "doc *" - Finds all files that start with doc.

ln - create a link to a file. ln file1 file2 - will create a hard link. The -s switch is used to create a symbolic link.

tar is a program for working with archives. tar -zxvf file.tar.gz - will unpack the file.tar.gz archive. tar -cvf my.tar myfile - zips the myfile, creating an archive my.tar.

more - output files with a stop for viewing, unlike cat, which outputs the entire file at once. You can scroll the text line by line using the enter key or page by page using the spacebar.

less - a file viewer similar to more , but allows you to scroll up and manipulate with arrow keys.

nano is a simple full-screen text editor. Recommended for beginners as it contains a minimum of functions and basic commands are displayed on the screen.

vi is a fairly powerful text editor, but it has its own non-standard command system, so it takes time to master.

mc (Midnight Commander) is a powerful file manager similar to Norton Commander for DOS or FAR for Windows. Allows you to delete, copy, rename, view, edit files, change their attributes, etc. Midnight Commander is usually not included in the standard set of system programs, so it must be installed separately. But it is highly recommended to use it as it greatly simplifies working with files.

Fig. 2. Midnight Commander in gnome-terminal

Fig. 2. Midnight Commander in gnome-terminal

Add or Remove Programs

Various utilities are used to install and uninstall programs, depending on the version of the Linux distribution. Debian-based distributions (Ubuntu, Linux Mint, etc.) use the apt-get or aptitude commands for this purpose. The first option is simplified, the second has more functionality. Some actions, such as installation and removal, must be performed as root, or the command sudo must be used.

sudo apt-get update - Get a new list of packages.

sudo apt-get upgrade - update programs, before that you need to update the package list by running the previous command. It is advisable to execute both commands periodically (often this is done automatically), as well as before installing new programs.

sudo apt-get install mc - installs the mc program.

sudo apt-get remove mc - remove mc. Red Hat-based distributions that use RPM packages often use the yum manager.

yum update - system update.

yum install mc - installation of the mc program.

yum remove mc - remove the mc program. There are other package managers and software installation options.

Network commands and work with remote computers

ping - ping a specific address on the network. ping google.com - check the availability of google.com, you can also use the IP address: ping 192.168.1.5 . If there is no answer, this does not mean 100% that there is no connection, sometimes the work of this command is blocked on the network.

traceroute - shows the traffic route. For example: traceroute google.com . Allows you to determine where the problem is occurring.

telnet - connection to a remote computer. Enables you to execute commands on another computer. It is mainly used on the internal network as traffic is not encrypted. Example: telnet 192.168.1.1 .

ssh - connection to a remote computer via an encrypted channel. ssh [email   protected] - connection to the site.com server of the user alex. To connect via a non-standard port, use the -p switch, for example

ssh -p 12345 [email   protected] - connecting to the server 111.222.123.123 of the root user through port 12345.

ftp - connection to a remote computer using the file transfer protocol. ftp site.com - connects to the site.com server.

sftp - the command is similar to ftp, but the connection is made using an encrypted protocol.

route -n - shows the routing table.

ifconfig - information about network connections and their settings.

hostname - displays or changes the network name of the computer.

whois site or IP-address - displays information about the domain, the owner of the domain name or IP-address, for example whois google.com or whois 8.8.8.8 .

dig - Displays DNS information, such as dig google.com . You can contact any DNS server by specifying it as follows: dig @ 8.8.8.8 google.com . You can also use the host and nslookup programs to retrieve information from the DNS server, followed by the domain name or IP address, but these utilities have less functionality thandig .

wget is a program for downloading files, pages, sites from the Internet. wget http://site.com - load the main page of site.com. wget -r -l 10 -k http://site.com - will load the entire site.

lynx , links , links2 (3 separate commands) - text browsers, allow you to view sites directly from the console.

Administration Commands

su - change user. su alex - will change the user to alex. By typing su without parameters, you will get superuser (root) rights, and the hint character $ will change to # .

You should not be in this mode all the time, but rather not use it at all, but use the sudo command.

To exit the session and return to the previous user, type exit .

sudo - allows you to run other programs as superuser, typed before another command, for example

sudo rm file - will delete a file created by any user.

sudo -i or sudo -s are analogous to su .

You should also use the sudo command very carefully and only if necessary.

passwd - change the password of the current user. passwd alex - change the password for user alex.

adduser or useradd - add a new user. adduser katya - add user katya. After typing the command, you need to enter the password. You need to be superuser to execute the command.

userdel - delete a user. userdel vasya - removes user vasya.

groupadd - create a new group. groupadd students - will create a group students.

groupdel - deleting a group. groupdel students - will remove the students group.

chmod - change the permissions of a file or directory. chmod 644 file - will set 644 permissions on the file. chmod + x file will give the file execute permissions.

chown - change the file owner. chown alex file - as a result of this command alex will become the owner of the file.

chgrp - change the file group. chgrp students laba1 - change the group of the file laba1 to students.

Commands for working with processes

ps - display a list of processes. ps axu - view all processes. ps axu | grep win - display all processes that contain "win" characters.

kill - kill the program, after the command is indicated the program number (process identifier - PID), which can be found using the ps command. Example: kill 1234 .

killall command - kills all processes started with the specified command.

bg - continue the program in the background, for example, after the Ctrl + Z key combination. The command may be followed by the PID:

bg 1234 . fg - continue the program execution as usual, PID can also be specified.

Other Linux commands and programming languages

Some commands from this list may not be present in standard distributions, they can be installed separately.

sed is a powerful text processing utility.

awk is a language for processing text.

grep is a text search utility using regular expressions, often used in conjunction with other commands. grep '^ a' 'text.txt' - will show all lines in text.txt that start with the letter a.

emacs is an advanced text editor with many features, including built-in games. For advanced users.

gcc is a C compiler that can be used to obtain executable files of programs that are distributed in source codes. Or compile your programs.

gcc hello.c -o privet - compilation of the hello.c program, the result of the compilation will be a program named privet. By default (without the -o option) the output file will be named a.out. GCC is a whole set of compilers (GNU Compiler Collection). In addition to C, there is support for programs in C ++, Fortran, Ada, Objective-C, Java and Go.

g ++ is the C ++ compiler from GCC. perl is a powerful scripting language.

python - invoke the Python interpreter. It is a modern and powerful language that can be recommended for beginners.

exit - termination of the current session, can be used to disconnect from a remote computer, close the terminal.

shutdown -h now - command to shutdown the system, shutdown the computer. The analogue is the halt command. If you use the -r switch instead of the -h switch, the system will reboot. You can specify the time after which the command will be executed. Now means now.

shutdown -r +10 - restart the computer in 10 minutes. The -c switch cancels command execution. You must be root to execute the command.

reboot - computer reboot, similar to shutdown -r .

The Topic of Article: Linux Commands.
Author: Jake Pinkman


LiveInternet