Ten commands required for Linux commands and ten commands for linux

Source: Internet
Author: User

Ten commands required for Linux commands and ten commands for linux

Linux has now become the most popular Operating System in the software industry. Mastering Linux has become a required professional skill for every developer.

In order to help you learn, I hope you can master the ten commands that you must master when using Linux.

1. cd command

Linux cd command is used to switch the current working directory to dirName (DIRECTORY parameter ).

DirName can be an absolute or relative path. If the directory name is omitted, it is changed to the user's home directory (that is, the directory where the login is located ).

In addition ,"~" It also indicates the home Directory, "." indicates the current directory, and "..." indicates the previous directory at the current directory location.

Syntax
cd [dirName]

DirName: target directory to be switched.

Instance

Jump to/usr/bin /:

cd /usr/bin

Go to your home directory:

cd ~

Jump to the top two layers of the current directory:

cd ../..
2. ls command

The Linux ls command is used to display the content in the specified working directory (list the files and subdirectories contained in the current working directory ).

Syntax

Ls [-alrtAFR] [name…]

Parameters

-A: displays all files and directories. (If the name or directory name starts with "." is specified in ls, it is regarded as a hidden file and will not be listed)
-L in addition to the file name, the file type, permission, owner, file size, and other information are listed in detail.
-R: Display files in reverse order (originally in alphabetical order)
-T list files in the order of creation time
-A is the same as-a, but "." (current directory) and "." (parent directory) are not listed)
-F Add a symbol after the name of the listed file. For example, add "*" to the executable file, and add "/" to the directory.
-R if the directory contains files, the following files are listed in sequence.

Instance

 

List all directories under the root directory:
# Ls/
Bin dev lib media net root srv upload www
Boot etc lib64 misc opt sbin sys usr
Home lost + found mnt proc selinux tmp var
List all files whose names start with "s" in the current working directory:
Ls-ltr s *
List all the following directories and file details in the/bin directory:
Ls-lR/bin
List all files and directories in the current working directory. Add "/" after the directory name, and add "*" after the executable file name:
Ls-AF

3. grep command

The Linux grep command is used to find the matching strings in the file.

The grep command is used to find files whose content contains the specified template style. If the content of a file conforms to the specified template style, the default grep command displays the column containing the template style. If no file name is specified or the given file name is "-", the grep command reads data from the standard input device.

Syntax
Grep [-abcEFGhHilLnqrsvVwxy] [-A <display columns>] [-B <display columns>] [-C <display columns>] [-d <action>] [-e <template style>] [-f <Template File>] [-- help] [template style] [file or directory...]
Common Parameters

-A: query the data of binary files as text files.

-C: calculates the number of times a 'query string' is found.

-I: Ignore the case sensitivity difference, that is, consider the case as the same

-V: reverse selection, that is, the row without the 'search string' content is displayed.

Example

# Retrieve the line containing MANPATH in the file/etc/man. config and add the found keyword to the color

Grep-color = auto'manpath'/etc/man. config

# Output the ls-l output containing the letter file (case-insensitive)

Ls-l | grep-I file

4. find command

The Linux find command is used to find files in a specified directory. Any string located before the parameter will be considered as the directory name to be searched. If you do not set any parameters when using this command, the find command searches for subdirectories and files in the current directory. In addition, all the subdirectories and files found are displayed.

Syntax
find   path   -option   [   -print ]   [ -exec   -ok   command ]   {} ;
Parameter description

Find judges the path and expression according to the following rules, and first-() in the Command column -(),! The previous part is path, followed by expression. If path is a Null String, use the current path. If expression is a Null String, use-print as the default expression.

There are more than 20 or 30 options available in expression. Here, we will only introduce the most commonly used options.

-Mount,-xdev: Only checks files in the same file system as the specified directory to avoid listing files in other file systems.

-Amin n: Read in the past n minutes

-Anewer file: The file that has been read later than the file.

-Atime n: Files Read in the past n days

-Cmin n: modified in the past n minutes

-Cnewer file: The file that is updated later than the file.

-Ctime n: Files modified in the past n days

-Empty: empty file-gid n or-group name: gid is n or group name is name

-Ipath p,-path p: The file whose path name is p-compliant. ipath ignores case sensitivity.

-Name,-iname name: name of the file that matches the name. Iname ignores case sensitivity.

-Size n: the file size is n units. B indicates the block of the 512-bit tuples. c indicates the number of characters, k indicates kilo bytes, and w indicates two-bit tuples. -Type c: the file type is c.

D: Directory

C: font Device File

B: block Device File

P: named storage Column

F: General Files

L: Symbolic Link

S: socket

-Pid n: The process id is n.

You can use () to separate the operators and use the following operations.

Exp1-and exp2

! Expr

-Not expr

Exp1-or exp2

Exp1, exp2

Instance

List all files with c extension files in the current directory and Its subdirectories.

# find . -name "*.c"

List all common files in the subdirectories of the current directory

# find . -ftype f

List all files updated in the last 20 minutes in the current directory and Its subdirectories.

# find . -ctime -20

Search for Common files that were modified seven days ago in the/var/logs directory and ask them before they are deleted:

$ find /var/logs -type f -mtime +7 -ok rm { } ;

The owner of the files in the preceding directory has the read and write permissions, and the users in the file group and other users have the read permissions:

$ find . -type f -perm 644 -exec ls -l { } ;

