Summary -linux commonly used commands

 1. commonly used commands

ls displays the file or directory

-a list all files and directories in the current directory, including hidden a (all)
the -l lists the file details L (List)
-al list all files in the current directory and detailed information, including hidden a (all )

Create a directory mkdir

-p create a directory, if not the parent directory, create a parent directory, such as: mkdir -p parent / child

cd Change directory

cd .. back to the parent directory

back to the root directory cd ~

rmdir to delete empty directories

rm delete files

# rm file name to delete a file, you are prompted to delete

rm -f filename # delete a file, you are not prompted to delete

rm -r / dir / dir1 / dir2 # delete a directory, you are prompted to delete

rm -rf / dir / dir1 / dir2 # delete a directory, you are not prompted to delete

Create an empty file touch

mv move or rename

mv / root / etc / tmp # etc files to / tmp directory

mv aaa abc # file name into abc aaa

cp copy

cp / root / aa / opt / # aa copied to the file directory opt

cp / root / aa / opt / bb # aa file copied to opt directory, and starting a new file name

cp -r / dir / dir1 / dir / dir2 # dir2 copy directory to directory dir1

cp -i # asking to overwrite while copying

find search for a file in the file system
pathname: directory path to find the command you are looking for. For example. To indicate the current directory, / root system is represented. (Example: the Find ./dir/ test.js)
-name find files by file name. (Example: the Find -name test.js)
-perm to find files by file permissions.
-user according to the file owner to locate the file.
-group according to the group the file belongs to locate the file.
-type locate a file type
(b - block device file .d - Catalog .c - character device file .p - pipe files.
L - symbolic link file .f - normal files.)
-print: Find command will match files to standard output.
-size n [c] lookup file block length n files, file length in bytes indicates time with c.
-depth look at the file, first locate the file in the current directory, and then look at its subdirectories

pwd displays the current absolute path

for echo output string

echo "It is a test"> myfile # contents of the left over the right side of the file contents
echo "It is a test" contents >> myfile # appended to the left of the file myfile

(Cat / etc / password> new_pass.txt # content of the left cover to the right of the file contents)

grep is used to find files in qualifying string

# Find filename inside 'str' string
grep 'str' filename

# In the current directory, find the file suffix words have file contains files test string, and print out the line of the string
grep test * file

# Recursively find qualified files. For example, to find the specified directory / etc / acpi and its subdirectories (subdirectories if one exists) all the files that contain the string "update" file, and print out the contents of the line where the string
grep -r update / etc / acpi

ps is used to report the current state of the system process

ps aux | grep amoeba # View amoeba process

#ps displays the current status is in the process of running, grep indicates that the search in these years, but ps aux that all processes and display its status.

ps -ef | grep tomcat-web # View tomcat-web process number
kill -9 process ID # kill process

 wc statistics the number of rows of text, words, characters

wc -l # statistics rows
wc -c # number of bytes of
wc counts the number of characters -m #, can not be used in conjunction with -c
wc -w # word count
wc -L # printing longest length

cat / etc / passwd | wc -l # view the file contents, and statistics / etc / passwd file line number
cat / etc / passwd | wc -L # view the file contents, and the length of the longest statistics

cat file path / filename to view the contents of the file

head file path / file name display the first N lines, 10 lines before the default display

The first n lines head -n file path / file name display #

tail file path / file name after the display of N lines, line 10 after the default display

tail -n file path / file name of the file # n lines of the display

tail -f file path / filename # dynamic print file content

date lists current system time

 

2. The system directory

bin directory: commonly used to store executable file

sbin directory: system used to store executable file

Home directory: / home / username used to store the user's own files or directories

dev directory: device file directory

etc directory: Profiles directory

tmp directory: temporary files directory

/ Opt / media / mnt # free to use

 

3. User Management

useradd username to add users

useradd -u 100 -g ljp -d / home / ljp -c test # -u 100: uid designated as 100 -g ljp: shared by a group ljp -d / home / ljp: ljp stored in the home directory -c test: Remarks information

passwd username modify user password

Delete user userdel username

su user switch user, loading a configuration file .bashrc (cut only the user name change, environment variables do not change)

su -user switch user, loading a configuration file / etc / profile (run environment variable)

4. File Rights Management

Three basic rights:
R & lt readings expressed as 4
to write the value W is represented as 2
X-values are expressed as an executable

"-Rw-rw-r--" a total of ten characters, divided into four sections.
"-" the first character indicates a normal file; (may also appear "l" link; "D" indicates a directory)
, "rw-" thirty-four second character represents user privileges currently belongs (4 + 2 values are expressed as 6 =)
"rw-" the first five hundred sixty-seven character, represents the rights of the current belongs. (Values are expressed as + 2 =. 6. 4)
"r--" ninety eighth character, showing another user rights (2 values are expressed as

 chmod [u belongs to the user group belong g o all users other users a] [+ Permissions increase - decrease permission] [r w x] directory name

chmod  777  text.txt  

chmod u+x g+w o+r  text.txt

chown to modify the file belongs to group

chown [option] ... [user] [: [group]] files ...

# File1.txt owner of the file to runoob, user groups runoobgroup:
chown runoob: runoobgroup file1.txt

# The current directory of all the files and subdirectories owned by key set runoob, user groups runoobgroup:
chown -R runoob: runoobgroup *

 

5. System Management Command

who # show online users log on

Display current user whoami #

hostname # show hostname

display system information uname #

ipconfig # View network conditions

Address # ping test network connectivity

netstat # display network status information

top # dynamically display the current resource consumption of the most process information

 

6. Shutdown / reboot

the shutdown
-r restart shutdown
-h shutdown not restart
now shut down immediately
halt shutdown
reboot reboot

init 0 shutdown

 

7. file compression decompression process

tar, unpackages

t: View

c f :create filename 

v: display the archiving process

z; Compression

x: unpack

tar -cf test.tar a.txt b.txt c.txt # a.txt b.txt c.txt compressed file to test.tar

tar -cvfz test.tar a.txt b.txt c.txt # a.txt b.txt c.txt compressed file to test.tar, displaying the archiving process

tar -tf test.tar # to see which files contain test.tar

tar xvf /tmp/test/test.tar -C / opt / # extracting file directory to opt

gzip compression

gzip test.txt   #生成test.txt.gz

gunzip unpacked

gunzip test.txt.gz    #生成test.txt

 

Guess you like

Origin www.cnblogs.com/lijinping716/p/11545589.html