The Linux command line uses

Source: Internet
Author: User

FHS: Standard file architecture specification
Use the man command.
Su-name Switch to User name
Su-root
chmod 777 filename
CD-: Previous working directory
CD ~: User's home directory
CD ~nid:q Switch to Nid's home directory
Mkdir-p/tmp/dd/dd/d Creating nested directories
RmDir dir: Delete empty directory
ls [filename | directory name | NONE]
Ls-a list of hidden files included
Ls-l listing the details of a file
To modify a user group:
Chown Nbcc:stu hello.sh
Chown Stu hello.sh
CHOWN:NBCC hello.sh
Ls-l hello.sh
Listed in the file information;
D: Catalog file
-: Normal file
C: Character file
L: Link File
Cp-r/temp/aa ~ Copy Directory home directory
There are multiple file handling methods for copying with the same name:
\cp-f/temp/aa/tmp/file03 ~
cp/tmp/smple.sh ~nbcc copy sample.sh to NBCC home directory
Copy files to directory (and retain permissions before copy-P)
Cp-p/tmp/file03/sample.sh ~NBCC
MV/TMP/DD/TMP/DD1/TMP/D2 ~ Move multiple Directories home directory
Moving files overwrite files with the same name;
Mv-f/TMP/D2 ~
Duplicate files
mv./file08./file01
Delete command:
Rm./file01
Delete multiple files;
Rm./file01./file02./file02
To delete a directory:
Rm-r./dir1
Delete directory directly:-F
Rm-fr./dir1
Soft links
ln-s [link to file] [link name]
Ln-s/tmp/hello.sh./hello_slink
If the file that the symbolic link points to is deleted, it means that the link is broken.
Hard links, soft links
Hard Links
ln [link to file] [link name]
Attention:
1. Creating directory hard links is not recommended
2. Creating hard links across disks is not recommended
3. Hard link Deletion just deletes the file name, not delete the file
Tar
TAR-CF [package filename] [File/list to package]
-C: Create a packaged file
-F: Specify the package file name
To package multiple files:
TAR-CF Sample.tar/tmp/file1/tmp/file2/tmp/file3
List all the file names in the package:
TAR-TF./sample.tar
To delete a file within a package:
Tar-f./sample.tar--delete tmp/file05
To merge packaged tar files:
Tar-f./sample.tar-a./sample1.tar
To add a file to the tar file:
Tar-f./sample.tar-r ~/file.txt
Unpacking files:
Tar-xf./sample.tar-c./sample
Note: Default unpacking to current directory
-C: Unpacking directory
Compressed files:
Gzip./sample.tar
Unzip the file:
gzip-d./sample.tar.gz
Packaging and compression commands used in combination: tar and gzip
For example:
Tar-czf sample.tar.gz/tmp/sample/tmp/file05
Unpack the Package
Tar-xzf sample.tar.gz

Locate. Tar to find Files
Locate is looking from the database:/var/lib/mlocate database
Update Database: UpdateDB

Find [Search scope] [find condition] [action]
Find/-name passwd
Find/bin-type L: Find symbolic Link file
-type d catalog File
-type F: Normal file
-type C: Character file
-type B: Block device files
-type L: Symbolic Link file

Find files that have changed content within three days
Find/tmp-mtime-3-ls
Find files that changed content seven days ago
Find/tmp-mtime +7-ls
Find changes to files that occurred 4 days ago in the directory that day
Find/tmp-mtime 4-ls
Comments:
+: Indicates n days ago
-: Indicates within n days
N: Indicates the first Nth day
Find/tmp-mmin-3-ls: Min
-amin-atime file is modified, execution time
-cmin-ctime file properties were modified time
-mmin-mtime File Modification Time

Search by size;
Find files below 3K in the directory;
Find/tmp-size-3k-ls
Find files that are larger than 100 bytes
Find/tmp-size +100c-ls

Find the file owner is the root user
Find/tmp-user root-ls
Find the user's UID 500 file
Find/tmp-uid 500-ls
Find user Group is Stu file
Find/ Tmp-group Stu-ls
Find files for user group gid0
find/tmp-gid 0-ls
Find files by user's own permissions
Find/tmp-perm 754-ls
Find multi-parameter lookup file: with-a
or-o
Non!
Example:
find/tmp \ (-size +1k-a-size-10m-a-mmin-30-a-type f\)-ls

Find a specific file and delete
find/tmp \ (-size +1k-a-size-10m-a-mmin-30-a-type f\)-exec rm-rf {} \;
; There is a specific meaning in bash, so use the transfer character
Find ~\ (-mmin-10-a-type d \)-exec TAR-CF {}.tar {} \;
-ok-exec (similar, there will be a hint)
find a file with the name temp deleted without prompting:
Find/-name temp-exec rm {} \;
Wildcard character:
*: string of any length (including 0 length)
? Represents an arbitrary single character
Ls-l/bin/?? SH
[c1-c2]c1-c2 character sequence
Cp/tmp/file[0-9].txt ~ Copy file to the home directory
[C1,c2,c3,c4,... cn] matches any single character within the sequence of characters in parentheses
example :
Modify the file properties of the following features:
chmod 700/tmp/script[a,1,x].sh
{string1,string2,string3,string4,.. STRINGN} match one of the string
Example:
RM-RF {script,shell}*.sh: Delete the file at the beginning of
! Take an inverse
to package any one of the characters except [0-9]
TAR-CF file.tar/tmp/file[!0-9].txt

Cat (concatenate) Connect several files, create files from the keyboard, view files
View Files
cat/var/shell.sh
View text files (large files)
Less/var/shell.cpp (Up,down up and down, pagedown,pageup)
Head-n 20/var/log/messages Viewing the first 20 lines of a file
Tail viewing end information for a file
Redirect:
Ls-l/tmp/example/1>./stdout.txt
Ls-l/1>>stdout.txt
Ls-l/tmp/example/2>./stdout.txt
Ls-l/2>>stderr.txt
Redirect to a file: wrong, correct
Ls-l/temp/example/file1/tmp/example/file04 &>std.txt
Ignore output:
Ls-l/tmp/example/file1/tmp/example/file04 2>>/dev/null
Enter redirection:
TR [the character to be replaced] [the character to be replaced]
Tr ' \ t ' <./fruit.txt replaces text in fruit.txt with tab
sort-k [keyword field ordinal] [text file to sort]
Sort-k2 <<eof
>1 Apple
>2 Pear
>3 Banana
>eof
1 apple
3 Banana
2 Pear

Pipeline
grep cut head tail less more WC tr sort
grep [keyword text] [find text]
ls-al/etc | Less
ls-al/etc | grep ' ssh '

Cut
Cat ~/install.log| cut-c1,2 the character column number of the cut
cat/etc/passwd | Cut-f1-d ":" (number,: delimiter)

WC: Statistics Command
WC/ETC/PASSWD count the number of rows and words
Wc-l/etc/passwd only count lines of text
Example
Ls-al ~|CUT-C1 | grep "D" | Wc-l

The Linux command line uses

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.