Linux Basic syntax

Source: Internet
Author: User
Tags bz2 gz file parent directory touch command

1. File details

Permission notation. is represented by a 10-bit character:

First bit: Is the file type, there are 7 types, common 3-Indicates that file d indicates that the directory L represents a soft connection (shortcut)
The next 9 bits, each 3 characters for a set of 3 kinds of users have permissions, followed by the file owner, the owner of the group, others
User permissions on the file, the three bits have each character sequentially:
R Read permission (read)
W Write permission (write)
X Execute Permissions

For example
-rw-r--r--.

First place
2-4 3-bit, file owner permissions
5-7 Owner Group Permissions
8-10 other people
.
-Indicates the file type
Rw-can be read and writable
r--Read Permissions
r--Read Permissions
Said

File details data list meaning:

File permissions
Number of file citations
File owner
The group where the files are
File size
Last Modified Date
Filename
-rw-r--r--.
1
Root
Root
1.2k
August 21 06:23
Install.log

2. Environment variables
1. View Environment variables
Echo $PATH
2. Once set as an environment variable, this path becomes the same as the current path, consistent with the window environment variable
such as: bash/root/jzk/hello.sh, if the/ROOT/JZK is set to environment variables, then the direct bash hello.sh can
3. Setting the environment variable method
Environment variables
(1) Valid for current user
The file is in the ~.bash_profile file.
Vim. Bash_profile

Multiple file paths with: separate out
Save Exit,
Execute the command to make the environment variable effective
source. bash_profile

(2) Valid for all users
All user-valid environment variables are
In the/etc/profile file, add

3. Basic syntax

Grammar
Description
Example
File and folder operations

[Email protected] ~]#
Root represents the login role, Jiangzengkui is the computer name ~ Indicates the current user home directory, such as root is the/root directory, #表示超级管理员, $ represents the average user

command [options] [parameters]
A common command pattern. Multiple parameters can be combined; simplified write and full write
RM-RF equals Rm-r-F
Ls-a-a equals--all
Ls
View directory or file information
LS option [-alfr ...] ..... [File or directory]
Parameter description:
-a displays all files, including hidden files
-L Display File details
-I Display file node information
-H humanized Display file size, automatically converted to KB or M

Ls-alh Show all file details and user-friendly display file size
Files and directories can be preceded by paths (relative and absolute paths)
Pwd
Displays the absolute path that is currently located

Cd
Switch directory path
CD ~ or CD back to the current user's home directory
CD-Enter the last command Yes directory
Cd.. Go to the top level directory of the current directory
Cd. Go to current directory

Mkdir
Create a Directory
Mdir [Options] Directory
-p Recursive create multi-level directory, without this option will error
The directory can be a relative path or an absolute path
mkdir JZK Current path Create a directory
Mkdir-p/tmp/test/test1 Create temp and below Test1 subdirectory
Relative Path/absolute path
Relative paths refer only to the current path,. Represents the current directory,.. Indicates a parent directory
absolute paths are searched from the directory, not affected by the current directory, and all files and directories can be added relative or absolute paths

Rm
Delete a file or directory
RM [-r-f] [Delete files or directories]
-R Delete Directory
-F Force Delete, if not add this parameter, each directory or file will ask whether to delete
RM Jzk/a.log
Rm-r/TMP/JZK
rm-rf/tmp/a
Cp
Copy file or directory
CP [Options] [original directory or file] [target directory or filename]
Options:
-R Copy Directory
-p Copy file attributes, such as last modified date
-D Link file (shortcut)
-A equivalent to-RPD
Cp-r jzk JZK/TMP/AA Copy the JZK directory to the/TMP/AA directory, note that if the AA directory does not exist, the AA is created automatically
Cp-a JZK jzk/tmp/aa All file attributes are exactly the same, such as file modification date
Cp-a T.log Jzk/t.log Note how to be a copy file, you must write the target file name
Mv
Cut files or rename
MV [original file or directory] [target file or directory]
Note: no options
MV jzk/tmp/the
Touch
Create a file
touch [options] [parameters]
The touch command has two functions: one is to update the time tags of existing files to the current time of the system (the default), their data will remain intact, and the second is to create new empty files.
-A: or--time=atime or--time=access or--time=use only change the access time;
-C: Or--no-create does not establish any documents;
-d:< Time Date > Use the specified date time, not the current time;
-F: This parameter ignores non-processing and is only responsible for the compatibility of BSD version touch directives;
-M: or--time=mtime or--time=modify only the change time;
-r:< reference file or directory > set the date and time of the specified file or directory to the same date and time as the reference file or directory;
-t:< Date Time > Use the specified datetime instead of the current time
Touch/tmm/a.log creating an empty file for A.log
Touch-m A.log Change time of modified file
Vi/vim
Edit File
Vim file name
1: Go to edit touch a.cfg. The command mode is entered.

    1. I key into edit mode
      3.ESC key to exit edit mode.
      4. In: Key exit format, Exit q! Exit Do not save wq! exit save
      Cat
      View File Contents
      Cat file name
      Cat/tmp/t.log Output T.log File contents
      File Search
      Find a file

