Linux manual-Basic commands (1)

Source: Internet
Author: User
Tags uncompress

Before you log on, you must first apply for a user registration name from the system administrator. No matter which computer the user logs on to ITPNET, the user will access the same file system.

1.1 Login

When a Login prompt appears on the screen, you can enter your own User Registration Name and press Enter.

If you have a password, the system prompts the user to enter the password and press the Enter key. After the password is entered correctly, the user logs on

. At this time, some information and command prompts are displayed on the screen. For example:

Login: guest [Enter]

Passwd: ****** [Enter]

Sun %

Note: The user name must be input in lower case letters, and UNIX systems are case sensitive letters.

1.2 exit

When you are about to exit your computer account, you can enter logout or exit or press

[Ctrl-D]. When Login appears on the screen, the user can safely leave the computer. For example:

Sun % logout [Enter]

Login:

1.3 Change Password

To prevent others from using your account, use the passwd command to modify only

The password is generally composed of 6 to 8 letters and numbers. For example:

Sun % passwd [Enter]

Old Passwd :******

New Passwd :******

Retype New Passwd :******

Note: When you log out of the system and log on again, you must use a new password.

2.1 display directory

Command: pwdprint working directory)

Format: pwd

Function: displays the full path name of the current working directory.

Example: % pwd

2.2 create a directory

Command: mkdirmake directory)

Format: mkdir directory_name

Function: Creates a new directory.

Example: % mkdir directory

2.3 change Directory

Command: cdchange directory)

Format: cd directory_name

Function: changes the current working directory.

Note: directory name options include:

(1) Go to the subdirectory under the current directory.

(2) .. indicates to go to the parent directory of the current directory.

(3)/indicates to go to the root directory.

(4) If there is no option, go to the user's home directory.

Example: % cd directory

2.4 delete a directory

Command: rmdir (remove directory)

Format: rmdir directory_name

Function: Delete the sub-directory name of a non-existing file.

Note:

(1) When deleting a sub-directory, the deleted directory must not contain any files or sub-directories; otherwise, the sub-directories cannot be deleted.

(2) If the deleted directory contains files or subdirectories, see the command rm-r directory_name.

Example: % rmdir directory

3.1 list file directories

Command: ls (list)

Format: ls [option] directory_name

Function: lists the file names and subdirectory names in a specified directory. List the current directory if no sub-directory name exists.

File Name and subdirectory name.

Option:-a lists all files, including hidden files starting with a vertex.

-L list file names in long format, including file type identifiers, permissions, links, and file master names,

File Group Name, number of bytes, and date.

-R: list all files in subdirectories

-G indicates the user group ID in the long format.

-T sort the generation Date of the security file.

Example: % ls-la

3.2 display file content

Command: cat (catenae)

Format: cat filename

Function: displays the file content.

Note: When the file content is displayed on the screen, press Ctrl + S to pause and press Ctrl + Q.

Key.

Example: % cat filename

3.3 display file content on screen

Command: more

Format: more filename

Function: displays the file content on one screen.

Option:

Note: There is a function key in the screen display process. The Space key continues the output of the next screen.

The output of one row; the q key jumps out of the more state;/the string query string is located; the key returns

Return to the previous screen.

Example: % more filename

3.4 Display file content by PAGE

Command: pg (page)

Format: pg [option] filename

Function: displays the content of a specified object by page. When a page of files is displayed, the last line will show waiting for use

User input command. You can enter the following commands.

Option: h displays the help commands that can be used in the pg command.

Q: exit the pg command.

[Return] displays the next page.

1. display the next line of the body

[Space] displays the next page

D/[Ctrl-D] Scroll the screen to a half screen.

N displays the next file described in pg command line.

P displays the previous file described in pg command line.

% Display the first page of the current page of the body.

/Pattern searches forward for the specified character pattern in the file.

? Pattern searches for the specified character pattern in the file.

Note: When the pg command is displayed at the end of the file, an end of file (EOF file) is displayed ).

Example: % pg filename

3.5 read files

Command: view

Format: view filename

Function: only the file content can be read.

Note: This command cannot write the read source file. If you modify the original file, you can

