Basic Linux commands for Kaka notes

Source: Internet
Author: User
Tags call shell
KaKa notes-Linux basic commands-Linux general technology-Linux technology and application information. The following is a detailed description. LS
# Ls [parameter] [directory or file name]
[Root @ localhost root] # ls? L long format output
[Root @ localhost root] # ls? A. Show all files, including hidden files, including "." and "...".
[Root @ localhost root] # ls? A shows all files, including hidden files, excluding the "." and "." directories.
[Root @ localhost root] # ls? Lh reading to display the size of a file or directory, such as K, M, or G.
[Root @ localhost root] # ls-t sorts the last access (or modification) Time of the file, with the latest at the top
[Root @ localhost root] # ls-lR recursively displays all the files in the directory and displays the files in the subdirectories.
[Root @ localhost root] # ls-la -- color = never indicates that the output is not colored.
[Root @ localhost root] # ls-la -- color = auto indicates automatic
[Root @ localhost root] # ls-la -- color = always indicates that the output content is colored.
[Root @ localhost root] # ls? LS sorts the file size.
[Root @ localhost root] # ls? If lr is in reverse order
[Root @ localhost root] # ls? Lt sort by the last access time
[Root @ localhost root] # ls? LX sort by extension
[Root @ localhost root] # ls/root/k ** represents 0 or multiple characters
[Root @ localhost root] # ls/root/k? ? Represents any single character

Create an empty file
[Root @ localhost root] # echo> test.txt
[Root @ localhost root] # touch> test.txt
[Root @ localhost root] # cat> test.txt exit Ctrl + C
File rename
# Original mv file name or directory name new file or directory name
[Root @ localhost root] # mv old.txt new.txt

View File Content
1 \ Cat
[Root @ localhost ~] # Cat/etc/profile Note: view the profile file content in the/etc/directory
[Root @ localhost ~] # Cat-B/etc/fstab Note: view the profile content in the/etc/directory and number non-blank rows. The row number starts from 1.
[Root @ localhost ~] # Cat-n/etc/profile Note: Numbers all the rows (including blank rows) of the profile in the/etc directory are output.
[Root @ localhost ~] # Cat-E/etc/profile Note: view the profile content under/etc/and add the $ symbol at the end of each line
The cat parameter-n is similar to the nl tool. When the file content is output, the row number is added before each line.
[Root @ localhost ~] # Cat-n/etc/profile
[Root @ localhost ~] # Nl/etc/profile
Cat can display the content of multiple files at the same time. For example, we can display the content of two files at the same time on a cat command;
[Root @ localhost ~] # Cat/etc/fstab/etc/profile
For files with large content, cat can be transferred to the more tool through pipelines and viewed on a page by page;
[Root @ localhost ~] # Cat/etc/fstab/etc/profile | more
Cat can create files. After creating a file, it must end with EOF or STOP;
[Root @ localhost ~] # Cat> linuxsir.org.txt <EOF Note: Create the linuxsir.org.txt file;
> I will test the cat creation file. Note: This is the content entered for the linuxsir.org.txt file;
> Test. Note: This is the content entered in the linuxsir.org.txt file;
> EOF Note: exit the editing status;
[Root @ localhost ~] # Cat> linuxsir.txt <EOF // Add new content to the existing file
Cat appends the content of one or more existing files to an existing file.
[Root @ localhost ~] # Cat sir01.txt sir02.txt sir03.txt> sir00.txt
Cat moves the content of one or more existing files to an existing file.
[Root @ localhost ~] # Cat sir01.txt sir02.txt sir03.txt> sir04.txt
2 \ More
[Root @ localhost ~] # More-dc/etc/profile Note: A prompt is displayed and displayed at the top of the terminal or console.
[Root @ localhost ~] # More + 4/etc/profile Note: it is displayed from row 4th of profile.
[Root @ localhost ~] # More-4/etc/profile Note: four lines are displayed on each screen
[Root @ localhost ~] # More +/MAIL/etc/profile Note: it is displayed from the first two lines of the first MAIL word in profile.
3 \ Less
Less parameter:
-C. Refresh the screen from top to bottom and display the file content. Instead of refreshing through the bottom scroll;
-F force open the file. No warning is prompted when the binary file is displayed;
-M: displays the percentage of Files Read;
-The percentage, row number, and total number of lines read by M-mode;
-N: output the row number before each row;
-S displays multiple consecutive blank rows as one blank row;
-P pattern: Search for pattern;
For example, to search for the Word MAIL in/etc/profile, use [root @ localhost ~] # Less-p MAIL/etc/profile
Less action command:
The enter key moves down a row;
Y: move one row up;
The Space key scrolls down a screen;
B. Scroll up the screen;
D. Scroll down the half screen;
U moves the half screen up;
G jumps to the first line;
G to the last line;
P n % jumps to n %, for example, 10%, that is, it is displayed starting from 10% of the entire file content;
/Pattern: Search for pattern. For example,/MAIL indicates searching for MAIL words in files;
V call the vi editor;
Q: Exit less
! Command to call SHELL, you can run commands; for example! Ls displays all files in the current directory of the current column;
4 \ Head
Displays the first few lines of a file;
Header-n rows numeric file name;
For example, the first 10 lines of/etc/profile are displayed.
[Root @ localhost ~] # Head-n 10/etc/profile
5 \ Tail
Displays the number of rows before the last row of a file;
Name of the numeric values in the tail-n rows;
For example, the last five lines of/etc/profile are displayed,
[Root @ localhost ~] # Tail-n 5/etc/profile

