Linux common commands 1

find
f (normal file) d (directory)
find: find directory -type -f
delete: find directory -type -f -exec rm -f {} \;
find: find directory -type -d
delete: find directory -type - d -exec rm -f {} \;
cat view file
cat -n add line number (only read, do not change)
cat -s merge multiple blank lines into one (only read, do not change)
cat >> test .txt<<EOF
content
EOF exit
tac line view in reverse order
wc -c view the number of bytes in the file
wc -m view the number of characters in the file
wc -l view the number of lines in the file
wc -w view the number of words in the file (space and newline cutting)
wc -L Check the length of the longest line
sort sort by first character from smallest to largest
sort -r sort by first character from largest to smallest
sort -h sort by number from smallest to largest
sort -f ignore case
sort -b ignore preceding spaces
sort -u The same data only has one row of
uniq Ignore or report duplicate rows
date Display time (I is 12-hour format H is 24-hour format)
date +"%Y%m%d %H%M%S"
20160824 223856
date +"%Y-%m-%d %H:%M:%S"
2016-08-24 22:39:07
date +"%Y-%m-%d %I:%M:%S"
2018-04-11 02:09:26
date -s Modify the date or time
date -s 20180411 //The time will become 00:00:00
date -s 16:59:59 //The time will not change
date after setting -s "12:12:23 2006-10-10" //This can set all the time
. After resetting the time, it needs to be synchronized to the hardware, the following command:
hwclock -w
cal display the current calendar
cal -y display the one-year calendar
cal 2017 display 2017 calendar
tzselect set time zone
passwd change password
passwd username change username password
logout logout
reboot restart
shutdown shutdown
shutdown -r now //restart immediately
shutdown -r +5 //restart shutdown after 5 minutes
-r 12:12 //12: 12 Restart
shutdown -h now //shutdown immediately
shutdown -h +5 //shutdown after 5 minutes
shutdown -h 12:12 //shutdown at 12:12
shutdown -c //Cancel the shutdown operation
cd switch directory
cd Return to the current user's home directory
cd .. switch to the previous directory
cd - switch to the previous directory
pwd View the current directory path
mkdir Create a directory
mkdir -pa/b/c/d Recursively create a directory
man View help
man -k Fuzzy search
man -f Find exactly
when touch changes a file or directory, if the file does not exist, create a new file
touch -c Do not create a file
touch -r test1 test2 test3 Compare the time of test2 and test3 Modify it to be consistent with the time of test1
touch -t 201804100922.08 test1
rm delete
rm -f force delete
rm -r delete a directory and its subordinate directories and files
rm -rf force delete a directory and its subordinate directories and files
mv move or reorder directory files
mv test.log test.txt file renamed
mv test1.txt girl/ move file
mv test1 test2 test3 girl/ move multiple files
cp copy
cp -r recursively copy all cp under the folder
-i will prompt when overwriting
cp -p At this time, in addition to copying the content of the source file, cp will also copy its modification time and access rights to the new file
stat View file related information
stat filename
# Access time(atime): refers to the time when the file is accessed , the so-called access, common operations are: use the editor to view the file content, use the cat command to display the file content, use the cp command to copy the file (ie the source file) into other files, or use grep sed more less on this file Commands such as tail head, all operations that read and do not modify the file will change the Access time of the file in a balanced manner.
# Modify time(mtime): Refers to the time to modify the content of the file, as long as the content of the file is changed (such as using steering output or steering additional method) or the operation of saving to disk, it will change the Modify time of the file. Usually, when we use ls -l to view the file, the displayed time is the Modify time
# Change time(ctime): It refers to the time when the file attribute or file location is changed. If you use chmod, chown, mv instruction set to use ln as a hard connection to the file, it will change the Change time of the file.
history View the executed commands
history 5 The last 5 commands
! number Execute the historical command number
! cat Execute the last cat execution The command
cut command can extract text columns from a text file or text stream.
-d : followed by a delimiter character. Used together with -f;
-f : Divide a piece of information into several segments according to the separator character of -d, and use -f to take out the meaning of the first paragraph;
-c : Take out the fixed character range in units of characters
tee reads data from standard input and outputs its contents to a file.
cat sec.log | tee file1 # Read sec.log and generate file1 file
cat sec.log | tee - a file1 # Read sec.log and append,
cat sec.log |tee file1 file2
more View file content
less View the content of the file
head View the first 10 lines of the file
head -n 5 file View the first 5 lines of the
file tail View the last 10 lines of the
file tail -n 5 file View the last 5 lines of the
file tail -f file Dynamic monitoring file
which Find other command locations
ls Query
ls -a all
ls -l details
ls -r English alphabetical sorting
ls -t time sorting
file types:
- ordinary file
d directory file
b block device file
c character device file
i link file
p pipe file
s spcket file
file permissions
rwxrwxr--: The three groups of rwx represent the permissions of the owner, all groups, and others.
r: means readable, can be represented by number 4
w: writable, can be represented by number 2
x : means executable, which can be represented by number 1
- : means no corresponding permission can be represented by number 0
Method of modifying permission:
chmod o+w file1
chmod gw file1
chmod go-w file1
chmod u=rwx file1
chmod 755 file1 # -rwxr-xr-x (755) only owner has read, write, execute permissions, group and others only have read and execute permissions
chmod 644 # -rw-r--r-- (644) only The owner has read and write permissions, and the group and others have only read permissions
# where:
# u represents the owner (user)
# g represents the owner's group (group)
# o represents others, but not u and g (other) # a represents all people, that is, including the permissions on the
u, g and o directories: r: Indicates whether the file name in the directory can be read w: Indicates whether the file can be created and modified in the directory x : Indicates whether the directory can be searched . After having x permission, the file can be executed in the way of ./a.py. chown : Change the owner and all groups of a file chown root:root file chown root file chown :root file








Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324761472&siteId=291194637