Run the command ": w newfilename" to write the modified file to the new file.

Example: % view filename

3.6 display the file header

Command: head

Format: head [option] filename

Function: displays the file header.

Option: the first 10 lines of the file are displayed by default.

-I: displays the start line of the file.

Example: % head filename

3.7 display the end Of the file

Command: tail

Format: tail [option] filename

Function: displays the end of a file.

Option: the last 10 lines of the file are displayed by default.

-I: displays the last line of the file.

+ I is displayed from row I of the file.

Example: % tail filename

3.8 display formatted File Content

Command: pr (print)

Format: pr filename

Function: display formatted file content on the screen, that is, print 66 lines of text files per page, including 5

The header of the row and the end of the five rows. The header of the page contains two blank lines, one line containing the file time and file name

And page number. The other two are empty rows. There are five blank lines at the end of the page.

Example: % pr filename

3.9 copy an object

Command: cp (copy)

Format: cp [option] filename1 filename2

Cp [option] filename... directory

Cp-r directory1 directon2

Function: Copies all the content of a file to another file. You can also copy one or more files.

To another directory.

Option:-I copy the file as prompted.

-P: copy the original file.

-R copies all files in the subdirectory.

Note: When filename1 is copied to filename2, if filename2 already exists, filename2

Will be overwritten by filename1.

Example: % cp filename1 filename2

3.10 rename a mobile file or file

Command: mv (move)

Format: mv filename1 filename2

Mv filename... direction

Mv direction1 dire2

Function: Change the name of a file or directory, or move some files to another directory.

Note: When filename1 is renamed to filename2, if filename2 already exists, filename2

Content will be overwritten by filename1

Example: % mv filename1 filename2

3.11 delete an object

Command: rm (remove)

Format: rm filename

Rm-r direction

Function: delete a specified file or a file in a directory.

Note: When the-r option is used, the files used in the specified directory, including the directory name, will be deleted.

Example: % rm filename

3.12 link file

Command: ln (link)

Format: ln [option] filename linkname

Ln [option] directory pathname

Function: Creates a chain for a file or directory. Here, filename and directory are the source file names and

Source directory name; linkname and pathname indicate

File or directory.

Option:-s creates a symbolic link for a file or directory.

Note: The purpose of the link is to assign more than two names to a file or directory so that it can output

In different directories, files or directories can be shared and disk space can be saved.

Example: % ln-s filename linkname

3.13 change the File Read Permission

Command: chmod (change mode)

Format: chmod {u | g | o | a} {+ |-| =}{ r | w | x} filename

Chmod [who] [op] [mode] directory

Function: Change the read/write and execution permissions of a file. The signed method and the octal digit method.

Option: (1) Symbolic method:

U (user) indicates the user himself.

G (group) indicates the same group of users.

O (oher) indicates other users.

A (all) indicates all users.

+ Permission granted to a specified user.

-Cancels the permission granted to a specified user.

= Grant the permitted permissions to the file.

R (read) indicates that the content of the file or directory can be copied.

W (write) write Permission indicates that the content of the file or directory can be modified.

X (execute) indicates that you can execute the file or enter the directory.

(2) octal digit method:

This method uses the three-digit octal number as the option. Each digit represents the user and the group respectively.

Permissions of users and other users, including:

4 (100) indicates readable.

2 (010) indicates writable.

1 (001) indicates executable.

Note:

Example: % chmod a + rx filename

Allows all users to read and execute file filename.

% Chmod go-rx filename

Cancel the read and execute file filename permissions of the same group and other users.

% Chmod 741 filename

Enable read/write execution by myself, readable by users in the same group, and executable file filename by other users.

3.14 change File Ownership

Command: chown (change owner)

Format: chown username filename

Chown-R username directory

Function: changes the ownership of a file or directory.

Option:-R changes the owner of all files and directories in the directory.

Note: Only the file owner and superuser can change the ownership of the file.

Example: % chown username filename

3.15 search for files

Command: find

Format: find pathname [option] expression

Function: search for a file that matches the expression under the given path.

Option:-name indicates the file name.