To find all common files with a length of 0 in the system and list their full paths:

$ find / -type f -size 0 -exec ls -l { } ;

Search for Common files that were modified seven days ago in the/var/logs directory and ask them before they are deleted:

$ find /var/logs -type f -mtime +7 -ok rm { } ;
5. cp command

The Linux cp command is mainly used to copy files or directories.

Syntax
cp [options] source dest

Or

cp [options] source... directory
Parameter description

-A: This option is usually used when copying a directory. It retains the link and file attributes and copies all contents in the directory. The function is equal to the dpR parameter combination.

-D: the link is retained during replication. The link mentioned here is equivalent to a shortcut in Windows.

-F: overwrite the existing target file without prompting.

-I: opposite to the-f option, a prompt is displayed before overwriting the target file, asking the user to confirm whether to overwrite the file. The target file will be overwritten when "y" is answered.

-P: In addition to copying the file content, it also copies the modification time and access permissions to the new file.

-R: if the source file is a directory file, all subdirectories and files under the directory will be copied.

-L: generate a link file without copying a file.

Instance

Run the command "cp" to copy all files under the current directory "test/" to the new directory "newtest". Run the following command:

$ cp –r test/ newtest          

Note: When you use this command to copy a directory, you must use the "-r" or "-R" parameter ".

6. mv command

The Linux mv command is used to rename a file or directory, or move a file or directory to another location.

Syntax
mv [options] source destmv [options] source... directory
Parameter description

-I: if the specified directory already contains files of the same name, first ask whether to overwrite the old file;

-F: do not give any instructions when the mv operation needs to overwrite an existing target file;

Mv parameter settings and running results

Command Format

Running result

Mv file name
Change the source file name to the target file name.

Mv file name directory name
Move the file to the target directory

Mv directory name
The target directory already exists.
Move to the target directory; Target
If the directory does not exist, rename it.

Mv directory name file name
Error

Instance

Rename the file aaa to bbb:

mv aaa bbb

Put the info directory into the logs directory. Note: If the logs directory does not exist, this command will rename info to logs.

mv info/ logs 

Another example is to move all the files and directories under/usr/student to the current directory. The command behavior is as follows:

$ mv /usr/student/*  . 
7. rm command

The Linux rm command is used to delete a file or directory.

Syntax
rm [options] name...
Parameters

-I ask for confirmation one by one before deletion.

-F the original file is deleted directly even if its attribute is set to "read-only". You do not need to confirm the attribute one by one.

-R also deletes directories and the following files one by one.

Instance

You can use the rm command to delete a file. If you delete a directory, you must use the "-r" option. For example:

# Rm test.txt rm: Do you want to delete the general file "test.txt "? Y # rm homework rm: the "homework" directory cannot be deleted: it is a directory # rm-r homework rm: Do you want to delete the "homework" directory "? Y

Delete all files and directories in the current directory. Command Behavior:

rm  -r  * 

Once the file is deleted using the rm command, it cannot be recovered. Therefore, you must use this command with caution.

8. ps command

The Linux ps command is used to display the status of the current process.

Syntax
ps [options] [—help]
Common Parameters

-A: all processes are displayed.

-A: All processes not related to terminal

-U: Processes of Valid users

-X: generally used together with parameter a. Complete information can be listed.

-L: long, detailed list of PID Information

Common combinations

Ps aux # view all process data of the system

Ps ax # view all processes not related to terminal

Ps-lA # view all process data of the system

Ps axjf # view the status of a part of the process tree together

9. kill command

The Linux kill command is used to delete programs or jobs in execution.

Kill can send the specified information to the program. The preset information is SIGTERM (15). You can terminate the specified program. If you still cannot terminate the program, you can use SIGKILL (9) Information to try to forcibly Delete the program. The program or job number can be viewed using the ps or jobs commands.

Syntax
Kill [-s <information name or number>] [Program] or kill [-l <information number>]
Parameter description

-L <Information No.> If the <Information No.> option is not added, the-l parameter lists all information names.

-S <information name or number> specifies the information to be sent.

[Program] [Program] can be the PID or PGID of the program, or the work number.

Instance

Kill Process

# kill 12345

Force process killing

# kill -KILL 123456

Send the SIGHUP signal. You can use the following signal.

# kill -HUP pid

Completely kill the process

# kill -9 123456

Kill all processes of a specified user

# Kill-9 $ (ps-ef | grep hnlinux) // Method 1: filter out the hnlinux user process # kill-u hnlinux // method 2
10. cat command

The cat command is used to connect an archive string and send it to the Basic output (screen or add> fileName to another archive)

Permission

All users

Syntax format
cat [-AbeEnstTuv] [--help] [--version] fileName
Parameter description

-N or-number indicates the number of all output rows starting from 1.

-B or-number-nonblank is similar to-n, except that the blank row is not numbered.

-S or-squeeze-blank when there are two consecutive blank rows or more, it is replaced by a blank row

-V or-show-nonprinting

Instance

Add the row number to the file content of textfile1 and enter textfile2.

cat -n textfile1 > textfile2

Add the row number to the file content of textfile1 and textfile2 (blank rows are not added) and then append the content to textfile3.

cat -b textfile1 textfile2 >> textfile3

Clear/etc/test.txt File Content

cat /dev/null > /etc/test.txt
Fixed Link: linux Learning Network-ten commands that must be mastered by Linux commands

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.