1、ls

ls -hG  //MacOS Output color file and directory

ls -a // Show hidden files

ls -l // Display file permissions and group information

ls -lR /home // List home A directory includes all the files in its internal subdirectories

2、cd

cd / Enter the system root directory

cd ..// Go to the previous Directory

cd -  Return to the directory before entering this directory

3、pwd

View current directory

The current directory has been deleted , and pwd The command still shows that directory

[root@localhost soft]# mkdir removed

[root@localhost soft]# cd removed/

[root@localhost removed]# pwd

/opt/soft/removed

[root@localhost removed]# rm ../removed -rf

[root@localhost removed]# pwd

/opt/soft/removed

4 、mkdir -m dirname

Create directory

-m Set the permissions mkdir -m 777 name

-p  Create multiple directories recursively  mkdir -p test2/test22

-v Displays information about creating a directory

[root@localhost test]# mkdir -v test4

mkdir: Directory created “test4”

5、rm

Delete files or folders

rm filename Delete a file

-r Delete all files in the directory and subdirectories  rm -r test1

-f Don't ask before deleting Delete directly

-i Interactive delete Every time you delete it, you need to confirm

6、rmdir

Delete empty directory

If there are subdirectories in the current directory , Even if the subdirectory is empty , You can't delete it with this command

-p Recursive delete : When subdirectories are deleted , When the parent directory is empty , Delete the parent directory as well .

7、mv Options Source file / Catalog Target file / Catalog

“ Move files to directory ” perhaps “ Rename the source file to the destination file name ” perhaps “ Add the source directory to the target directory ”

mv  text.txt  text1.txt          Will file text.txt Rename it to text1.txt       There are only text.txt file , After moving the folder, only text1.txt

mv test1.txt test3               take test1.txt Move to test3 Directory

Will file log1.txt,log2.txt,log3.txt Move to directory test3 in

mv log1.txt log2.txt log3.txt test3

mv -t /opt/soft/test/test4/ log1.txt log2.txt  log3.txt

-t  : --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY, Designated mv Target directory for , This option is suitable for moving multiple source files to a directory , At this point, the target directory is in front , The source file is after .

mv  1.txt   2.txt                   Use 1.txt take 2.txt Cover , add  -i   The parameter represents a query about whether to override   -f Directly covered , Don't ask

mv -f 1.txt 2.txt

mv dir1 dir2                       If dir2 non-existent , take dir1 Renamed as dir2; If dir2 There is , Put the table of contents dir1 Move to dir2

mv * ../                               Move all the files in the folder to the previous directory