File/directory Deletion
# Rm [parameter] file1 file2 ......
# Rm [parameter] dir1 dir2 dir3... delete non-empty directory // rmdir Delete empty directory
[Root @ localhost root] # rm-f test.txt // delete without warning or prompt information
[Root @ localhost root] # rm-I test.txt
// The warning message is displayed when the file is deleted. It is safer to use it more often.
[Root @ localhost root] # rm-r test.txt r or-R indicates that the entire directory (including subdirectories and all files) can be deleted)
File/directory Replication
# Cp [parameter] source file or directory target file or directory
[Root @ localhost root] # cp? I file1 file2 interaction function
[Root @ localhost root] # cp? B file1 file2
-B backs up the overwritten files. If you copy file1 to file2, if file2 exists, it overwrites file2. With this parameter, a file2 ~ ~ End
[Root @ localhost root] # cp-a mydir youdir
// Keep the attribute of the source file or directory as much as possible during the replication process
[Root @ localhost root] # cp-a mydir youdir
If the medir directory does not exist, create the medir directory, and the content in the medir directory is the same as that in mydir.
File/directory Movement
[Root @ localhost root] # mv file1 file2 move file1 to file2. If file2 does not exist, create a file2 file name.
[Root @ localhost root] # mv file1 dir // the engineering department moves a file to an existing Directory.
[Root @ localhost root] # mv dir1 dir2
Move the directory dir1 to dir2. If dir2 does not exist, create it.
[Root @ localhost root] # mv file1 file2 file3 dir move multiple files such as file1, file2, and file3 to the dir directory
[Root @ localhost root] # mv-I file dir // man-machine interaction mode

File Permission
I. digital form
R: 4 w: 2 x: 1-: 0
[Root @ localhost root] # chmod 664/test/file
Ii. text form
User: u (User) g (Group) o (Other) a (All)
Permission: r (Read) w (Write) x (eXecute)
Operation: = (re-specify) + (Increase)-(decrease)
[Root @ localhost root] # chmod u + x, g + w, o-r/test/file
Directory permission
[Root @ localhost root] # chmod 666/test /*
Set all file permissions in the/test directory to allow all users to read and write data.
[Root @ localhost root] # chmod? R 666/test/*/If the directory contains sub-directories, add the-R parameter.

