/boot///store kernel, boot file directory
Note:all files under Linux, such as the keyboard, mouse and so on in the Linux are embodied as a file, but some files can not be opened directly, you need to use the program or software Call 2. View and retrieve file CD commandsCD < directory path to enter >
Switch the directory (equivalent to a mouse double-click into a directory in Windows, directly view the contents of the directory)
Example :
pwd
View your current directory
cd /etc/
Switch from the current path to the/etc/directory
cd 或 cd ~
Enter the current login user home directory
cd -
Go to last switch directory
Relative path and absolute path
relative path : Represents the position starting from the current path;./For the current directory, ... /represents the upper-level path
Absolute Path : The full representation of the path starting from "/"
Example :
① represents the "/etc/sysconfig/network-scripts/ifcfg-eth0" file location, currently located in the "etc/" directory
Relative path:./sysconfig/network-scripts/ifcfg-eth0 or Sysconfig/network-scripts/ifcfg-eth0
Absolute path:/etc/sysconfig/network-scripts/ifcfg-eth0
② represents the "/etc/hosts" file location, currently located in the "/etc/sysconfig/network-scripts/" directory
Relative path: /.. /hosts
Absolute path/etc/hosts
Note : Generally relatively more convenient than absolute use, can reduce the file structure, of course, according to the customary use can
Cat commandCat [Options] File name:
Display file contents to view multiple file contents at the same time
Options :
-N: Show line numbers
-A: Displays all special symbols in the file, such as "$" terminator, etc.
Example :
cat /etc/hosts
View/etc/hosts file contents
cat -n /etc/hosts
View/etc/hosts file contents and display line numbers
cat -A /etc/hosts
View the contents of the/etc/hosts file and all its special symbols
More commandsMore [options] File name ...
Full screen display of the contents of the file, can be paged to view multiple files at the same time
shortcut keys :
Enter key: Line down
SPACEBAR: Turn down one page
Q Key: Exit
Example :
more /root/anaconda-ks.cfg
Paging View/root/anaconda-ks.cfg File
Note : More can only be turned upside down, cannot go up
Less commandLess [options] file name ...
Same as the more command, but supports scrolling up and down, and supports the search function
shortcut keys :
Page UP key: Page UP
Page DOWN key: Page Down
/text: Find specified file in file
N: Jumps to the next address in the search text in the file
N: Jump to the previous address in the file to search for files
Q Key: Exit
Example :
less /root/anaconda-ks.cfg
Detailed Head commandHead-n file name ...
View part of the beginning of a file (default is 10 lines)
head /root/anaconda-ks.cfg
View the beginning of the file 10 lines
head -3 /root/anaconda-ks.cfg
View the beginning of the file 3 lines
Tail commandTail-n file name ...
View a portion of the end of the file (default is 10 lines)
Options :
-F: Dynamic update To view the end of the file, real-time monitoring file changes (CTRL + C key termination), generally used for the log
Example :
tail /root/anaconda-ks.cfg
View end of file 10 lines
tail -3 /root/anaconda-ks.cfg
View end of File 3 lines
tail -f /var/log/messages
To view the public message log file dynamically
WC commandWC [Options] File
Information about the number of words in the statistics file (Word Count), file size, number of file lines, and more
Options :
-L: Count rows
-W: Count the number of words, separated by spaces
-C: Statistics of bytes
Example :
wc /etc/hosts
The situation of statistical/etc/hosts
Note : When using the WC command, do not follow any options, default use WC-LWC
wc -l /etc/hosts
Count the number of lines in a/etc/hosts file
wc -l /etc/passwd
Count/etc/passwd file lines to get the number of accounts in the system
find /etc -name "*.conf" | wc -l
Statistics. conf number of files ending in
grep commandgrep [Options] ... < find criteria > < destination file >
Finds and displays the line containing the specified string in the file
Options :
-I: Ignore case when finding
-V: Reverse lookup, output rows that do not match the condition
Search Criteria :
The searched string should be enclosed in double quotation marks ("").
"^ ..." means ... The beginning, "... $" represents a ... End
"^$" indicates a blank line
Example :
grep "f" /etc/inittab
Filter the lines in the display file that contain F (match lowercase characters F only)
grep -i "f" /etc/inittab
Filter the lines in the display file that contain F (ignoring case, case f)
grep "f$" /etc/inittab
Filter the lines that end with F in the display file
grep "^i" /etc/inittab
Filter the lines that start with I in the display file
grep -v "^#" /etc/inittab
Filter the remaining lines in the display file except #
grep -v "^$" /etc/inittab
To filter the remaining lines in the file that are empty lines apart
grep -v "^#" /etc/inittab | grep -v "^$"
Display valid lines in a file (no blank lines and # start lines are displayed)
3. File compression and archiving gzip and gunzipgzip [-9] < filename ...//compression
GZIP-D xx.gz Format compressed file or gunzip xx.gz format compressed file//Unzip
Use the GZIP compression algorithm to compress files, unzip compressed files (can reduce file occupancy, but not absolute)
Options :
-9: High compression ratio, compressed files smaller (from 0~9, the larger the number, the higher the compression ratio, the default is 6)
-D: For extracting files
Example :
dd if=/dev/zero of=/root/test bs=100M count=1
Generate a test file of size 100M
gzip /root/test
Use gzip to compress the file, the original file is lost and changed to Test.gz
gzip -d /root/test.gz
Unzip the test.gz file to the original directory
Note : Only files compressed using gzip can be decompressed, with the suffix. gz
gzip -9 /root/test
High compression ratio using gzip compressed files, default to 6
gunzip /root/test.gz
Unzip using the Gunzip command, as with the gzip-d effect
Bzip2 and BUNZIP2bzip2 [-9] < filename ...//compression
BZIP2-D xx.bz2 Format compressed file or BUNZIP2 xx.bz2 format compressed file//Unzip
Use the BZIP2 compression algorithm to compress files, extract compressed files (can reduce file occupancy, but not absolute)
Options :
-9: High compression ratio, compressed files smaller (from 0~9, the larger the number, the higher the compression ratio, the default is 6)
-D: For extracting files
Example :
bzip2 /root/test
Use bzip2 to compress the file, the original file is lost and changed to TEST.BZ2
bzip2 -d /root/test.bz2
Unzip the test.bz2 file to the original directory
Note : Only files compressed using the Bzip2 method can be decompressed, with the suffix. bz2
bzip2 -9 /root/test
High compression ratio using bzip2 compressed files, default to 6
bunzip2 /root/test.bz2
Unzip using the BUNZIP2 command, as with the bzip2-d effect
XzXZ [-9] < filename ...//compression
xz-d compressed files//decompression in XX.XZ format
Use the XZ compression algorithm to compress files, extract compressed files (can reduce file occupancy, but not absolute)
Options :
-9: High compression ratio, compressed files smaller (from 0~9, the larger the number, the higher the compression ratio, the default is 6)
-D: For extracting files
Example :
xz /root/test
Use XZ mode to compress the file, the original file is lost to Test.xz
xz -d /root/test.xz
Unzip the Test.xz file to the original directory
Note : Only files compressed using XZ mode can be decompressed, with the suffix. XZ
xz -9 /root/test
High compression ratio using XZ compressed files, default to 6
xz -d /root/test.xz
Unzip the Test.xz file to the original directory
Comparison of three compression modes