Beginners have learned about Unix (Linux).

This article

Now that you've learned Unix commands and terminology, I'll put them together in an article for review.

What is Unix?

First of all, I will talk about what Unix is in the first place. Like Windows and MAC, it is a type of OS used for servers that make up the Internet. In addition, there is a history that many free compatible OSs have appeared because they were distributed as open source for a while. ** Linux is especially recognized. ** There are many companies and organizations that distribute Linux with its own settings and configurations, and the distribution format is called distribution. All basic commands are standardized by the standard ** POSIX **. In addition, the interface that can be operated with a mouse is called GUI, and the interface that can be operated only with commands is called CUI.

Commands and terms

Command list

date Current date cal calendar

Up and down arrow keys

History of commands entered. Ctrl + c New prompt. Ctrl + u Clear the command. Ctrl + l Clear the entire screen. etc Various configuration files home A place that users can handle as they like var The location of the data managed by the app. Web and database data, LOG files, etc. bin Executable file sbin Executable file for management tmp temporary file

~(tilde)

The home directory of the currently logged-in user is represented by the ~ symbol. ls Check the contents of the directory ls -a View hidden files. ls -l See more detailed information. The displayed contents shown in blue are directories. ls --help Show what the options are with the ls command. Not only ls but also other commands can be searched in the same way. man ls Display a detailed description of the command. * A type of wild card. Any character string except dots with zero or more characters can be represented by *. ????? ?? Can represent any one character.

[2 letters of the alphabet] ??

Search for one that begins with either of the two letters of the alphabet. [f-h]* Search by starting with f, g, h.

{Arbitrary character, arbitrary character}

Search only for those that start with any specified character.

touch command

It updates the modification date and time of the file, but creates it if the file does not exist.

cp file name file name

Copy the first file you wrote to the second file.

mv file name file name

Rename the first file you wrote to the second file you wrote.

rm file name

Delete file

mkdir name

Creating a directory

mv file name directory

Move the file to the directory. Note: You can rename the directory.

rm directory / file

Delete the contents.

rmdir directory

Delete directory. mkdir -p Create directories up to a deep hierarchy. cp -r Copy all the contents of the directory. The default is for files. rm -r Delete everything, including the contents in the directory.

ln -s dir / dir / dir Your own name

Create a symbolic link. Change to a shorter name.

rm name decided by himself

You can remove symbolic links. cat Check the contents of the file. more A type of pager. The first page is displayed, and what percentage is also displayed. You can press the space key on the next page and the q key to exit. less You can search by using / word. Press the n key to move to the next search result, and use the space key and q key as above.

wc file name

Word count. From the left, the number of lines, the number of words, and the number of bytes are displayed by file name. However, in the case of Japanese text, the number of personal words may not be available. wc -l Display only the number of lines.

head -3 file

Display the first and last 3 lines.

tail -3 file

Display only the last three lines of the sentence.

grep'' file

Search for and display a specific word in the file. history Display the history of commands. !3 Display and execute the third command. !! Execute the previous command. ! - 2 Execute the previous command. !$ Display the arguments of the last command passed. !pw Execute the latest command starting with pw. !pw:p If: p is added, it will be displayed without execution. !! !! Execute with. Ctrl + r Search history Ctrl + c Search interruption /etc/passwd Display user list From left to right, separated by colons, passwords, user IDs, user group IDs, comments, home directory locations, and commands used as shells are displayed in that order. cat /etc/group View group.

groups username

Search for the group you belong to. chmod A command to change the access right. There are several ways to enter, and the user's access right is u group's access right. When changing all other access rights at once, it is expressed as a.

chmod a=r--r--r--file name
chmod g=rw,o=rw filename
chmod g+w,o-w file name

It is represented by. The other is a method shown in binary. r is 2 squared, w is 2 squared, and x is 2 0. For example, if you want to change the access right to rwxrwxrwx. 421421421 so

chmod 777 filename

It can be expressed as. sudo A command that allows you to work with root user privileges only when needed.

vi file name

On Unix, the vi editor comes standard. Enter the file name you want to create or edit and start it. Method of operation

I:Edit mode
esc:Command mode
:q:Exit editor
echo:Display string
:wq:Save
:q!:forced termination

export Instructions to set environment variables

export PATH=/home/Directory name:$PATH

Add the existing directory above to the beginning of $ PATH.

which file name

Check which directory the call is from.

redirect

Standard output redirection For example, when outputting a calendar to a file, it will be as follows.

command>file name
$ cal > cal.txt 

However, as a caveat,> is overwritten, so if the file has contents, it will disappear. So, in that case, use the following command to add it to the contents of the file.

command>>file name