-User Username: select the file to which the user belongs.

-Group name: select the files belonging to the user group.

-Mtime n: select the file to be modified in n days.

-Newer fn: select a file that is modified later than the file name fn.

Note:

Example: % find.-name '* abc *'-print

3.16 search for matching characters in a file

Command: grep

Format: grep [option] pattern filenames

Function: searches the specified file or standard input row by row, and displays each row in the matching mode.

Option:-v: Find out the row with Mode Mismatch.

-C: count the number of matched rows

-N: each row in the matching mode is displayed.

Note:

Example: % ps-aux | grep R

3.17 compare different files

Command: diff (difference)

Format: diff filename1 filename2

Function: displays the differences between the two files.

Option:

Note:

Example: % diff file1 file2

3.18 comparison files

Command: cmp (compare)

Format: cmp [-l] [-s] filename1 filename2

Function: Display and compare the information of two different files

Option:-l indicates the number of different bytes for the two files.

-S does not display the differences between the two files, and the comparison result is given.

Note:

Example: % cmp file1 file2

3.19 comparison file co-location

Command: comm (common)

Format: comm [-123] filename1 filename2

Function: select or reject the common lines of the two files

Option:-1 does not display column 1st

-2 Column 2nd is not displayed

-3 columns not displayed

Note: three columns are output. The first column indicates the row that appears in file1, and the second column indicates that the row appears in file2.

The row. The third column indicates the row that appears together in file1 and file2.

Example: % comm file1 file2

3.20 sort files

Command: sort

Format: sort [option] filename

Function: sorts the specified files according to requirements.

Option:-r in reverse alphabetical order

-N: sort by number values from smile to big

-R: sort by the current sorting rule in reverse order

-F case-insensitive sorting

-D. sort by typical order

Note: The options are sorted by ascii codes in short time.

Example: % sort-nr file

3.21 compressed file

Command: compress

Format: compress [option] filename

Function: compress a file.

Option:-f force Compression

-V compression display compression percentage

Note:

Example: % comproess files

3.22 decommission files

Command: uncompress

Zcat

Format: compress [option] filename

Zcat filename

Function: Expand or display compressed files.

Option:-c does not change file writing to standard output

Note: The zcat command is equivalent to uncompress-c.

Example: % uncomproess files. Z

3.23 display file type

Command: file

Format: file filename...

Function: determines the file type based on the file content, such as text, ascii, C, executable, and core.

Option:

Note:

Example: % file *

3.24 create an archive

Command: tar (tape archive)

Format: tar [option] tarfile filename

Function: Create an archive or read archive file.

Option:-c. Create a new archive file.

-X reading files from archive files

-V: displays the information of the processed file.

-F specifies the file name. The default value is/dev/rmt/0.

-T list the information of the archive file

Note:

Example: % tar cvf tarfile.

% Tar xvf tarfile

% Tar tvf tarfile

3.25 copy files on tape

Command: dd

Format: dd [option = value]

Function: use a tape drive to convert or copy files.

Option: if = name indicates the input file name.

Of = name specifies the output file name

Ibs = n specifies the size of the input file block to n Bytes. The default value is 512 bytes)

Obs = n specifies the size of the output file block to n Bytes. The default value is 512 bytes)

Note:

Example: % dd if = filename of =/dev/rmt/0

% Dd 'if =/dev/rmt/0 of = filename ibs = 1024

3.26 file modification date

Command: touch

Format: touch filenae

Function: changes the date of a file. The file content is not modified. If the file does not exist, a new file is created.

Option:

Note:

Example: % touch file

3.27 words in the statistics File

Command: wc (word characters)

Format: wc [option] filename

Function: counts the number of lines, characters, and characters in a file.

Option:-l number of statistics files

-W words in the statistics File

-C: number of characters in the statistics File

Note: If the default file name is used, standard input is used.

Example: % wc file

3.28 check spelling

Command: spell (spelling)

Format: spell [option] filename...

Function: check spelling errors in files.

Option:-B checks by UK spelling

-V: Display words that are literally not in the spelling dictionary

-X shows every reasonable root word

Note:

Example: % spell file


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.