Commonly used linux command Daquan

Done before two years of operation and maintenance, I used a lot of command, to fully appreciate some linux command proficiency in how to enhance efficiency. Here is a simple example, often have to run some of the data after doing research and development, for processing the resulting data, the students of our products are generally used for statistical use excel, to copy the data to excel, and then disaggregated data, sorting ............ finally draw some simple conclusions, I just need cat, do the same operation between waving sort, uniq, awk, grep these orders.
  Here I summarize my work at some of the commands used in recent years, of course, here not to mention those vim cd ls mv cp this simple commands, and these commands if you will not, I suggest you first learn next. Here many commands, I simply list a few of my favorite parameters. In fact, many commands I have used is not particularly large, this article I just want to let everyone know there is such a tool, but if you want to continue with the specific understanding, then we recommend checking the manual, the part of the more command I have listed some references.

 

Directory / file processing command

mkdir dirname create a folder

mkdir -p / tmp / a / b create directories recursively

rm -rf dirname delete the directory and internal documents -r: recursive representation delete files and folders; -f: indicates a mandatory delete without prompting

touch filename to create a file

mv ins.war ins_new.war rename

mv ins.war webapps / move files to the specified directory

cp index.jsp index_new.jsp copy and rename

cp -r ./nlzbTools2 / opt / webapps / Copy nlzbTools2 directory under the current directory to the next -r / opt / webapps / directory: recursive continuous replication for copying directories

cp -r ./HouseProperty.war / opt / webapps / copy files (copy nlzbTools2.war files in the current directory to / opt / webapps /)

ls -ld / tmp / a to view a directory of information

scp remote file copy conditions: two Linux LAN to LAN can communicate, no firewall. Note: After you enter the command once prompted, enter [yes] to enter a target server account password.

scp /gxxj/apache-tomcat-7.0.78-ins/ins.war [email protected]: / data / ins.war on the server 107 passes the specified directory server 38

scp /gxxj/apache-tomcat-7.0.78-ins/ins.war [email protected]: / var / tomcat-7 / ins.war on the server 107 passes the specified directory server 45

scp -r /data/apache-tomcat-7.0.78-ins [email protected]: / var / tomcat-7/38 on the Tomcat file folders to the machine 45

scp /root/abc.zip [email protected]: / abc / /root/abc.zip should spread on 192.168.1.240 and 192.168.1.102 machine onto / abc directory, with the command unit in 192.168.1.240

scp -P 1234 /root/abc.zip [email protected]: / abc / SSH if not the default port 22, for example, port 1234 is added -P parameters

Compression / decompression command

unzip file unzip -o ac.war war

unzip abc.zip -d / home / kayak extract the files to a specified directory

tar -zcf Japan.tar.gz Japan

tar -xzvf apache-tomcat-7.0.69.tar.gz extracting tar.gz file unpacked x f v show details designated extract file decompression z

After the zip -r GISutilzip20170105 GISutil compressed files compressed zip -r filename need to compress a file name for the folder backup [more]

zip -r /home/kms/kms.zip / home / kms / server / kms compression and specify the directory

File Viewer command

vim cas.properties view the file, you can edit wq to save and quit ZZ save and exit q! forced to withdraw and ignore all the changes e! Abandon all changes and open the original file

cat filename to view file contents (not suitable for viewing long file)

tac filename above, the content is displayed upside down

more / etc / services file contents page display for viewing spaces or long file f: scroll Enter: The next line q: quit

less / etc / services as above, but supports page up, PageUp: page up and down arrow: the vertical line of input / add searchable keywords, used to find the next key position n

head -n 7 / etc / services file before displaying the contents of row 7

tail -n 3 / etc / services file displays the last three rows

tail -f / var / log / messages file at the end of the display dynamic content

./startup.sh;tail -300f ../logs/catalina.out start tomcat side edge view log (dynamic view the latest log line 300)

Link command

ln -s [original document] [link file] to create a link, -s soft link

ln -s / etc / issue /tmp/issue.soft create the file / etc / issue of soft link /tmp/issue.soft

ln / etc / issue /tmp/issue.hard create the file / etc / issue hard link /tmp/issue.hard

Soft link is a shortcut to Windows systems, hard links is equivalent to cp -p, file replication and synchronization update

Rights Management Command

chmod 777 filename assigned read and write permissions to run the file (4 read, write 2, 1 run) first number represents the owner of the file, the second number represents where the user group, the third number represents other users

chmod 754 * to all files in the current directory empowerment, owner of the file read and write can run, run user group can be read, read other users

chmod -R 777 / tmp / a to / tmp / a directory and directory permissions granted to the following 777 -R: recursively modified without permission to modify the parameter only a directory, subdirectory under the authority of a directory, for example

chown username filename change the file owner (change file ownership)

chgrp groupname filename Changes file group

umask -S The New default file permissions to rwx form, that is what the new file permissions (Note: The file type can be run automatically remove permissions)

umask 023 new file permissions set to 754 (rwxr-xr--) 023 = 777-754

User Management Commands

usaradd username create user

passwd username password

userdel -r username -r delete users delete users delete the user's home directory

Creating user groups groupadd groupname

Switching on behalf of the user's environment associated with -c:: execute only one command, without switching user identity - su - username to switch users

sudo su - switch user

w view the currently logged on user (detail)

all who view the current logged-on user

last view the user's login records, including multiple logins

View lastlog last login time for all users

touch / etc / nologin ban all users except for root login This command is to create a nologin file in the / etc directory

passwd -l username Specifies the user to log ban

passwd -u username lift the user is prohibited landing

passwd -d username Clears the user's password, the user can log in without a password

Search Commands

find [search] [criteria] consumption of resources, slow, not the best

find / -name init a comprehensive search of the file named init

find / etc -name init find files init (only the file called init will be searched out) in the directory / etc,

find / etc -name * init * find the file filename contains init in the directory / etc, the * represents multiple characters

find / etc -name init ???? Matches any single character

find -name * .text Find ending .text file

All files find path -size + 25k for the specified directory is a file size greater than + means greater than 25k, - means less than, equal to not write represents units lowercase k, M being the size of the

All files find path -size + 25M -a -size -30M find the specified directory file size is greater than and less than 30M, 25M -a represents and, -o represents or

locate filename command to establish the database, the system will periodically update files to the database, look in the library, very fast. Because the database is not updated in real time, you may not find the new file.

Update Now updatedb database, the database file is not included in the / tmp directory, even if under the command updatedb locate the file, / tmp also find less than

which cp cp command search directory and alias information where

Search directory which useradd useradd command is located

Directory search whereis useradd useradd command, as well as help document path

grep -iv [String Specifies] [File] matches the search string in the document line and outputs a case-insensitive -i       

-v exclude specified string -n: output line number

grep mysql /root/install.log find install.log file mysql in line, and list the contents of the bank --color = auto searched keyword color display

grep -v ^ # / etc / inittab to remove the lines beginning with # (comment line, ^ represents the beginning of the line)

Help command

man ls ls command to view the help information

man services View profile services help information

Network command

write <user name> to send user information to save end Ctrl + D (requires a user logged in)

linzhiling write linzhiling send a message to the user, Enter to send written information, provided that the user is already logged

wall [message] transmits broadcast information, information that is sent to all online users

mail <username> E-mail to the user, may also be used even if the network fails

ping 192.168.1.2 send packets to specify the IP address, network connectivity test, Ctrl + C stops

ping -c 3 192.168.1.2 sent three times to specify the IP address packet

ifconfig name of the NIC IP address settings and view card information

traceroute shows the path between the packet to the host

traceroute www.sina.com.cn Check your phone to routing node Sina, the general problem to view the network node which appears

netstat displays network-related information -t TCP protocol -u UDP protocol routing -r -n -l monitor displays the IP address and port number

netstat -tlun view port of the machine is listening (udp not listening state, there is only tcp)

netstat -an to see this machine all network connections ESTABLISHED: Connecting the network

netstat -rn view native routing table

netstat -ano view the port number

netstat -nat | grep -i "8080" | wc -l to view the number of connections on a port

configure the network setup

File system commonly used commands

df hl View disk consumption

du -sh a directory take up disk space, not including the file directory and subdirectories under -s: display disk space occupied by the directory, do not show its subdirectories and files take up disk space

du -h filename specified files take up disk space

du -ah --max-depth = disk footprint size and overall footprint size -a directory of 1 View a directory of all the files and folders: displays the disk space occupied by the directory,

And also displays the directory files take up disk space size; -h: displaying a human-readable manner; without --max-depth = 1 would like all the subordinate directory space are listed

System Command