Locate
Search by file name
Locate file name
Fuzzy query, query contains the input file name content files, note: Will be separated from the file suffix
Query from database, in/var/lib/mlocate/mlocate.db, the fastest query speed
Data is automatically updated one day, the file you just created cannot be found
UpdateDB Manual update, you can query to the latest files
Note: File search does not search the/tmp/folder
Limitations: Only file names can be searched
Locate A.cfg
UpdateDB
Locate A.cfg
Whereis
Command Search command
is to search for Linux system commands
Whereis [Options] Command
-B Search Execution files only
-M search only help documents
Add: Whereis Where am I, whois who am I, whatis I do?
Whereis ls
Whereis-b Cat
which
Command Search command
Which you can see the alias of this command in addition to the file location Whereis the enhanced version
which LS
Which cat
Find
File search mode with multiple parameters
Find [Search scope] [search criteria]
Try to avoid too large a search range, such as From/directory search
Note that find is exactly exactly the exact match, and the locate is not the same. Find to use a fuzzy query, you need to use the wildcard character
1. Search by file name
-name Search file name
-iname Case insensitive
2. Search by file Owner
-user search for the specified owner's file
-nouser search without owner's file

3. Search by file change time
-[Time option]+[-] Days
-mtime File content Changes
-ctime changing file properties
-atime File access time
The default is the number of days
4. Search by File size
Find path-size +[-] Size
5. Follow the file node to search
Find path-inum file inode node

6. Combination Query
-A indicates that the logic and all conditions are satisfied
-O means logic or, one condition satisfies

7. Output query result file for file processing

Use-exec file to process command {}\;
Find/root-name Install.log
Locate Install.log There's a difference between the two results.
Find/root-name Install.log * equals locate Install.log
Find/root-iname Test.log Case insensitive

Find/root-user Root Search All files owned by root
Fint/root-nouser Search for files without user

Find/root-mtime +10 10 days ago File content changes that have occurred
FIND/ROOT-MTIME-10 file content changes within 10 days

Find. -size-25k search files less than 25k
Find/etc-size +2m search for files larger than 2 megabytes, note M capital

Find. -inum 134277 Finding the I-node 134277 file

Find/etc-size +20k-a-size-50k Find files larger than 20k and less than 50k

Find/etc-size +20k-a-size-50k-exec ls-l {}\;
The query structure is displayed with Ls-l.

Find/etc-size +20k-a-size-50k-exec rm-rf {}\;
Delete the results of the query
Grep
Search string command
Query for a file (not) containing the specified search content on the row display
grep [Options] search string Specify file
-I ignores case
-V excludes the specified search content

Displays the line where the character is located
grep "Size" anaconda-ks.cfg
Displays the line containing the size string in the Anaconda-ks.cfg file
Wildcard characters

    • Unlimited length of any content
      ? Any one character
      [] any one of the brackets
      Find/root-name Any file that starts with "ab*" AB
      Find/root-name 3-character file starting with "AB?" Ba
      Find/root-name "Ab[c,d]" abc and ABD Files
      Compression and decompression
      Zip gz bz2
      tar.gz tar.bz2 5 Common types of Linux compression formats

Zip
Compress files or folders
Zip compressed file name destination file name
Zip-r Compressed Package name destination file directory
Linux zip can be used in Window System
Zip a.cfg.zip a.cfg Compressed file
Zip-r jzk.zip JZK Compressed Files directory
Zip a.cfg./jzk/a.cfg.zip compress the a.cfg into the a.cfg.zip in the./JZK Directory
Unzip
Unzip the zip file
Unzip compressed files/directories
Note: Without extracting the file name or directory, you can specify a compressed file name and a directory for Linux compression.
But decompression, is extracted to the previous file storage location and file name (Restore the original, no directory is created), and compressed files in the same directory and file name Independent
Unzip Jzk/a.cfg.zip
Gzip
Files and directories in compact GZ format
Gzip Source files
Note: No compressed file name, automatically generate compressed file name: Original file. gz, original file disappears
Gzip-c source file name > Compressed file name
Note: Source files do not disappear
Gzip-r Original file directory
Note: All files in the file directory are compressed and the file directory is not compressed.
Gzip Aa.cfg
Gzip-c aaa.cfg > aaa-1.cfg.gz Keep the original file
Gzip-r JZK All files in compressed directory, directory not compressed

Gunzip
Unzip the GZ file
Gunzip Compressed Files
Gunzip-r the directory that the compressed file corresponds to
Note: After Gunzip decompression, it is the file name corresponding to the compressed file name, and zip is not the same, the compressed files disappear
Unzip directory plus-R
Gunzip a.cfg.gz
Gunzip-r JZK
bz2
Compress bz2 Files
bzip2 source File
Compressed into bz2 format, the source file disappears
Bzip2-k source files Keep original files
Note: bzip2 cannot compress folders
Bzip2 a.cfg
Bzip2-k aa.cfg

Bunzip2
Unzip the bz2 file
BUNZIP2 Compressed Files
Bunzip2-k Keep Compressed files

Tar
File Packaging commands
TAR-CVF package file name source file
-C Packaging
-V Display procedure
-f Specifies the file name after packaging
TAR-CVF A.cfg.tar a.cfg File Packaging
TAR-CVF Jzk.tar JZK Directory Packaging
Tar unpacking
Tar file Unpacking command
TAR-XVF tar file name
-X Unpack the package
-V Display procedure
Unzip to the current directory, the extracted file or directory name is the name of tar
TAR-XVF A.tar
tar.gz Packaging
TAR-ZCVF compressed package name. tar.gz Source File
-Z Turn tar into tar.gz bag

Linux Basic syntax

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.