Standard input redirection This is the same as setting arguments in a command. For example, $ cat cal.txt and the following are the same.

command<file name
$ cat < cal.txt

pipeline

You can write multiple commands by connecting commands with |. For example, suppose you want to extract a line containing the sudo string from the etc directory.

command|command
$ ls -l /etc/ | grep 'sudo'

Phrase expansion

You can create multiple strings and directories at once.

$ echo {a,b,c}
$ mkdir {hode1,hoge2,hoge3}

find File search function. You can specify a location and search by passing a character string by name, or use a wildcard to search.

$find file name
$find location-name 'hoge1.txt':hoge1.File called txt
$find location-name 'hoge*':Files starting with hoge

List of terms

$ Mark

Refers to general users.

~(tilde)

The home directory of the currently logged-in user is represented by the ~ symbol.

shell

The core of linux, like the shell that covers the kernel. An interface that returns search results from user commands and the kernel. Through the shell, it is responsible for interpreting and executing commands so that the kernel can be understood, and interpreting search results from the kernel so that they can be understood and returning them to the user.

Shell prompt

The part that is waiting for input. It is in the following state.

[username@Login machine name~] $

directory

Absolute PATH, relative PATH

When expressing a directory with a command, there are two types, absolute PATH and relative PATH. First of all, about absolute PATH. / /etc Expressed as / home / file name. Next, about relative PATH. .: Current directory ..: One directory above ../ ..: Represents the next higher directory.

Wildcard

A command that searches for and displays a specific item.

Symbolic link

Renames a deep directory to a shorter name.

Pager

A command to view page by page.

wc command

Perform word counting.

Users and groups

Users belong to a group, and unix is available to multiple users on a single computer and must be logged in first. Also, which user has what authority and what can be done is decided, and the directories that can be used differ for each user. And users are used in groups to make it easier to manage on the system. User and group information is managed in a file, and user information can be viewed in ** / etc / passwd **, and group information can be viewed in ** etc / group **. Also, the user can be a ** administrator (root user) or a general user **. The root user can perform all operations, but it is common to set a general user for each role so as not to make mistakes.

Access right

The left and center displayed by ls -l are related to access rights. The user and group that owns the file or directory created in the center are listed. Normally, the owning user and the group to which the user belongs are set.

Access right:-rx-r--r--

The left is displayed like this. First, the leftmost-means the file type. -Is a normal file, d is a directory, and l is a symbolic link. The next 9 characters are divided into 3 characters each, and from the left, the access right of the owning user, the access right of the owning group, and other access rights are shown. Also, r means read, w means write, and x means execute. Also, if it is a directory, x means it can be opened instead of executed. $PATH ** PATH is the name of an environment variable. An environment variable is a special variable that can be used in the local environment. ** Commands are managed by this environment variable. In Unix, data and settings are managed in files, and commands are actually managed in execution management files. When you enter the command, the shell is searching for and loading an executable file in your local environment. At this time, PATH is used as a means of searching. For example, echo to display a character string and cd to move a directory are in the PATH. Normally, you have to specify which environment variable directory you are in, but you can omit the ones in your PATH. Also, the command export is a command that defines environment variables, and you can add anything you want to add to your PATH.

redirection

You can switch between input and output of shell commands. By default, the standard input is the keyboard and the standard output is the screen, but the function that can switch between them is redirection. > >> The above two are standard output redirects < The above is the standard input redirect There is also a pipeline, which is the process of passing command input / output to another command. Input / output results can be freely manipulated by connecting small commands with pipes. | The above is the pipeline

Phrase expansion

By enclosing multiple character strings separated by commas with {} braces (curly braces), the enclosed character strings can be expanded.

Learn unix

I learned this time through dot installation. It was easy to get in because I had learned about Git in advance. I could easily understand basic commands such as cd to move between basic directories and absolute PATH and relative PATH to represent directories. The mechanism of environment variables and commands are also managed in files, and it was difficult to understand what the shell was searching for and executing when executing it. I think that what I understood this time is only the touch of Unix, so I would like to deepen my understanding and write an article in the future.

Recommended Posts

Beginners have learned about Unix (Linux).
What I learned about Linux
For the first time, I learned about Unix (Linux).
About Linux
About Linux
About Linux
About Linux
About Linux ①
[Linux] About export
[Linux] About PATH
Linux (about groups)
Linux (about directory path)
About Linux kernel parameters
LibYAML installation (Linux / Unix)
A story about creating a UNIX / Linux compatible OS from scratch
About Linux environment construction (CentOS)
Linux (About adding / removing users)
About python beginner's memorandum function
Linux distribution recommended for beginners
Linux command memorandum [for beginners]
Convenient Linux shortcuts (for beginners)