top performance analysis, dynamic memory (Mem) display, Cpu occupancy

sync forces the cache data is written to the hard disk, freeing the cache area, run the sync command sync subroutine. If you must stop system, run the sync command to ensure file system integrity. The sync command system all unwritten buffers written to disk, the inode contains the modified, the delayed block I / O read and write mapping file; echo 1 0 default, clear the page cache 1, 2 and empty inode cache directory tree, 3 to clear all cache. Can be viewed through the command cat / proc / sys / vm / drop_caches.

free -m relative to the top provides a more concise view of the system memory usage

Free -9 abrupt termination process is running can lead to system resources can not be released at this time need to use the free command to reclaim memory

kill -pid kill -signal pid pid is the process number to kill the process, signal: 1 weight run (restart process (to validate the configuration, etc.)), 9 forced termination of the process, end 15

ps -ef | grep tomcat process contains a tomcat standard format of -e: show all processes -f: Full format

ps -eO lstart | grep tomcat view the detailed process of start-up time

echo $ PATH environment variable to view the system

alias View alias   

alias vi = 'vim' set an alias, with no spaces before and after the equal sign

vi /root/.bashrc make permanent aliases, you can modify the configuration file

unalias delete the alias alias

echo 1> / proc / sys / vm / drop_caches clear memory

Command history

View history command history records -c: Delete command history records -w: the cache write history command history command to save the file ~ / .bash_history (under normal circumstances would have to wait after the user exits the command to write the history of a file)

cat ~ / .bash_history View history commands to save the file is saved by default 1000 History

note

Use up and down arrows recall previous commands history

Use "! N" repeat the n th command history (history command lists history command, n get to see in the list)

Use "!!" Repeat the previous history command

Use "! String" repeat the last command beginning with that string

 

Server-related operational status command
ps
view the system process thread, I usually use this command to view the process pid, pid then do a more in-depth investigation.

Basic usage
ps -aux view all processes
ps -T -p $ {pid} to see a process of thread

References
10 important Linux ps command combat

pstree
view the system process tree, he can put the relationship between the various processes to identify it with a tree structure.

Basic usage
pstree

top
view thread running system processes, usage package of resources, system load. My usage is very high if the load on the server look and see exactly which processes more which thread occupied cpu.

The basic usage of
top lists all the threads load information
top -H load information listed all the threads of
top -H -p $ {pid} lists all the threads under load information of a pid

free
view memory usage and

Basic usage
free

File operations related
cat
I always use this command to view the configuration file, or log file, but need a little attention, the cat command will output the entire file to the terminal, and if the contents of the file is very large, it is recommended to use grep to filter, or directly less or more commands.

Basic usage
cat file.txt

tail
View the tail of a file, or view the most out of the end of the standard, the default value is displayed 10 lines, you can use the -n option to specify how many rows output.

Basic usage
tail -n 100 file.txt output the very end of the line 100
content tail -f file.txt file with the new, the new continuous output, generally used to watch real-time log

head
and tail command is very similar, but the head is the output of the head content, personal feeling head is far more than the tail command.

Basic Usage
head -n 100 file.txt beginning of the output line 100

more
is used to view files, but more command loads only the contents of a screen, you can flip down, because less loaded content, so much faster than a cat.

Basic usage
more file.txt

less
and more like, but you can flip up and down, feeling less and more needs only less on it, can be removed more ah

Basic usage
less file.txt

grep
This is my command a very common, especially when troubleshooting, you need to use grep to filter out large amounts of data from some of what I want. grep supports regular expression matching.

Basic Usage
grep "abc" file filter out the line containing the file abc from.

awk
beginning I also said that this command is one of my most commonly used commands, such as multiple columns in a file, I can use awk output of a few specific columns, or do some simple statistical summation, averaging ah , then, or do some simple data format.

Basic usage
cat data | awk '{print $ 1, $ 3, $ 5}' output 1 3 5, note that index from the start. 1
CAT Data | awk '{SUM + = $. 1} the END {Print SUM}' first column summation
cat data | awk -F '\ t ' '{print $ 1, $ 3}' each line by tab disaggregated data, and output 1 3

References
Ruan Yifeng introduced awk

sort
of standard content to do sorting,

Basic usage
cat file | sort the data in the file sorting, note that according to the dictionary order row, if you want to press the numeric row, you need to be able to add the -n option
cat file | -r sort sort -k2 -n reverse by the second column value , -k specify the first few columns, -r is flip reverse the meaning of

