UNIX operating systems are widely used on modern servers of various processor architectures, workstations, network and mobile devices. The term "UNIX command" refers to the family of multi-user operating systems. The graphical interfaces of the OS are diverse. But for Mac or Linux users who want to get the most out of their operating system, be sure to get familiar with the Unix command line.
UNIX History
The first version of UNIX was developed in 1969 by Ken Thompson at Bell Laboratories using PDP-7 downtime, and Dennis Ritchie soon joined him.
UNIX was originally intended to be used internally by the Bell System for programmers. Thompson and Richie worked for many years to develop various versions of UNIX. Ritchie developed the C language to support UNIX. The third version was related to rewriting the OS on C. As UNIX progressed, it became widely used in AT&T, and since the source code was available, it was gradually adopted by other organizations in the field of computer science. One of the most important advances made at UNIX by Berkeley programmers has been to provide support for Internet Protocol (TCP / IP).
In 1988, BSD, AT&T UNIX, and other operating systems were merged into UNIX System V.4. This new generation of OS has combined the best features of its predecessors to become the standard and foundation for AT&T UNIX, SUNOS Sun Microsystems, IBM AIX and HP-UX HP.
OS advantages:
- UNIX provides multi-user, multi-tasking, secure RAM, using the minimum amount of memory.
- Provides strong user protection through account verification and authentication.
- Simplifies I / O operations.
- It is very portable, which means that it can run on several different hardware platforms, which makes it easy for users to install on any equipment that they prefer to use.
The main components of the operating system
The main components of the UNIX OS are simple and not numerous, the interaction of these components with each other is unique. The three main components of a UNX system are:
- Kernel (KERNEL).
- Shell (SHELL).
- File system.
The UNIX kernel manages the physical RESO urces of the hardware computer, devices, memory, processes d (daemons). Manages functions between system programs and hardware and executes all the basic UNIX commands.
The kernel controls the following elements:
- File system and structures.
- Device management, such as storing data on disk.
- Process management, such as daemons.
- Memory management, such as swap space.
A shell is an interface between the user and the kernel. She acts as a shell. It accepts the basic UNIX commands issued by the user, interprets them, and then sends the executable to the kernel. The three most common shells are: Bourne, C, and Korn. There are also popular open source shells such as Z and bash, both of which are extensions of Bourne.
To identify the one used in UNIX, for example, for zsh, the UNIX echo command is executed:
- echo $ SHELL;
- / bin / zsh.
A file system is a hierarchy of directories, subdirectories and files that are organized or grouped for special purposes, all that is under the system call interface. The hardware provides a file system, a process control subsystem, memory and OS management over system calls. Programmers use kernel calls to deploy useful functions, to compile and manipulate examples.
Development environment
The programmer interface on UNIX is defined by calls. Most UNIX system programs are written in C, and all calls are C functions. Since call details are known only to the compiler, this makes portability the main function of UNIX programs. System calls for file manipulation are, for example: creat, open, read, write, close, link, unlink and trunc.
A new process is created by calling fork. A process is a copy of the process space of the parent process that calls fork.
Signals are used to handle exceptions. There are 20 different signals on UNIX. For example, an interrupt signal is used to interrupt a command before completion of the execution, usually performed by the user.
Disadvantages of the command line:
- Some tasks are difficult or impossible to do on the command line.
- Tasks that require a lot of typing, such as long file names, can be annoying and tiring due to the lack of minimal cut support.
- For most people, learning and remembering typed commands is difficult if they don't use commands all the time.
Feature Benefits:
- In almost all cases, it is much faster and easier to use for experts, and not for beginners.
- It can be used remotely with more ease than the GUI.
- The remote GUI is SLUGGISH.
- When absolute precision is needed, the mouse / GUI is too inaccurate.
- For complex tasks, the command line can be scripted to automate processes.
User interface
UNIX developers and users can use programs that are already compiled and available for execution. These programs can be divided into functions, for example, directory and file processing: mkdir, ls, touch, file, rm, link, unlink, cat UNIX command, a program for sorting sort files, for comparing diff files, for finding grep and awk patterns . In addition, text editors such as vi, vim, sed and others are available. These commands are executed by the user interpreter or shell.
Standard I / O refers to the three types of files that a process can open. They are known as standard input (file descriptor 0), standard output (1), and standard error (2). The program can read from standard input and send output to the user's screen or to a file with standard output.
The user can send standard output to a file named test1 or send test1 files as input to the program:
- [mbeuses @ myserver linuxacademy] $ ls> test1;
- [mbeuses @ myserver linuxacademy] $ lpr <test1.
UNIX has three main categories of I / O:
- blocking devices;
- character devices;
- sockets for network communication.
Block devices, this category includes disks and tape. A block device is essential for isolating disk parts from the rest of the kernel. Block devices are accessible through a system file. Example: / dev / sda the first scsi drive on the first scsi bus, the first scsi drive on the first scsi bus.
Character devices, this category includes printers, terminals. Example UNIX terminal authentication command: / dev / null a bit bucket or bottomless sink for data.
To display the block and character devices in the system, execute the following command in the shell. Truncated output shows some / dev devices on a UNIX server.
Traditional OS commands
No matter which shell the user uses, whenever the command is entered, it will run the UNIX program. A simple example for counting the number of files in the / etc: IDG directory.
This sequence of commands illustrates two important concepts:
- the ls UNIX equivalent dir command on Windows displays the contents of a directory;
- number of words wc.
On UNIX, parameters are traditionally prefixed with a single dash “-”. These command line options change the behavior of the program. Often they override the default values set in the environment. If you need to change the way the command is conducted on an ongoing basis, they automatically set the environment variable when entering the system. Many commands allow you to combine parameters in one line, for example, ls – la, but others do not. You can learn about all options for a team by checking its manual or man page.
Learning and using string parameters is a big part of UNIX efficiency. Some commands have a lot of options, but usually just a few options for performing a given task are enough, and most parameters are used only when writing programs in the shell language.
There are many commands related to the file system, since it is fundamental to the OS.
The ls command is used most often, and it has many options for setting output. Point files (files or directories) whose names begin with a period or period are hidden by default. These files or directories typically contain configuration information or logs for UNIX. For example, a .bash_history file records all the commands that are entered in a string.
Another command that you will need immediately is cd, it is used to change directories. It is similar to that in Windows, but with a significant difference. On UNIX, all drives appear as a single drive. If on Windows you can have your pictures on an external hard drive that displays as E :, on Unix, this drive might be / home / user / pictures.
The pwd command prints the working directory. Since there are many places that can be lost in a growing file system, it allows you to quickly determine where the user is.
Disk space
Loading disk space is a gradual process that can take years. There are two commands that you need to use to check free space and determine which files clog the disk: du using the disk and df without the disk. They both choose the h option. To understand how full the disk is, use the UNIX filter df command.
In order to find out how space is used, type du and limit the output to the first 10 lines. Otherwise, it will appear in every directory on the machine, which may be too complicated to understand. From this list you can see how much space is consumed by each directory. By combining several teams together, they put together a script that will list the top 10 directories for space use. The command needed to sort the output is sort.
Since the MacOS version cannot process du data for human reading, use the m-option to du-display disk usage in megabytes, the g or k parameter displays data in gigabytes or kilobytes, respectively. The parameters n and r are used to sort (sort the output) in the forward and reverse order, so the largest directories appear at the top of the list.
Superusers su and sudo
A number of commands relate to system administration. The main team for system administration is su. This means superuser and refers to the administrator account or root user. All files belonging to the system belong to this user.
The associated sudo allows you to become superuser for one team. Why use sudo instead of su? Practice shows that this is necessary so that the user does not often use root, because of the possibility of causing irreparable harm to the system. It is better to do everything possible (in the status of a regular user) and becomes a superuser only when it is absolutely necessary. Obtaining superuser privileges will depend on the UNIX distribution.
Sometimes the current user does not have su permission. In some wheel-systems, this means that the user must be in a group, and in other OSs, including MacOS, the user must be in a sudoers-file.
Naturally, to add a user to sudoers, the file requires root privileges. To do this, log out of the account and log in to the administrator account. Then run sudo nano / etc / sudoers on the command line, Nano will open the sudoer file in the terminal window, ready for editing.
Navigate through a file in Nano using the arrow keys. To make nunez, scroll down to the "User Privilege Specification" section and enter the line: nunez ALL = (ALL) ALL, for root users and min users.
When you enter Ctrl + x, enter “Yes” to save the changes and exit Nano.
Advanced System Operators
Enhanced UNIX commands enable you to perform various tasks on UNIX, giving you more control over data and actions.
File Operations:
- chmod;
- chown;
- basename
- ln - create links and symbolic links to files and directories;
- find - search for files and directories;
System Status Commands:
- last;
- w;
- who –r;
- uname
- lsb_release - Find information about the Linux Base Base (LSB).
Privileged Access:
- su;
- sudo - run commands with elevated root privileges;
- visudo - Securely edit the / etc / sudoers file.
Advanced process management:
- ps –aef;
- ptree
- kill;
- nice;
- renice;
- pmap;
- pfiles
Text manipulation commands:
File System Commands:
File System Management:
- Mount;
- Umount
- Fsck;
- Growfs;
- tune2fs - setting parameters of a custom file system (for ext2 / ext3);
- mkfs;
- Networking
- iptables - manage firewall rules on a Linux server;
- netstat;
- traceroute.
Cat file display command
The Linux cat command is used to display the contents of text files and merge several files into a single file, unlike the ls UNIX command, which lists the contents of file directories and directories. Keep in mind that cat does not accept directories.
The parameters cat are presented in the table.
Option | Description |
cat -b | add line numbers to non-empty lines |
cat -n | add line numbers to all lines |
cat -s | compress blank lines on one line |
cat -E | show $ at the end of the line |
cat -T | show ^ I instead of tabs |
Examples of cat UNIX commands.
View text file data:
- $ cat list1.txt;
- milk
- bread;
- apples
- $ cat list2.txt;
- house;
- car;
- $.
Combine 2 text files:
- $ cat list1.txt list2.txt;
- milk
- bread;
- apples
- house;
- car;
- $.
Combine 2 text files into another file:
- $ cat list1.txt list2.txt> todo.txt;
- $.
Key Search Examples
The first find Linux example searches through the root file system (/) for a file named Chapter1. If it finds a file, it prints the location on the screen: find / -name Chapter1-type f -print.
On Linux and UNIX systems, the print parameter is no longer needed at the end of the find command, so you can get it as follows:
- find / -name Chapter1-type f;
- -type f.
This option runs a search command to return only files. If not used, it will return files, directories, and other items, such as named pipes and device files, that match the specified name pattern. If the user does not need this, just leave the option with the command: type f.
The following find searches only with the / usr and / home directories for any file named Chapter1.txt: find / usr / home -name Chapter1.txt -type f.
To search the current directory and all subdirectories, simply use the symbol to refer to the current directory in the find UNIX command, for example: name Chapter1 -type f.
The following example searches the / usr directory for all files starting with the letter Chapter. A file name can end with any other combination of characters. It will match file names such as Chapter, Chapter1, Chapter1.bad, Chapter in the life: find / usr -name "Chapter *" -type f.
The following command searches the / usr / local directory for files ending with the .html extension. These file locations are displayed: find / usr / local -name "* .html" -type f.
WC for counting the number of lines, words, characters
The UNIX and Linux WC command is used to find out the count of a new line, the number of words, bytes, and count characters in the files specified by the file arguments. The syntax for the wc command is:
# wc [options] file names
The following are the options and uses provided by the team.
- wc -l: prints the number of lines in a file.
- wc -w: prints the number of words in a file.
- wc -c: displays the number of bytes in the file.
- wc -m: prints the number of characters from a file.
- wc -L: prints only the length of the longest line in the file.
Basic wc example:
The wc command without passing any parameter displays the main result of the tecmint.txt file. The three numbers below are: 12 (number of lines), 16 (number of words) and 112 (number of bytes) of the file.
[root @ tecmint ~] # wc tecmint.txt 12 16 112 tecmint.txt.
To count the number of lines in a file, use the l parameter, which prints the number of lines from a given file. Say the following UNIX command will show the number of lines in a file. In the output, the first name is assigned as count, and the second field is the file name.
[root @ tecmint ~] # wc -l tecmint.txt 12 tecmint.txt.
To count the words in the file, enter the following command:
[root @ tecmint ~] # wc -w tecmint.txt 16 tecmint.txt.
When using the c and m options with the wc command, the total number of bytes and characters in the file will be printed:
[root @ tecmint ~] # wc -c tecmint.txt 112 tecmint.txt.
[root @ tecmint ~] # wc -m tecmint.txt 112 tecmint.txt.
The wc UNIX command allows you to use the L argument; it can be used to print the length of the number of characters in a file. The longest Scientific Linux character string in the file.
[root @ tecmint ~] # wc -L tecmint.txt 16 tecmint.txt.
Display a line of text echo
Echo is the fundamental command of a UNIX system, also used on most other operating systems that offer a string. It is often used in scripts, files, and as part of separate commands, when you may need to insert text. Many shells such as bash, ksh, and csh implement echoes as a built-in command.
Tag | Description |
-n | Do not output the final new line |
-e | Enable interpretation of backslash escape sequences (see list below) |
-E | Disable interpretation of backslash escape sequences (this is the default value) |
--help | Display help message and exit |
--version | Display exit information and exit |
\\ | Backslash literal character (\) |
\ a | Warning (BELL symbol) |
\ b | Return to one position. |
\ c | After that, do not create any additional results. |
To print the line “Hello world!”, Write the command of the UNIX console:
- $ echo "Hello world!"
- output: Hello world !.
Executing shell commands from vi
You can run UNIX commands and view their output without leaving vi, and you can also paste its output into a file that you are editing.
They start and use the shell in the same way as a regular UNIX environment, and then exit the shell and return to vi.
The type of shell to be started is determined by the UNIX command $ SHELL variable. To start another, you must set the vi shell option. Revert to using vi by typing exit or Ctrl-D. To insert output from into a file, immediately after the cursor:
r! command
The vi UNIX command is interesting when used for documentation when you need to include sample output.
UNIX makes an excellent platform for service servers such as Domain Name System or DNS, Dynamic Host Configuration Protocol or DHCP, and Web servers. Its architecture conserves resources for real applications that need to be used not only to load the operating system itself. UNIX also provides a stable and secure platform for applications that do not require direct interaction with the operating system.