Linux Common High frequency commands (self-summary)

Source: Internet
Author: User
Tags parent directory

Linux Common High frequency commands (self-summary) using some command-line and shell programming in a Linux environment has been a long time trying to write an article about Linux command line and shell programming, but something has been shelved. Take some time today to write this article after verifying the high frequency commands that are commonly used under Linux. A lot of commands may have been used, but sometimes you may remember a little blurry. The system is listed here, hoping to have some help for themselves and others. creation and deletion of files or directories

1) Create files and directories

1) Touch file1 file2 file3

2) Mkdir-p dir1/dir11/dir111

- p (do not leave spaces in the middle) you can establish a cascading directory , and if this parameter is not present , The parent directory of the new directory must already exist .

3) Delete command RM(more powerful) with rmdir

Delete a directory tree rm–rf dir1

Description

1. The rmdir command is only used for removing empty directories. the rmdir dir1 command refuses to remove the directory because there are files under the dir1 directory . You can -rf parameters and remove them at once. However, please use caution because the command does not have any prompts.

2, RM command commonly used parameters are three:-i,-R,-F

- I.: Delete the operation, the system will ask us whether to delete files ;

-R: This operation can be deleted along with the subdirectories below this directory. Note that this feature is much more powerful than the rmdir command , not only to delete the specified directory, but also to delete files and subdirectories under that directory;

- F: This operation can forcibly delete files without system confirmation.

copying and moving of files

1) cp/home/jin/p/1.txt.

2) Cp-r means to copy together with subdirectories in the original file

3) MV Jin1/p/1.txt jin1/jin2: move files to the known directory

4) MV 1.txt 11.txt: rename 1.txt below the current directory to 11.txt

Show file Contents

1)cat 1.sh Display file contents ( -N for display line number)

Description :

1,cat 1.sh | More the contents of the file file1 are listed in pagination mode ;

2,cat 1.txt 2.txt in order to display the contents of 1.txt,2.txt ;

3.cat 1.txt 2.txt>3.txt put 1.txt,2.txt content together and redirect to 3.txt file.

2)gedit 1.sh display text content with gedit Editor (this command facilitates text viewing, editing, etc.)

3)vi 1.sh or vim 1.sh

See file or directory structure

1) ls-l

Description

1 Common file types: Contents (d) file ( - ) character device ( c ) block Device ( b l: link, n: Network file

2,-L (Long): The parameter generates a long list of tables ( each file or directory in the directory is listed using one line ).

2)tree # View the directory structure completed under the current directory

Description

1. It is not recommended to use the directory structure in a very complex context, such as the home directory ;

2. Encounter the tree command cannot be performed, first install the tree, in use this command.

-D lists only directory files

3)find will list every file in the directory tree under the current working directory

See specified file

1)ls-l | grep ^d Lists all directories in the current directory

Description

1. Syntax: Command 1 | Command 2

The execution result of command 1 is sent to command 2as input to command 2 .

2)Ls–l | grep ^- (- minus, not underlined ) # lists normal files in the previous directory

3)ls-l *.sh # lists the current directory . SH file

4)grep 1.txt 1.sh search file 1.sh contains the text content of the 1.txt line

5)grep 1 *

Find text content and file names in all files in the current directory that contain 1 ( case insensitive ) lines ( directory files are not included )

6)grep 1 *-n find the file with content 1 and the file name, show travel number

Description

1,-n write in the back or front can, other commands can also be with - n display line number, such as the back of the cat-n 1.sh


User Name related

1)wo am I or whoami View your user name

2)passwd

Description:

Syntax: passwd
Old Password: < Enter legacy password >
New Password: < Enter a password ( preferably 6~8 words, the English alphabet mixed with the number ) >
Retype new Password: < Enter password again >

------ only the root user can change the password of another user

3) switch to root user

Su root enters root user

syntax: su [-] Root

For example :

su root enters the user root account.

Passwrod: < Enter password for user root >

" - " To load the new user's environment , if it does not include the number, use the current user environment , note the "-" Spaces are required on both sides.

Description

1, if the switch to the root user, enter the Linux system settings password, the prompt is unsuccessful. Maybe we didn't activate the root account;
2. Activate root user: sudo passwd root.

file compression and decompression ( used to very high frequency )
1) Create Compressed package:tar-czf jin1.tar.gz jin1 Single original file tar-czf jp.tar.gz jin1/p/

2) list But do not press tar.gz file:tar-tf jin1.tar.gz

3) unzip the package: tar-xzf jp.tar.gz-c/home/jin Extract the jp.tar.gz package to /home/jin< under the/c13> directory

Description :

1.-c ,C is uppercase, and if not, it will be extracted to the current directory.

2. Related command selection instructions:

-C: Create, creating a new tar archive file;

- Z: zip to redirect the output to the gzip command for compression;

- F: file, output the result to files (or devices); [ in tar command selection, this parameter is essential ]

- t: list, which lists the contents ofan existing tar archive file;

- x: extract , unzip the existing archive file;

- V: View, which lists the files during processing.

Linux Common High frequency commands (self-summary)

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.