mv test3/*.txt test5             Move test3 In the following .txt Move the ending file to test5 Next

mv log1.txt -b log2.txt       -b Parameter function , Make a backup before the file is overwritten

8、cp Source The goal is perhaps

cp -t The goal is Source

Copy files or copy files to the target directory

In the absence of -a When parameters are , The time of the two files is different .( Be careful : I'll take it with me -a When parameters are , The time of the two files is the same , Otherwise, the time is inconsistent )

Copy the entire directory to the target directory

9、touch Parameters file name

Create a file or change the file time ( Can modify the file access time and file modification time )

touch -c test                                    -c parameter , If the file doesn't exist , So don't create a file

touch -r log.log log2012.log                 to update log2012.log The time to make it with log.log It's the same time

touch -t 201211142234.50 log.log         Set the time stamp of the file ,  The format of time stamp is [[CC]YY]MMDDhhmm[.SS]

10、cat

1)、 Show the whole file at once cat fileName             Display file contents

2)、 Create a file from the keyboard cat > fileName         Only new files can be created , That is, if there was this file , After using this command , The original file will be overwritten .

3)、 Merge multiple files into one file Or merge one file into one cat file1 file2 > file

file1 and file2 Merge into file Show ,file If there was content , Will be covered . If there is no content , New .

cat -n log2012.log log2013.log                           hold  log2012.log  Add the line number to the contents of the file and input  log2013.log  In this document   If it's more than one file , Input to the last file

cat -b log2012.log log2013.log log.log                 hold  log2012.log  and  log2013.log  The contents of the document are numbered ( Blank lines do not add ) Then attach the content to  log.log  in

Use  here doc To generate files

bogon:logX sunhongbo$ cat >log.txt <<EOF
> world
> hello
> EOF
bogon:logX sunhongbo$ cat log.txt
world
hello

here doc String substitution is possible . tac  Yes, it will  cat  Write it back , So his function is just like  cat  contrary , cat  It's shown on the screen from the first line to the last line , and  tac  It is shown on the screen from the last line to the first line !

tac log.txt

11、nl Options file

Add line numbers to the contents of the file

-b  : Specify how line numbers are specified , There are two main types :

-b a : Indicates whether the line is empty or not , Also list line numbers ( similar  cat -n);

-b t : If there is a free line , Do not list the line number in the blank line ( The default value is );

-n  : List the method of line number representation , There are three main types :

-n ln : The line number is shown at the far left of the screen ;

-n rn : The line number is displayed on the far right side of your field , And no more  0 ;

-n rz : The line number is displayed on the far right side of your field , And add  0 ;

-w  : The number of digits occupied by the line number field .

[root@localhost test]# nl -b a -n rz -w 3 log2014.log

001     2014-01

002     2014-02

003     2014-03

004     2014-04

005     2014-05

The command line number defaults to six digits , To adjust the number of digits, you can add parameters  -w 3  Adjusted for 3 position .

12、more

Function like cat , But you can set pagination display .

And the most basic command is to press the blank key (space) The next page shows , Press  b  The key will go back (back) One page shows , It also has the function of searching for strings  .

more [-dlfpcsu ] [-num ] [+/ pattern] [+ linenum] [file ... ]

+n       From the first n Line start display

-n        Define screen size as n That's ok

+/pattern  Search for the string before each file is displayed (pattern), Then it starts to display... After the first two lines of the string

-c        Clear the screen from the top , Then show

-d        Tips “Press space to continue,’q’ to quit( Press the space bar to continue , Press q Key to exit )”, Disable the ring function

-l         Ignore Ctrl+l( Change the page ) character

-p        Wrap the document by clearing the window instead of scrolling , And -c Similar options

-s        Display consecutive blank lines as one line

-u        Remove the underline from the contents of the document

ls -l  | more -5

List the files in a directory , Due to too much content , We should learn to use more To display in pages . It has to do with the pipes  |  Combine

13、less Parameters file

Page through files or other output

less file             see file

ps -ef | less      ps View process information and go through less Pagination display

history | less      Check the command history and pass less Pagination display

1. Full screen navigation

ctrl + F -  Move one screen forward

ctrl + B -  Move back one screen

ctrl + D -  Move half screen forward

ctrl + U -  Move back half screen

14、head Parameters file

head -n 5 file1       Display file file1 The first five elements of

head -n -6 file1     Display file file1 Except for the last six lines

head -c 20 file     Display file file Before 20 Bytes

head -c -20 file   Display file file Except after 20 Everything except a byte

15、tail Parameters file

tail -n 5 file         Show the last five lines of the file

tail -n +5 file       Show all the rest of the file from the fifth line

tail -f file             Loop through the contents of the file ,tail -f filename Will be able to filename The last part of it is shown on the screen , And not only refresh , So that you can see the latest file content .

ping 192.168.120.204 > test.log & // Backstage ping Remote host . And output the file to test.log; This approach is also used for more than one file surveillance . use Ctrl+c To terminate .

16、which Executable file name

Show command path , which The order will be in PATH In the path specified by the variable , Search for the location of a system command , And return the first search result .

which ls View command ls directory

17、whereis

Look for binary files 、 Description files and source files

[root@localhost ~]# whereis svn

svn: /usr/bin/svn /usr/local/svn /usr/share/man/man1/svn.1.gz

[root@localhost ~]# whereis -b svn

svn: /usr/bin/svn /usr/local/svn

[root@localhost ~]# whereis -m svn

svn: /usr/share/man/man1/svn.1.gz

[root@localhost ~]# whereis -s svn

svn:

[root@localhost ~]#

18、locate

loacte pwd  Find and pwd All relevant documents

locat /etc/sh  Search for etc All under the directory sh Opening file

19、find

find -atime -2         Find files that have been modified within a specified time , lookup 2 * 24  = 48 Documents modified within hours

find . -name "*.log"   Search in the current directory to .log Final document , . Represents the current directory

find Catalog -perm 777 To find the specified “ Catalog ” The next permission is 777 All files for

find . type -f -name “*.log”   Search the current directory to .log The end of the common type of file

find . -type d | sort   Find all the directories in the current directory ! And sort

-type   Find a type of file , Such as :

b -  Block device file .

d -  Catalog .

c -  Character device file .

p -  Pipeline files .

l -  Symbolic link file .

f -  Ordinary documents .

find . -size +1000c -print Find the current directory is greater than 1k Size file

-print: find Command to export matching files to standard output

find Command related :

find ~ -name “*.log”  ~ Represents to search in the root directory . Represents the current directory and subdirectories   / Directory name Find... In the specified directory

find . -name "[A-Z]*" -print    You want to search the current directory and subdirectories for files whose names begin with a capital letter

20、find Order exec

Will find the file perform exec Later orders ; The command ends with a semicolon , Considering the system, semicolons have a special meaning , Add one before the semicolon \,{} representative find Result

find . -type f -exec ls -l {} \;   Find the common file in the current directory and output it as a list

find . -type f -mtime +14 -exec rm {} \;   lookup 14 Files that were changed a few days ago and delete them

find . -name "*.log" -mtime +5 -ok rm {} \;  Find all filenames in the current directory to .log ending 、 Change the time in 5 Documents over days , And delete them , Just give a hint before deleting .  Press y Key delete file , Press n Key does not delete .

find /etc -name "passwd*" -exec grep "root" {} \; find The command first matches all the files named “ passwd*” The file of , for example passwd、passwd.old、passwd.bak, And then execute grep Command to see if one of these files exists root user .

find . -name "*.log" -exec mv {} .. \; Move the found file to the previous directory

find . -name "*.log" -exec cp {} test3 \; Copy the found file to the specified directory

21、find And xargs command

exec The command has a limit on the length of input that can be accepted , So for long input files , It might spill over ;xargs It's an order to deal with this , He will process the input file in batches

And there are systems for exec, Each input command generates a process , Such multiple input files can cause performance degradation , and xargs There is only one process .

find . -type f -print | xargs file    Find every common file in the system , And then use xargs Command to test what kind of files they belong to

find / -name "core" -print | xargs echo "" >/tmp/core.log   Find the memory dump file (core dump) And output to the coer.log In file

find . -perm -7 -print | xargs chmod o-w         Find the file that the user has read and write permission to execute , And reclaim write permissions

find . -type f -print | grep xargs “hostname”    use grep The command searches all normal files for hostname The word

find . -name "*.log" | xargs -i mv {} test4 Moving files

22、Linux file :

Ordinary documents ( text file Binary Data interface file )、 Directory file 、 Character files and block device files 、 Symbolic link files and device interface files .

File extension :.sh Script file or batch file

*Z, *.tar, *.tar.gz, *.zip, *.tgz Compressed files , For different compression software ( gunzip, tar  wait ), There are different compressed files

ls -lih You can see the file details , Include Document indexing inode(-i control ) etc.

for example :2095112 -rw-r--r-- 1 root root 296K 11-13 06:03 log2012.log

First column :inode

Second column : File types and permissions ;

The third column :  Number of hard links ;

The fourth column :  Belong to ;

The fifth column : The group to which you belong ;

The sixth column : The size of the file or directory ;

Columns seven and eight : Last visited or modified at ;

Row 9 : Filename or directory name

23、SecureCTR;

use SSH management linux The server often needs remote and local interactive files . And direct use SecureCRT Its own upload and download function is undoubtedly the most convenient . Need to install SecureCTR To host .

ssh It's an agreement , It's a protocol between the application layer and the transport layer .SecureCRT It's based on ssh Protocol terminal transmission software .

24、tar Parameters file

tar Just packing , Packaging is to package multiple files or directories into one file ; And compression is to compress a large file into a small file through some kind of compression algorithm .

tar Only the function of packing , But it can be controlled by parameters , Add packaging function .

tar cvf fileneme.tar filename pack

tar xvf filename.tar   Unpack

Compress gzip FileName

decompression gunzip filename.zip

gzip -d filename.zip

tar zcvf  filename.tar.gz filename Packaging compression

tar zxvf filename.tar.gz   Unpack and unzip

Compress bzip2 -z filename

decompression bzip -d filename.bz2

bunzip filename.bz2

tar jcvf filename.tar.bz2 filename   Packaging compression

tar jxvf filename.tar.bz2   Unpack and unzip

uncompress FileName.Z        tar Zxvf FileName.tar.Z

rar x FileName.rar   decompression             rar a FileName.rar DirName Compress

25、gzip

Compress command

gzip * Compress  gzip -r test1 Recursive compression Compress files in directories and subdirectories

gzip -d file.gz decompression

26、chmod

Modify the owner of a file or directory Group and Other user privileges

u : The current user of the directory or file
g : The current group of directories or files
o : Users or groups other than the current users or groups of directories or files
a : All users and groups

chmod a+x file   file Add executable permissions to all users

chmod g-w file   file Group users reduce write access

chmod ug+r file   file Add read permission to the owner and group users

chmod u=x file    file Set the owner executable permissions

chmod -R u+x test4    Add permissions to all files in a directory and its subdirectories

27、 chgrp

Group users who change files or directories , The permission is super user

chgrp -v bin file   hold file Change the group of users to bin -v Print details on behalf of

chgrp --reference==file1 file2  file2 Change the group of users to file Group users of

chgrp -R bin test1 change test1 The group users of all files in the directory and its subdirectories are bin

chgrp -R 100 test6   change test1 The group users of all files in the directory and its subdirectories are users(100 by users The ID of the group , Specific groups and group IDs can go to /etc/group View in file )

28、chown

Change file owners and groups

chown mail:mail file   file Change the owner and group of to mail

chowm root: file        file Change the owner and group of to root

chown :mail file        file Change your group to mail

29、df

View disk space usage

df -h Display disk space usage in a more readable way

30、du

View the current directory and subdirectory size

du -h [ Directory or file name ]     View the size of a directory or file in a more readable way

31、top

Check the resource usage of each process

32、free

Check the system free memory 、 Used physical memory and swap Swap memory ( Virtual memory ), And what's used by the kernel buffer.

free -s 10 Periodic display of memory usage ,10s Refresh once

33、vmstat

View system virtual memory 、 process 、CPU Activities

34、iostat

see CPU、 network card 、tty equipment 、 disk 、CD-ROM  And so on, the activity of the equipment

35、lsof

View information about the currently open file

36、ifconfig

Get network interface configuration information or modify .

ifconfig eth0 up Open a network card called eth0

ifconfig eth0 down Close network card eth0

ifconfig eth0 add 33ffe:3240:800:1005::2/64   Configure IPV6 Address

ifconfig eth0 del 33ffe:3240:800:1005::2/64     Delete IPV6 Address

ifconfig eht0 hw ether 00:aa:bb:cc:dd:ee         Modify the physical address of the network card

ifconfig eth0 192.168.120.56 netmask 255.255.255.0 broadcast 192.168.120.255 Configure network card iP Address Subnet mask and broadcast address

ifconfig eth0 arp   Enable network card eth0 Of arp agreement    -arp On behalf of closing the network card arp agreement

ifconfig eth0 mtu 1500   Set the maximum transmission unit to 1500bytes

37、route

Show routing table

route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0 Add settings gateway

route add -net 224.0.0.0 netmask 240.0.0.0 reject Add a masked route   The destination address is  224.x.x.x  Will be rejected

route del -net 224.0.0.0 netmask 240.0.0.0

route del -net 224.0.0.0 netmask 240.0.0.0 reject   Delete routing record

route del default gw 192.168.120.240

route add default gw 192.168.120.240 Delete and add default gateway

38、ping

Test network connectivity

ping -c 5  www.58.com   ping Specify the number of times a site on the public network

ping -i 3 -s 1024 -t 255  www.58.com   3 Seconds to send , The number of bytes sent is 1024,TTL = 255 It's survival time , Going through a route will be subtracted 1

39、traceroute

Detect the time required for the device to send data to the destination device until it returns , By default, a device sends data three times .

traceroute -q 4 www.58.com
traceroute to ngx-out-1.op.58.com (115.159.231.139), 64 hops max, 52 byte packets
1 localhost (172.16.140.1) 5.698 ms 8.428 ms 5.090 ms 7.119 ms     // Send data four times

traceroute -r www.baidu.com   Bypass the normal routing table Send directly to the host connected to the network

40、date cal

View the current time and date

41、grep

Keyword search

42、wc

Count the number of rows in the current file , Number of words , Number of bytes .

Use pipes ,ls - al | wc -l   View the number of files in the current directory

43、ps

View the current process

44、watch

Check the running result of the command , Periodic execution , You don't have to do it many times manually

45、at

Set timing task

One every day linux More about the command

  1. One every day linux command (1):ls command

    ls The order is linux Give the most common command .ls The order is list Abbreviation  By default ls To print out a list of the current directory  If ls Specify a different directory  The list of files and folders in the specified directory will be displayed .  adopt ls  The command can not only view linu ...

  2. One every day linux command ——halt

    halt The command is used to close the running Linux operating system .halt The command will check the system first runlevel, if runlevel by 0 or 6, Then shut down the system , Otherwise, call shutdown To shut down the system . grammar : halt( Options ) ...

  3. One every day linux command ——crontab

    crontab Commands are used to submit and manage user tasks that need to be performed periodically , And windows The next planned task is similar to , When the operating system is installed , This service tool is installed by default , And it will start automatically crond process ,crond The process is checked every minute on a regular basis ...

  4. One every day Linux command (OS X Operation on the system )

     Linux Rookies must learn 60 An order Installation and login commands :login.shutdown.halt.reboot.install.mount.umount.chsh.exit.last: File processing command :file ...

  5. One a day linux command for zipon

    linux Learning Websites :https://linuxtools-rst.readthedocs.io/zh_CN/latest/base/index.html 19.dhclient eth0 Make the network card work , ...

  6. One every day linux command ——shutdown

    shutdown The command is used to shut down the system .shutdown Command to close all programs , And according to the needs of users , To restart or shut down . grammar : shutdown( Options )( Parameters ) Options : -c: When executed “shutdown ...

  7. One every day linux command ——login

    login The command is used to give the login interface , It can be used to log back in or switch user identity , You can also change your login identity at any time through its functions . When /etc/nologin When the file exists , System only root Account login system , No other users are allowed to log in . grammar : lo ...

  8. Foreign media express : What system administrators must master 20 strip Linux command

    [51CTO.com The original manuscript ] Foreign media express is a selection of nuclear cola. Recently, it was recommended by foreign media , Hope you enjoy it ! Today's recommendations include : What system administrators must master 20 strip Linux command . Five best Linux Screen recording application .MySQ ...

  9. shock , When I run this Linux After the command , The server actually ... (Linux Delete command in )

    shock , When I run this Linux After the command , The server actually ... 0X00 Write it at the front You've all heard of the delete command rm -rf /*, But who has really practiced it ? But as a programmer , Don't look at what happens when this command is executed , How can you be reconciled ...

Random recommendation

  1. Spring There are several ways to inject it

    Ordinary injection In the configuration file <!-- Tectonic injection --> <bean id="user1" class="entity.User"> < ...

  2. SQList

    SQLite Gu Ming's thoughts are based on SQL Database software based on ,SQL Is a powerful database language , The main concept is by 「 database 」.「 Data sheet 」(table).「 Query instructions 」(queries) And so on 「 Relevance database 」( further ...

  3. Use PowerDesigner Create a table and import it into the database

    Use PowerDesigner Create a table and import it into the database Just learned to use PowerDesigner Create the database , Now I'll share how to create a table and import it into the database . 1. First, download it from the Internet PowerDesigner ...

  4. ios There are two ways to stretch pictures

    UIImage *image = [UIImage imageNamed:@"qq"]; The first one is : // Left end cap width NSInteger leftCapWidth = image. ...

  5. javascript call oc Methods

    1. introduce #import <JavaScriptCore/JavaScriptCore.h> 2.JSContext *jsContext = [self.webView valueForK ...

  6. [ mysql Optimize one ] explain explain select sentence

    NOSQL   There's no data sheet , Just some variables ,key_value  ,redis More variables are supported . You can persist files to your hard disk . mysql Relational database , There are all kinds of id The relationship between . shortcoming   High concurrent reading ...

  7. PAT TIANTI competition L2-004 Is this a binary search tree ?

    Recursive judgment + Build up trees Topic link :https://www.patest.cn/contests/gplt/L2-004 Answer key The characteristic of binary search tree is that the value of its root node is located between the left and right subtrees , That is greater than all the values of the left subtree , But little ...

  8. MongoDB Account and authority management and in Python And Java Landing in

    This paper mainly introduces MongoDB New account , Rights management ( ordinary ), And in Python,Java And login in the default client . default MongoDB There is no account authority management , in other words , You don't need a password to log in , You can have the right to read and write ...

  9. python day1 Basic grammar homework

    One . too 7 start =1 while start<=10: if start !=7: print(start) start +=1 Two .100 Within and sum = 0 start = 1 w ...

  10. MacOS Environment python3 Deploy

    MacOS Environment python3 Deploy author : Yin Zhengjie Copyright notice : Original works , Declined reprint ! Otherwise, the legal liability will be investigated . One . stay MacOS install Python3.6 1>. open python About MacOS Version of the official website ...