ENV:
[test@centos7 ~]$ uname -r
3.10.0-514.el7.x86_64
[test@centos7 ~]$ cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
Linux的学习,永远都是命令为基础,要想更好的操作linux系统,就要熟知基础操作命令,牢记并熟练使用命令,习惯命令linux的命令行(terminal)
命令为基础,把学的用的命令都整理一遍,做进一步的复习(man文档很强大)。
Fri 17 May 2019 01:41:44 PM CST
文件与目录管理
一、文件与目录基本操作
1.ls
NAME
ls - list directory contents
Usage: ls [OPTION]... [FILE]...
DESCRIPTION
-a, --all
do not ignore entries starting with .
-d, --directory
list directories themselves, not their contents
-i, --inode
print the index number of each file
-l use a long listing format
2.cd
NAME
cd dir Change the current directory to dir
Usage: cd [-L|[-P [-e]]] [dir]
3.cp
NAME
cp - copy files and directories
Usage: cp [OPTION]... [-T] SOURCE DEST
cp [OPTION]... SOURCE... DIRECTORY
cp [OPTION]... -t DIRECTORY SOURCE...
DESCRIPTION
-R, -r, --recursive
copy directories recursively
-u, --update
copy only when the SOURCE file is newer than the destination
file or when the destination file is missing
4.mv
NAME
mv - move (rename) files
Usage: mv [OPTION]... [-T] SOURCE DEST
mv [OPTION]... SOURCE... DIRECTORY
mv [OPTION]... -t DIRECTORY SOURCE...
DESCRIPTION
-f, --force
do not prompt before overwriting
-u, --update
move only when the SOURCE file is newer than the destination
file or when the destination file is missing
5.pwd
NAME
pwd - print name of current/working directory
Usage: pwd [OPTION]...
6.rm
NAME
rm - remove files or directories
Usage: rm [OPTION]... FILE...
DESCRIPTION
-f, --force
ignore nonexistent files and arguments, never prompt
-r, -R, --recursive
remove directories and their contents recursively
7.mkdir
NAME
mkdir - make directories
Usage: mkdir [OPTION]... DIRECTORY...
DESCRIPTION
-p, --parents
no error if existing, make parent directories as needed
8.rmdir
NAME
rmdir - remove empty directories
Usage: rmdir [OPTION]... DIRECTORY...
DESCRIPTION
-p, --parents
remove DIRECTORY and its ancestors
9.cat
NAME
cat - concatenate files and print on the standard output
Usage: cat [OPTION]... [FILE]...
10.touch
NAME
touch - change file timestamps
Usage: touch [OPTION]... FILE...
DESCRIPTION
-d, --date=STRING
parse STRING and use it instead of current time
--time=WORD
change the specified time
11.ln
NAME
ln - make links between files
Usage: ln [OPTION]... [-T] TARGET LINK_NAME (1st form)
ln [OPTION]... TARGET (2nd form)
ln [OPTION]... TARGET... DIRECTORY (3rd form)
ln [OPTION]... -t DIRECTORY TARGET... (4th form)
DESCRIPTION
-L, --logical
dereference TARGETs that are symbolic links
-s, --symbolic
make symbolic links instead of hard links
12.dd
NAME
dd - convert and copy a file
Usage: dd [OPERAND]...
dd OPTION
DESCRIPTION
bs=BYTES
read and write up to BYTES bytes at a time
count=N
copy only N input blocks
if=FILE
read from FILE instead of stdin
of=FILE
write to FILE instead of stdout
seek=N skip N obs-sized blocks at start of output
skip=N skip N ibs-sized blocks at start of input
13.rename
NAME
rename - rename files
Usage: rename [options] expression replacement file...
二、文件查看、权限与属性
1.more
NAME
more - file perusal filter for crt viewing
Usage: more [options] file [...]
2.less
NAME
less - opposite of more
Usage: less -?
less --help
less -V
less --version
less [-[+]aABcCdeEfFgGiIJKLmMnNqQrRsSuUVwWX~]
[-b space] [-h lines] [-j line] [-k keyfile]
[-{oO} logfile] [-p pattern] [-P prompt] [-t tag]
[-T tagsfile] [-x tab,...] [-y lines] [-[z] lines]
[-# shift] [+[+]cmd] [--] [filename]...
(See the OPTIONS section for alternate option syntax with long option
names.)
3.head
NAME
head - output the first part of files
Usage: head [OPTION]... [FILE]...
4.tail
NAME
tail - output the last part of files
Usage: tail [OPTION]... [FILE]...
DESCRIPTION
-n, --lines=K
output the last K lines, instead of the last 10; or use -n +K to
output starting with the Kth
-f, --follow[={name|descriptor}]
output appended data as the file grows;
5.cut
NAME
cut - remove sections from each line of files
Usage: cut OPTION... [FILE]...
6.stat
NAME
stat - display file or file system status
Usage: stat [OPTION]... FILE...
DESCRIPTION
-f, --file-system
display file system status instead of file status
7.chown
NAME
chown - change file owner and group
Usage: chown [OPTION]... [OWNER][:[GROUP]] FILE...
chown [OPTION]... --reference=RFILE FILE...
DESCRIPTION
-f, --silent, --quiet
suppress most error messages
-R, --recursive
operate on files and directories recursively
8.chgrp
NAME
chgrp - change group ownership
Usage: chgrp [OPTION]... GROUP FILE...
chgrp [OPTION]... --reference=RFILE FILE...
DESCRIPTION
-f, --silent, --quiet
suppress most error messages
-R, --recursive
operate on files and directories recursively
9.chmod
NAME
chmod - change file mode bits
Usage: chmod [OPTION]... MODE[,MODE]... FILE...
chmod [OPTION]... OCTAL-MODE FILE...
chmod [OPTION]... --reference=RFILE FILE...
DESCRIPTION
The letters rwxXst select file mode bits for the affected users:
read(r), write (w), execute (or search for directories) (x)
A numeric mode is from one to four octal digits (0-7), derived by
adding up the bits with values 4, 2, and 1
10.chattr
NAME
chattr - change file attributes on a Linux file system
Usage: chattr [ -RVf ] [ -v version ] [ mode ] files...
DESCRIPTION
The letters 'aAcCdDeijsStTu' select the new attributes for the files:
append only (a), no atime updates (A), compressed (c), no copy on write
(C), no dump (d), synchronous directory updates (D), extent format (e),
immutable (i), data journalling (j), secure deletion (s), synchronous
updates (S), no tail-merging (t), top of directory hierarchy (T), and
undeletable (u)
11.whereis
NAME
whereis - locate the binary, source, and manual page files for a command
Usage: whereis [options] [-BMS directory... -f] name...
DESCRIPTION
-b Search only for binaries.
-m Search only for manuals.
-s Search only for sources.
-u Only show the command names that have unusual entries
12.which
NAME
which - shows the full path of (shell) commands
Usage: which [options] [--] programname [...]
DESCRIPTION
--all, -a
Print all matching executables in PATH, not just the first
--read-alias, -i
Read aliases from stdin, reporting matching ones on stdout
13.lsattr
NAME
lsattr - list file attributes on a Linux second extended file system
Usage: lsattr [ -RVadv ] [ files... ]
DESCRIPTION
-a List all files in directories, including files that start with `.'.
-d List directories like other files, rather than listing their contents.
三、文件查找与比较
1.find
NAME
find - search for files in a directory hierarchy
Usage: find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]
DESCRIPTION
-depth Process each directory's contents before the directory itself.
The -delete action also implies -depth.
-maxdepth levels
Descend at most levels (a non-negative integer) levels of direc‐
tories below the command line arguments
Numeric arguments can be specified as
+n for greater than n,
-n for less than n,
n for exactly n.
-amin n
File was last accessed n minutes ago.
-atime n
File was last accessed n*24 hours ago.
-cmin n
File's status was last changed n minutes ago.
-ctime n
File's status was last changed n*24 hours ago.
-group gname
File belongs to group gname (numeric group ID allowed).
-size n[cwbkMG]
File uses n units of space.
-type c
File is of type c:
b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link;
s socket
D door (Solaris)
-uid n File's numeric user ID is n.
-user uname
File is owned by user uname (numeric user ID allowed).
2.grep
NAME
grep, egrep, fgrep - print lines matching a pattern
Usage: grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]
DESCRIPTION
-E, --extended-regexp
Interpret PATTERN as an extended regular expression
-F, --fixed-strings, --fixed-regexp
Interpret PATTERN as a list of fixed strings, separated by
newlines, any of which is to be matched.
3.cmp
NAME
cmp - compare two files byte by byte
Usage: cmp [OPTION]... FILE1 [FILE2 [SKIP1 [SKIP2]]]
DESCRIPTION
-b, --print-bytes
print differing bytes
-s, --quiet, --silent
suppress all normal output
4.diff
NAME
diff - compare files line by line
Usage: diff [OPTION]... FILES
DESCRIPTION
5.diff3
NAME
diff3 - compare three files line by line
Usage: diff3 [OPTION]... MYFILE OLDFILE YOURFILE
DESCRIPTION
-A, --show-all
output all changes, bracketing conflicts
四、文件压缩与解压缩
1.tar
NAME
tar - manual page for tar 1.26
Usage: tar [OPTION...] [FILE]...
DESCRIPTION
-c, --create
create a new archive
-d, --diff, --compare
find differences between archive and file system
-t, --list
list the contents of an archive
-u, --update
only append files newer than copy in archive
-x, --extract, --get
extract files from an archive
-C, --directory=DIR
change to directory DIR
-j, --bzip2
filter the archive through bzip2
-J, --xz
filter the archive through xz
-z, --gzip
filter the archive through gzip
2.gzip
NAME
gzip, gunzip, zcat - compress or expand files
Usage: gzip [ -acdfhlLnNrtvV19 ] [-S suffix] [ name ... ]
gunzip [ -acfhlLnNrtvV ] [-S suffix] [ name ... ]
zcat [ -fhLV ] [ name ... ]
DESCRIPTION
3.gunzip
the same as gzip
4.zip
NAME
zip - package and compress (archive) files
Usage: zip [-aABcdDeEfFghjklLmoqrRSTuvVwXyz!@$] [--longoption ...] [-b path]
[-n suffixes] [-t date] [-tt date] [zipfile [file ...]] [-xi list]
DESCRIPTION
add
Update existing entries and add new files.
update (-u)
Update existing entries if newer on the file system and add new
files.
5.unzip
NAME
unzip - list, test and extract compressed files in a ZIP archive
Usage: unzip [-Z] [-cflptTuvz[abjnoqsCDKLMUVWX$/:^]] file[.zip] [file(s) ...]
[-x xfile(s) ...] [-d exdir]
DESCRIPTION
五、其他
1.uniq
NAME
uniq - report or omit repeated lines
Usage: uniq [OPTION]... [INPUT [OUTPUT]]
DESCRIPTION
-c, --count
prefix lines by the number of occurrences
-u, --unique
only print unique lines
2.wc
NAME
wc - print newline, word, and byte counts for each file
Usage: wc [OPTION]... [FILE]...
wc [OPTION]... --files0-from=F
DESCRIPTION
-c, --bytes
print the byte counts
-m, --chars
print the character counts
-l, --lines
print the newline counts
-w, --words
print the word counts
3.sort
NAME
sort - sort lines of text files
Usage: sort [OPTION]... [FILE]...
sort [OPTION]... --files0-from=F
DESCRIPTION
4.tr
NAME
tr - translate or delete characters
Usage: tr [OPTION]... SET1 [SET2]
DESCRIPTION
-c, -C, --complement
use the complement of SET1
-d, --delete
delete characters in SET1, do not translat
5.tac
NAME
tac - concatenate and print files in reverse
Usage: tac [OPTION]... [FILE]...
DESCRIPTION
-b, --before
attach the separator before instead of after
6.paste
NAME
paste - merge lines of files
Usage: paste [OPTION]... [FILE]...
DESCRIPTION
7.pr
NAME
pr - convert text files for printing
Usage: pr [OPTION]... [FILE]...
DESCRIPTION
8.rev
NAME
rev - reverse lines of a file or files
Usage: rev [options] [file ...]
DESCRIPTION
9.ftp
no used
10.scp
NAME
scp — secure copy (remote file copy program)
Usage: scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
[-l limit] [-o ssh_option] [-P port] [-S program]
[[user@]host1:]file1 ... [[user@]host2:]file2
DESCRIPTION
-P port
Specifies the port to connect to on the remote host.
-r Recursively copy entire directories.
-q Quiet mode: disables the progress meter as well as warning and
diagnostic messages from ssh(1).