RPM
Rpm-qa
All RPM software packages installed in the query system
[Root @ localhost root] # rmp? Qa // query all RPM software packages installed in the system
[Root @ localhost root] # rmp? Qa | more // display by PAGE
[Root @ localhost root] # rmp? Qa | grep X
// Works with grep to find a software package containing a specific string
Install or not in the system
Rpm? Q package name
[Root @ localhost root] # rpm? A xinetd bind // search for multiple software packages at the same time
Describes the software packages installed in the query system.
Rpm? Qi package name
Query files in a software package
Rpm? Ql package name
The software package of the specified file in the query system
Rpm? Absolute path name of the qf File
Query the information in the RPM package file
[Root @ localhost root] # rpm? Qp *****. rpm // query the software name in the rpm package
[Root @ localhost root] # rpm? Qpi *****. rpm // query the description of the software in the rpm package
[Root @ localhost root] # rpm? Qpl *****. rpm // query the file list of the software in the rpm package
RPM package installation
[Root @ localhost root] # rpm? I ***. rpm // used to install the specified RPM package to the current system
[Root @ localhost root] # rpm? Ivh *****. rpm // I = install, v = verbose, h = hash
RPM package uninstall
[Root @ localhost root] # rpm? E package name

TAR package management
Create a TAR package
Files or directories backed up by the tar cvf package file name
[Root @ localhost root] # rpm cvf test.tar/test/
[Root @ localhost root] # file test.tar // test.tar file type
Create a compressed tar package
Name of the file or directory backed up by Tar zcvf compressed tar package file name
Tar-extract Compression
[Root @ localhost root] # tar zcvf test.tar.gz/test/
Query the content in the tar package
Tar tf TAR package file name
[Root @ localhost root] # tar tf test.tar
Release the tar package
Tar xvf compressed TAR package file name // x = released
[Root @ localhost root] # tar xvf test.tar
Release compressed tar package
Tar zxvf compressed TAR package file name
[Root @ localhost root] # tar zxvf test.tar.gz
File compression and decommission
/ZIP Compression
[Root @ localhost root] # zip test. zip test // compress the specified file
[Root @ localhost root] # zip? M test. zip test //-m automatically deletes the original file
If the compressed directory contains subdirectories
1. The default subdirectories are also compressed.
[Root @ localhost root] # zip? R file. zip/test/
2. Do not compress subdirectories
[Root @ localhost root] # zip? F file. zip/test/
If the compressed file is decompressed on other platforms, it must be in the format of-k.
[Root @ localhost root] # zip? K file. zip/test/
/ZIP unzip
[Root @ localhost root] # unzip file.zip
[Root @ localhost root] # unzip file.zip? X file2 //-x exclude specific files
[Root @ localhost root] # unzip? Z file.zip
//-Z: view the information in the compressed file without interrupting the file.
[Root @ localhost root] # unzip? L file.zip // equivalent to the above
/Gzip // Note: you cannot compress multiple files into one file.
[Root @ localhost root] # gzip file1
[Root @ localhost root] # gzip? L file1.gz // view the content of the extracted File
/Gunzip // decompress
[Root @ localhost root] # gunzip file1.gz

Account Management
User and Group
User Management
-Create a user
[Root @ localhost root] # useradd test // create a test user
[Root @ localhost ~] #/Usr/sbin/useradd test // create a test user
[Root @ localhost root] # useradd? G tests test // Add a user to a specified group
[Root @ localhost root] # useradd? D // display user settings
-User Password
[Root @ localhost root] # passwd test
-Modify user
[Root @ localhost root] # usermod? L newuser olduser // modify the current user name
[Root @ localhost root] # usermod? L test // lock the current user
[Root @ localhost root] # usermod? U test // unlock the current user
-Delete a user
[Root @ localhost root] # userdel test // delete a specified user
[Root @ localhost root] # userdel? R test // Delete the specified user and delete the Home Directory
User Account file passwd
[Root @ localhost root] # head/etc/passwd
User Password File shadow
[Root @ localhost root] # head/etc/shadow
Group Management
-Create a group
[Root @ localhost ~] # Groupadd tests
-Modify group
[Root @ localhost ~] # Groupmod? N newugroup oldgroup
-Delete a group
[Root @ localhost ~] # Groupdel tests // delete a user before deleting a group
User Group account file
[Root @ localhost root] # head/etc/group
Related Article

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.