uniq
for good content to re-sort, pay attention to it and just adjacent to the same weight, so if you want to go global weight, you need to sort a sort.

Basic usage
cat file | sort | uniq sort the file in the file and go heavy
cat file | sort | uniq -c to file in the file sorting and de-emphasis, and output frequency of each line appears

wc
I always come up with the number of how wc, wc fact, not only can count the number of rows, you can also count how many words, how many characters.

Basic usage
file under wc -l file number in the number of firms
wc -w file how many words
wc -c file how many bytes
the number of characters wc -m file

References
http://www.runoob.com/linux/linux-comm-wc.html

sed
Parallel
Linux commands are mostly single-process, this command allows multiple processes to perform other commands.

Reference
15 minutes artifact gnu parallel entry guanzhi

scp
operation and maintenance of a large number of machines before, you usually need to batch modify a configuration file, are changing for the better on a machine, then distributed to other machines using scp script up, greatly improving efficiency.

The basic usage of
scp aaa.txt [email protected]: / tmp / aaa.txt the files in the current directory into account by the test on the 192.168.1.3 / tmp directory under
scp [email protected]: / tmp / aaa. txt., and on the contrary a

And disk IO
du
View directory size

Basic usage
du -h --max-depth = 1 1 Output deepest layer directory and the file size with the human-readable manner, such as 1K 234M 2G

df
view disk size and occupancy

Basic usage
df -h to see the size and usage of each partition

iostat
view the status of the disk io

iotop
may be similar to top directories, real-time display io status of each process.

find
find files, search criteria can be a file name, file date, file size, very strong. Before we have on the server disk is full to force the server to delete a directory under greater than 1g, and longer than two days, and the file name is * .log file is to use the find command to do plus xargs

Basic usage of
find / home / test -iname "test.txt find a file named test.txt file in the / home / test /, also supports wildcards
find / home / test -isize + 100M Find / at home / test greater than 100M document

References
wikipedia unix find

locate
the position of locating a particular file, locate command much faster than find -name, because it does not search for a specific directory, but searching a database /var/lib/mlocate/mlocate.db, this database will be through a cron regularly updated, it is possible that the new file will not be retrieved.

Basic usage
position of the locate a.txt a.txt positioning, if there are multiple a.txt system, all will be displayed.

tree
can see the tree structure,

Basic usage
tree -L 2 show two tree

Network
ping
to see whether the network through

Basic usage
ping www.baidu.com

nc
netcat, can be used to view a remote port is open, very powerful, but I used much.

Basic usage
nc -z xindoo.me 443 443 I detect whether the open port on the server (of course, is open)

References
linux nc Commands

route
to view and operate the routing tables

Basic usage
route listed in the local routing table

References
Baidu Encyclopedia route command

netstat
view network status of the machine, you can see the port occupancy and network links circumstances.

Basic usage
netstat -antp

traceroute
view a request to the server all the routing nodes through which certain, generally for troubleshooting network problems.

Basic usage
traceroute www.baidu.com

References
Baidu Encyclopedia netstat

iftop
view real-time network io situation

lsof
view the port occupancy

dig
view of domain name information, to do before the operation and maintenance of the time, often need to verify that a DNS change goes into effect, because on average, a domain name will be -A multiple ip, use the ping command can only see a ip, this time I information will resolve the domain name with a dig of view.

Basic usage
dig www.baidu.com

References
dig Commands

curl
initiate a http request, I usually use this command to verify that normal services can be accessed, it has acquired html source function.

Basic usage
curl www.baidu.com
curl -I baidu.com acquisition request of the request header www.baidu.com

References
usage curl of (English)

wget
to download a file on the network, basically there is a command-line version of the download tool.

Basic Usage
wget xindoo.me/test.txt I downloaded the file to a local server test.txt

Other
yum | apt install
is not a lot of time on the server tools we want, you can use this command to install, yum Fedora and RedHat and CentOS is in the front of Shell package manager, apt ubuntu is on the platform.

Basic usage
yum install curl
APT install curl

man
This command is used to view the manual of other commands, you can see in detail the role of a specific command, and specific parameters. This is a very important command, and generally he will command a lot of detail than each comes with -help.

Basic usage
man curl curl command to view the manuals

 

Guess you like

Origin www.cnblogs.com/wpnr/p/11938638.html