linux basic commands

  • 2020-05-12 06:38:46
  • OfStack

Linux provides a large number of commands that can be used to effectively perform a large number of tasks, such as disk operations, file access, directory operations, process management, file permission Settings, and so on. Therefore, working on an Linux system requires using the commands provided by the system.

Character match

* stands for any string ? It stands for 1 character [abcd...]. C is for selecting characters from inside [1-9] [a-z] represents the range [!abcd] stands for in addition to these strings

The & # 65279; redirect

ls -l /tmp > / tmp.msg is no longer displayed on the screen, but is entered into/tmp.msg date > > /tep.msg > > Means to append at the end grep 127 < /etc/hosts input redirection cp -R /usr /backup/usr.bak 2 > / bak.error error output redirection

Pipeline: take the input of one command as the input of another

ps aux | grep apache2

Command linker

ls l/etc/hosts; ls l/etc/host; Command execution sequence sudo service apache2 stop&&sudo service apache2 start service apache2 restart || sudo service apache2 restart

Command substitution character

ls-l 'which touch' takes the input of which touch as the parameter of ls-l

Directory and file management commands

ls-ald /root displays all files under /root pwd displays the current directory touch test.c create a new file test.c mkdir test creates a new directory test cp test. c /root copy test. c to /root cp-R test /root copy the test folder to /root mv test.c /root move test.c to /root mv test. c/root/test2. c motion and changed its name rm-rf /mydir does not ask for y/n, forcing the /mydir directory and its files to be deleted cat Myfile view files more Myfile pagination to view file contents, space: next 1 page, enter: next 1 line, q: exit tail-num log. txt view the file in real time before num line content ln source.txt /var/ source.txt create hard links (equivalent to copy + live update) ln-s source.txt /var/ source.txt create a soft connection (equivalent to a shortcut) sudo chmod -R 777 /sh

Compression and decompression

gzip-d file: compressed to.gz file, no directory is supported, no source files are retained, -d is uncompressed bzip2-k file: compressed to.bz2 file, which has a surprising compression ratio, -k will retain the source file. bunzip2.bz2 file: unzip the.bz2 file. tar-zxvf aa. tar. gz unzip to the current folder tar-zcvf tar.gz /etc/ aa.txt zip file, remember to use full path zip services.zip /etc/services zip test.zip /test zip is reserved source file compression. uzip zip file: unzip file;

File permissions

chmod [-R] 777 /var/home/www change file/directory permissions -R is recursive chown caokaiyan/var/home/www/aa txt change the file's owner chgrp [- R] admin/var/home/www/aa txt change file all groups

User management

useradd caokaiyan adds a user to the system passwd caokaiyan gives the user a secret Switch from su to root user sudo normal users use root user privileges, 1 normally available in Debian series linux logout log out

File search

which ls locates the absolute path to the ls command; Provides command alias information whereis ls the absolute path to the ls command; Provide help documentation information find /etc host look for a file with the name host in /etc locate host searches for files with the host name based on the linux built-in file database, and 1 updates the built-in database before looking for updatedb 1 file file: determine the file type

Network communication command

ping + ip address /URL: send a packet and see if you can get the packet back ping address: if it works, your network Settings are fine! ping 127.0.0.1(loopback address) : check whether the tip/ip protocol is installed on your machine ping + 6000 www. baidu. com: send one packet of 6000 block size to test the network connection delay ifconfig-a: view network card information; eth0 is the first network card. lo is the loopback network card. netstat-anp: monitor network status, port number, which process is listening on this port, etc. traceroute + domain name/host IP: trace routes route-n: displays the native routing table

To turn it off

shutdown -h [now/ wait time] shutdown-r [now/ wait time] restart reboot quick restart (skipping the sync data synchronization process) init 0 to turn it off init 6 restart System halt is down

View hard disk partitioning

fdisk-l [/dev/had] hard disk partitioning situation Usage of df -h hard disk partitions du-sh /root view all directory sizes under /root uname-a version number of linux

linux environment configuration

Locale view the current locale LANG= zh_CN.UTF-8 sets the current language. LANG is the environment variable You can use configuration environment variables without modifying the corresponding configuration file env lists all the environment variables date shows the current time cal displays the current calendar

Process management

ps aux looks at all the processes running ps e kill 8024 kills the process by PID Kill-9 8935 force kill process killall 8323 kills it and its child processes top monitors processes in real time

Related articles: