目录操作命令(6个)
ls tree pwd mkdir rmdir cd
其中tree在/usr/bin下面,其他在/bin下
—ls—
-a: 显示隐藏目录
-l: use a long listing format
-c: show create time and sort by ctime
-t: sort by modification time
-d */: list director
-h: human readable
-o: 类似-l,但不显示group
-g: 类似-l,但不先手onwer
-n: 类似-l,udi和gid用数字代替
-r: reverse显示
-i: 显示inode
-S: sort by file size
-1 :每行列一个文件或者目录
—tree—
-L: level, Max display depth of the derectory tree
-a : all files are printed, 不包括.,包括.bashrc
–pwd—
—mkdir— and —rmdir—
-p : parents
-v : verbose
—cd—
文件操作命令(7个)
touch cp mv rm ln find rename
只有rename在/usr/bin下面,其他都在/bin下
—touch—
注意如果文件存在,touch会把文件的stamp都改了,但内容保留
-a:更改访问时间
-m:可更改修改时间
—cp—
此命令总是有提示,是因为root/.bashrc中定义了alias。如果不想看提示,可以使用/bin/cp 或者\cp
-r: copy directories
-p: 保持属性
-v:explain what is being done
—mv— mv [option] … source dest
对文件和文件夹都实用
-f : force, do not prompt befor overwritig,如果dest已有相同名字的文件
—rm—
remove files or directories, 同样定义了alias
-f:force, ignore nonexistent files, and never prompt
-r : recursive
-v: verbose
—ln—
-s :symblic
—find—
find [pathnames] [conditions]
An extremely useful command for finding particular groups of files (numerous examples follow this description). find descends(降序) the directory tree beginning at each pathname and locates files that meet the specified conditions. The default pathname is the current directory. The most useful conditions include -name and -type (for general use), -exec and -size (for advanced use), and -mtime and -user (for administrators).
Conditions(匹配规则) may be grouped by enclosing them in ( **) (escaped parentheses), negated with !, given as alternatives by separating them with -o, or repeated (adding restrictions to the match; usually only for -name, -type, or -perm). **Note that “modification” refers to editing of a file’s contents, whereas “change” means a modification, or permission or ownership changes. In other words, -ctime is more inclusive(范围广的) than -atime or -mtime.
Conditions and actions
-amin +n| -n| n
Find files last accessed more than n (+n), less than n (-n), or exactly n minutes ago.
-anewer file 查找其存取时间较指定文件或目录的存取时间更接近现在的文件或目录。
Find files that were accessed after file was last modified. Affected by -follow when after -follow on the command line.
-atime +n| -n| n
Find files that were last accessed more than n (+n), less than n (-n), or exactly n days ago. Note that find changes the access time of directories supplied as pathnames.
-cmin +n| -n| n
Find files last changed more than n (+n), less than n (-n), or exactly n minutes ago.
-cnewer file
Find files that were changed after they were last modified. Affected by -follow when after -follow on the command line.
-ctime +n| -n| n
Find files that were changed more than n (+n), less than n (-n), or exactly n days ago. A change is anything that changes the directory entry for the file, such as a chmod.
-daystart???
Calculate times from the start of the day today, not 24 hours ago.
-depth从指定目录下最深层的子目录开始查找。???
Descend the directory tree, skipping directories and working on actual files first, and then the parent directories. Useful when files reside[ri`zaid]居住 in unwritable directories (e.g., when using find with cpio).
-empty???
Continue if file is empty. Applies to regular files and directories.
-exec command{ } \ ;
Run the Linux command, from the starting directory on each file matched by find (provided command executes successfully on that file—i.e., returns a 0 exit status). When command runs, the argument { } substitutes the current file. Follow the entire sequence with an escaped转义 semicolon分号 (\;). In some shells, the braces 大括号may need to be escaped as well.
-false
Return false value for each file encountered.
-follow排除软链接
Follow symbolic links and track the directories visited (don’t use with -type l).
-fstype type
Match files only on type filesystems. Acceptable types include minix, ext, ext2, xia, msdos, umsdos, vfat, proc, nfs, iso9660, hpfs, sysv, smb, and ncpfs.
-gid num
Find files with numeric group ID of num.
-group gname
Find files belonging to group gname. gname can be a group name or a group ID number.
-ilname pattern
A case-insensitive忽略大小写 version of -lname.
-iname pattern
A case-insensitive version of -name.
-inum n
Find files whose inode number is n.
-ipath pattern
A case-insensitive version of -path.
-iregex pattern
A case-insensitive version of -regex.
-links n
Find files having n links.
-lname pattern
Search for files that are symbolic links, pointing to files named pattern. pattern can include shell metacharacters and does not treat / or . specially. The match is case-insensitive.
-maxdepth num
Do not descend more than num levels of directories.
-mindepth num
Begin applying tests and actions only at levels deeper than num levels.
-mmin +n| -n| n
Find files last modified more than n (+n), less than n (-n), or exactly n minutes ago.
-mount, -xdev
Search only for files that reside on the same filesystem as pathname.
-mtime +n| -n| n
Find files that were last modified more than n (+n), less than n (-n), or exactly n days ago. A modification is a change to a file’s data.
-name pattern
Find files whose names match pattern. Filename metacharacters may be used but should be escaped or quoted.
-newer file
Find files that were modified more recently than file; similar to -mtime. Affected by -follow only if it occurs after -follow on the command line.
-nogroup
The file’s group ID does not correspond to any group.
-noleaf
Normally, find assumes that each directory has at least two hard links that should be ignored (a hard link for its name and one for “.”–i.e., two fewer “real” directories than its hard link count indicates). -noleaf turns off this assumption, a useful practice when find runs on non-Unix-style filesystems. This forces find to examine all entries, assuming that some might prove to be directories into which it must descend (a time-waster on Unix).
-nouser
The file’s user ID does not correspond to any user.
-ok command { }\;
Same as -exec, but prompts user to respond with y before command is executed.
-path pattern
Find files whose names match pattern. Expect full pathnames relative to the starting pathname (i.e., do not treat / or . specially).
-perm nnn
Find files whose permission flags (e.g., rwx) match octal number nnn exactly (e.g., 664 matches -rw-rw-r–). Use a minus sign before nnn to make a “wildcard” match of any unspecified octal digit (e.g., -perm -600 matches -rw-*, where can be any mode).
-print
Print the matching files and directories, using their full pathnames. Return true. This is the default behavior.
-regex pattern
Like -path, but uses grep-style regular expressions instead of the shell-like globbing used in -name and -path.
-size n[c]
Find files containing n blocks, or if c is specified, n characters long.
-type c
Find files whose type is c. c can be b (block special file), c (character special file), d (directory), p (fifo or named pipe), l (symbolic link), s (socket), or f (plain file).
-user user
Find files belonging to user (name or ID).
Examples
List all files (and subdirectories) in your home directory:
find $HOME -print
List all files named chapter1 in the /work directory:
find /work -name chapter1
List all files beginning with memo owned by ann:
find /work -name ‘memo*’ -user ann -print
Search the filesystem (begin at root) for manpage directories:
find / -type d -name ‘man*’ -print
Search the current directory, look for filenames that don’t begin with a capital letter, and send them to the printer:
find . ! -name ‘[A-Z] *’ -exec lpr { }\;
Find and compress files whose names don’t end with .gz:
gzip find . \! -name '*.gz' -print
Remove all empty files on the system (prompting first):
find / -size 0 -*ok rm { } *;
Search the system for files that were modified within the last two days (good candidates for backing up):
find / -mtime -2 -print
Recursively grep for a pattern down a directory tree:
find /book -print | xargs grep ‘[Nn] utshell’
If the files kt1 and kt2 exist in the current directory, their names can be printed with the command:
$ find . -name ‘kt[0-9] ’ ./kt1 ./kt2
Since the command prints these names with an initial ./ path, you need to specify the ./ when using the -path option:
$ find . -path ‘./kt[0-9] ’ ./kt1 ./kt2
The -regex option uses a complete pathname, like -path, but treats the following argument as a regular expression rather than a glob pattern (although in this case the result is the same):
$ find . -regex ‘./kt[0-9] ’ ./kt1 ./kt2
$ find /usr/bin -type f -perm 4755 -exec ls -l {} \;
$ find ./ -maxdepth 1 -type d ! -name “.” // -and -or ! 都可以用
$ find /app/logs -type f –name “*.log” –mtime +7 –exec rm -f {} \;
\$ find /app/logs -type f -name “*.log” -mtime +7 –delete
$ find /app/logs -type f -name “*.log” -mtime +7 |xargs rm –f;
—rename—
文件查看及处理命令(19个)
cat more cut sort 在/bin下面
tr seq less head tac tail paste uniq wc iconv file diff vimdiff tree chattr lsattr rev在/sur/bin下面
—cat—
Read(concatenate 连锁) one or more files and print them on standard output
e.g. 1: cat ch1 —Display a file
e.g. 2: cat ch1 ch2 ch3 > all —Combine files
e.g. 3: cat note5 >> notes —Append to a file
e.g. 4: cat > temp1— Create file at terminal and edit, don’t forget add a(Enter). To exit, enter (Ctrl-D).
cat > temp2 << EOF —Create file at terminal and add contents. To exit, enter EOF.
-****n : 显示行号
—more—
值得一提的是,more和less可以切换到vi状态*记住按空格键和b就好了*
+num :从numbered line往下显示
-num : set screen size
—less—
比more强大,按page up和down来翻页,/pattern 来向下寻找字符,?pattern向上寻找字符
—cut—
-c : 指定characters个数cut
# cut -c 1-10 /etc/passwd
-d:指定分隔符delimiter,默认是空格
#cut -d: -f1,6 /etc/passwd
#who | cut -d” ” -f1
#cut -c4 file | paste - file
[root@localhost-ziyi home]# who|cat >temp10
[root@localhost-ziyi home]# cat temp10
root pts/0 2017-03-21 20:07 (192.168.0.101)
root pts/1 2017-03-21 09:27 (192.168.0.101)
[root@localhost-ziyi home]# cut -c4 temp10|paste - file1
t .
t |– a
|– file1
|– test
|– test1
|– test2
-- test3
– file1
—sort—
-b 忽略每行前面开始出的空格字符。
-c 检查文件是否已经按照顺序排序。
-f 排序时,忽略大小写字母。
-M 将前面3个字母依照月份的缩写进行排序。
-n 依照数值的大小排序。
-o<输出文件> 将排序后的结果存入指定的文件。
-r 以相反的顺序来排序。
-t<分隔字符> 指定排序时所用的栏位分隔字符。
-k 选择以哪个区间进行排序。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
下面通过几个例子来讲述Sort的使用。
(1)sort将文件的每一行作为一个单位,相互比较,比较原则是从首字符向后,依次按ASCII码值进行比较,最后将他们按升序输出。
[rocrocket@rocrocket programming] catseq.txtbananaapplepearorange[rocrocket@rocrocketprogramming] sort seq.txt
apple
banana
orange
pear
用户可以保存排序后的文件内容,或把排序后的文件内容输出至打印机。下例中用户把排序后的文件内容保存到名为result的文件中。
Sortseq.txt>result(2)sort的−u选项它的作用很简单,就是在输出行中去除重复行。[rocrocket@rocrocketprogramming] cat seq.txt
banana
apple
pear
orange
pear
[rocrocket@rocrocket programming] sortseq.txtapplebananaorangepearpear[rocrocket@rocrocketprogramming] sort -u seq.txt
apple
banana
orange
pear
pear由于重复被-u选项无情的删除了。
(3)sort的-r选项
sort默认的排序方式是升序,如果想改成降序,就加个-r就搞定了。
[rocrocket@rocrocket programming] catnumber.txt13524[rocrocket@rocrocketprogramming] sort number.txt
1
2
3
4
5
[rocrocket@rocrocket programming] sort−rnumber.txt54321(5)sort的−o选项由于sort默认是把结果输出到标准输出,所以需要用重定向才能将结果写入文件,形如sortfilename>newfile。但是,如果你想把排序结果输出到原文件中,用重定向可就不行了。[rocrocket@rocrocketprogramming] sort -r number.txt > number.txt
[rocrocket@rocrocket programming] catnumber.txt[rocrocket@rocrocketprogramming]
看,竟然将number清空了
就在这个时候,-o选项出现了,它成功的解决了这个问题,让你放心的将结果写入原文件。这或许也是-o比重定向的唯一优势所在。
[rocrocket@rocrocket programming] catnumber.txt13524[rocrocket@rocrocketprogramming] sort -r number.txt -o number.txt
[rocrocket@rocrocket programming] catnumber.txt54321(6)sort的−n选项你有没有遇到过10比2小的情况。我反正遇到过。出现这种情况是由于排序程序将这些数字按字符来排序了,排序程序会先比较1和2,显然1小,所以就将10放在2前面喽。这也是sort的一贯作风。我们如果想改变这种现状,就要使用−n选项,来告诉sort,“要以数值来排序”![rocrocket@rocrocketprogramming] cat number.txt
1
10
19
11
2
5
[rocrocket@rocrocket programming] sortnumber.txt110111925[rocrocket@rocrocketprogramming] sort -n number.txt
1
2
5
10
11
19
(7) sort的-t选项和-k选项
如果有一个文件的内容是这样:
[rocrocket@rocrocket programming]$ cat facebook.txt
banana:30:5.5
apple:10:2.5
pear:90:2.3
orange:20:3.4
这个文件有三列,列与列之间用冒号隔开了,第一列表示水果类型,第二列表示水果数量,第三列表示水果价格。那么我想以水果数量来排序,也就是以第二列来排序,如何利用sort实现?幸好,sort提供了-t选项,后面可以设定间隔符。指定了间隔符之后,就可以用-k来指定列数了。
[rocrocket@rocrocket programming]$ sort -n -k 2 -t ‘:’ facebook.txt
apple:10:2.5
orange:20:3.4
banana:30:5.5
pear:90:2.3
(8) 其他的sort常用选项
-f会将小写字母都转换为大写字母来进行比较,亦即忽略大小写
-c会检查文件是否已排好序,如果乱序,则输出第一个乱序的行的相关信息,最后返回1
-C会检查文件是否已排好序,如果乱序,不输出内容,仅返回1
-M会以月份来排序,比如JAN小于FEB等等
-b会忽略每一行前面的所有空白部分,从第一个可见字符开始比较。
—tr—
Translate characters. Copy standard input to standard output.
-d :–delete
-s: squeeze-repeats
Examples
Change uppercase to lowercase in a file:
cat file | tr ‘A-Z’ ‘a-z’
Turn spaces into newlines (ASCII code 012):
tr ’ ’ ’ ’ < file
Strip blank lines from file and save in new.file (or use 011 to change successive tabs into one tab):
cat file | tr -s “” ” ” > new.file
Delete colons from file and save result in new.file:
tr -d : < file > new.file
—seq—
生成一个数字序列
语法:
seq [OPTION]… LAST
seq [OPTION]… FIRST LAST
seq [OPTION]… FIRST INCREMENT LAST
-s:指定分隔符,默认为 \n
—head—
默认打印10行
-n number:指定打印行数
—tac—
—tail—
-f: not quit
—paste—
Create a three-column file from files x, y, and z:
paste x y z > file
—uniq—
去重
-c:显示行数
—wc—
print count of one file
-l: print line count only
—iconv—
转码用的
—file—
看file类型
—diff—— vimdiff—
—chattr——lsattr—
+i -i :immutable
—rev—
reverse each line by chareters
文件打包压缩命令(3个)
gzip gunzip tar unzip
unzip在/usr/bin下,其他/bin下
—gzip—
压缩和解压zip类型
-d:解压decompress = gunzip
-v:verbose
—tar—
tar czvf file.tar filename 为压缩
tar xzvf file.tar 为解压缩
-z: 使tar也支持zip类型压缩文件
-v:verbose
-c: create a new archive, 压缩的必选项
-f:指定file
–unzip—
用 MS Windows 下的压缩软件 winzip 压缩的文档如何在 Linux 系统下展开呢?能够用 unzip 命令,该命令用于解扩展名为 .zip 的压缩文档。
系统信息显示命令(12个)
uname hostname dmesg df date 在/bin下uptime stat du top free w 在/usr/bin下
uname :默认显示kernel-linux
uname -m:print the macine hardware name
uname -r:print the kernel release
hostname:打印主机名
—dmesg—
dmesg 命令的使用范例
‘dmesg’命令设备故障的诊断是非常重要的。在‘dmesg’命令的帮助下进行硬件的连接或断开连接操作时,我们可以看到硬件的检测或者断开连接的信息。‘dmesg’命令在多数基于Linux和Unix的操作系统中都可以使用。
下面我们展示一些最负盛名的‘dmesg’命令工具以及其实际使用举例。‘dmesg’命令的使用语法如下。
dmesg [options…]
我们可以使用如‘more’。 ‘tail’, ‘less ’或者‘grep’文字处理工具来处理‘dmesg’命令的输出。由于dmesg日志的输出不适合在一页中完全显示,因此我们使用管道(pipe)将其输出送到more或者less命令单页显示。
[[email protected] ~]# dmesg | more
[[email protected] ~]# dmesg | less
输出
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
[ 0.000000] Linux version 3.11.0-13-generic (buildd@aatxe) (gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu8) ) #20-Ubuntu SMP Wed Oct 23 17:26:33 UTC 2013
(Ubuntu 3.11.0-13.20-generic 3.11.6)
[ 0.000000] KERNEL supported cpus:
[ 0.000000] Intel GenuineIntel
[ 0.000000] AMD AuthenticAMD
[ 0.000000] NSC Geode by NSC
[ 0.000000] Cyrix CyrixInstead
[ 0.000000] Centaur CentaurHauls
[ 0.000000] Transmeta GenuineTMx86
[ 0.000000] Transmeta TransmetaCPU
[ 0.000000] UMC UMC UMC UMC
[ 0.000000] e820: BIOS-provided physical RAM map:
[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
[ 0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000007dc08bff] usable
[ 0.000000] BIOS-e820: [mem 0x000000007dc08c00-0x000000007dc5cbff] ACPI NVS
[ 0.000000] BIOS-e820: [mem 0x000000007dc5cc00-0x000000007dc5ebff] ACPI data
[ 0.000000] BIOS-e820: [mem 0x000000007dc5ec00-0x000000007fffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000e0000000-0x00000000efffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000fec00000-0x00000000fed003ff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000fed20000-0x00000000fed9ffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000fee00000-0x00000000feefffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000ffb00000-0x00000000ffffffff] reserved
[ 0.000000] NX (Execute Disable) protection: active
…..
2 列出所有被检测到的硬件
要显示所有被内核检测到的硬盘设备,你可以使用‘grep’命令搜索‘sda’关键词,如下:
[[email protected] ~]# dmesg | grep sda
[ 1.280971] sd 2:0:0:0: [sda] 488281250 512-byte logical blocks: (250 GB/232 GiB)
[ 1.281014] sd 2:0:0:0: [sda] Write Protect is off
[ 1.281016] sd 2:0:0:0: [sda] Mode Sense: 00 3a 00 00
[ 1.281039] sd 2:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn’t support DPO or FUA
[ 1.359585] sda: sda1 sda2 < sda5 sda6 sda7 sda8 >
[ 1.360052] sd 2:0:0:0: [sda] Attached SCSI disk
[ 2.347887] EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: (null)
[ 22.928440] Adding 3905532k swap on /dev/sda6. Priority:-1 extents:1 across:3905532k FS
[ 23.950543] EXT4-fs (sda1): re-mounted. Opts: errors=remount-ro
[ 24.134016] EXT4-fs (sda5): mounted filesystem with ordered data mode. Opts: (null)
[ 24.330762] EXT4-fs (sda7): mounted filesystem with ordered data mode. Opts: (null)
[ 24.561015] EXT4-fs (sda8): mounted filesystem with ordered data mode. Opts: (null)
注解 ‘sda’表示第一块 SATA硬盘,‘sdb’表示第二块SATA硬盘。若想查看IDE硬盘搜索‘hda’或‘hdb’关键词。
3 只输出dmesg命令的前20行日志
在‘dmesg’命令后跟随‘head’命令来显示开始几行,‘dmesg | head -20′命令将显示开始的前20行。
[[email protected] ~]# dmesg | head -20
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
[ 0.000000] Linux version 3.11.0-13-generic (buildd@aatxe) (gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu8) ) #20-Ubuntu SMP Wed Oct 23 17:26:33 UTC 2013 (Ubuntu 3.11.0-13.20-generic 3.11.6)
[ 0.000000] KERNEL supported cpus:
[ 0.000000] Intel GenuineIntel
[ 0.000000] AMD AuthenticAMD
[ 0.000000] NSC Geode by NSC
[ 0.000000] Cyrix CyrixInstead
[ 0.000000] Centaur CentaurHauls
[ 0.000000] Transmeta GenuineTMx86
[ 0.000000] Transmeta TransmetaCPU
[ 0.000000] UMC UMC UMC UMC
[ 0.000000] e820: BIOS-provided physical RAM map:
[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
[ 0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000007dc08bff] usable
[ 0.000000] BIOS-e820: [mem 0x000000007dc08c00-0x000000007dc5cbff] ACPI NVS
[ 0.000000] BIOS-e820: [mem 0x000000007dc5cc00-0x000000007dc5ebff] ACPI data
[ 0.000000] BIOS-e820: [mem 0x000000007dc5ec00-0x000000007fffffff] reserved
4 只输出dmesg命令最后20行日志
在‘dmesg’命令后跟随‘tail’命令(‘ dmesg | tail -20’)来输出‘dmesg’命令的最后20行日志,当你插入可移动设备时它是非常有用的。
[[email protected] ~]# dmesg | tail -20
parport0: PC-style at 0x378, irq 7 [PCSPP,TRISTATE]
ppdev: user-space parallel port driver
EXT4-fs (sda1): mounted filesystem with ordered data mode
Adding 2097144k swap on /dev/sda2. Priority:-1 extents:1 across:2097144k
readahead-disable-service: delaying service auditd
ip_tables: (C) 2000-2006 Netfilter Core Team
nf_conntrack version 0.5.0 (16384 buckets, 65536 max)
NET: Registered protocol family 10
lo: Disabled Privacy Extensions
e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
Slow work thread pool: Starting up
Slow work thread pool: Ready
FS-Cache: Loaded
CacheFiles: Loaded
CacheFiles: Security denies permission to nominate security context: error -95
eth0: no IPv6 routers present
type=1305 audit(1398268784.593:18630): audit_enabled=0 old=1 auid=4294967295 ses=4294967295 res=1
readahead-collector: starting delayed service auditd
readahead-collector: sorting
readahead-collector: finished
5 搜索包含特定字符串的被检测到的硬件
由于‘dmesg’命令的输出实在太长了,在其中搜索某个特定的字符串是非常困难的。因此,有必要过滤出一些包含‘usb’ ‘dma’ ‘tty’ ‘memory’等字符串的日志行。grep 命令 的‘-i’选项表示忽略大小写。
[[email protected] log]# dmesg | grep -i usb
[[email protected] log]# dmesg | grep -i dma
[[email protected] log]# dmesg | grep -i tty
[[email protected] log]# dmesg | grep -i memory
输出
[ 0.000000] Scanning 1 areas for low memory corruption
[ 0.000000] initial memory mapped: [mem 0x00000000-0x01ffffff]
[ 0.000000] Base memory trampoline at [c009b000] 9b000 size 16384
[ 0.000000] init_memory_mapping: [mem 0x00000000-0x000fffff]
[ 0.000000] init_memory_mapping: [mem 0x37800000-0x379fffff]
[ 0.000000] init_memory_mapping: [mem 0x34000000-0x377fffff]
[ 0.000000] init_memory_mapping: [mem 0x00100000-0x33ffffff]
[ 0.000000] init_memory_mapping: [mem 0x37a00000-0x37bfdfff]
[ 0.000000] Early memory node ranges
[ 0.000000] PM: Registered nosave memory: [mem 0x0009f000-0x000effff]
[ 0.000000] PM: Registered nosave memory: [mem 0x000f0000-0x000fffff]
[ 0.000000] please try ‘cgroup_disable=memory’ option if you don’t want memory cgroups
[ 0.000000] Memory: 2003288K/2059928K available (6352K kernel code, 607K rwdata, 2640K rodata, 880K init, 908K bss, 56640K reserved, 1146920K highmem)
[ 0.000000] virtual kernel memory layout:
[ 0.004291] Initializing cgroup subsys memory
[ 0.004609] Freeing SMP alternatives memory: 28K (c1a3e000 - c1a45000)
[ 0.899622] Freeing initrd memory: 23616K (f51d0000 - f68e0000)
[ 0.899813] Scanning for low memory corruption every 60 seconds
[ 0.946323] agpgart-intel 0000:00:00.0: detected 32768K stolen memory
[ 1.360318] Freeing unused kernel memory: 880K (c1962000 - c1a3e000)
[ 1.429066] [drm] Memory usable by graphics device = 2048M
6 清空dmesg缓冲区日志
我们可以使用如下命令来清空dmesg的日志。该命令会清空dmesg环形缓冲区中的日志。但是你依然可以查看存储在‘/var/log/dmesg’文件中的日志。你连接任何的设备都会产生dmesg日志输出。
[[email protected] log]# dmesg -c
7 实时监控dmesg日志输出
在某些发行版中可以使用命令‘tail -f /var/log/dmesg’来实时监控dmesg的日志输出。
[[email protected] log]# watch “dmesg | tail -20”
—df—
Report the amount of free disk space available on all mounted iflesystems
-h: human readable
[root@localhost-ziyi ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 7.2G 2.1G 4.8G 30% /
tmpfs 497M 0 497M 0% /dev/shm
/dev/sda1 194M 28M 156M 16% /boot
-i: show inodes using conditions
—date—
[root@localhost-ziyi ~]# date +”Hello%t Date is %D %n%t Time is %T”
Hello Date is 03/22/17
Time is 13:31:10
—uptime—
uptime
13:50:40 up 1 day, 18:30, 2 users, load average: 0.00, 0.00, 0.00
—stat—
stat显示的所有信息,就差内容了,哈哈
#stat file00
File: `file00’
Size: 190 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051d Inode: 257 Links: 1
Access: (0644/-rw-r–r–) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-03-22 12:08:03.711537040 +0800
Modify: 2017-03-21 23:46:38.000000000 +0800
Change: 2017-03-22 12:08:03.708872303 +0800
—du—
Print disk usage (as the number of 1 KB blocks used by each named directory and its subdirectories; default is the current directory).
-h: human readable
-s:summarize
—top—
Provide information(frequently refreshed) about the most CPU-intensive processes currently running
—free—
Display statistics about memory usage. Default calculate memory in bytes
-k: Calculate memory in kilobytes.
-m: in megabytes.
#free
total used free shared buffers cached
Mem: 1016516 314772 701744 0 68356 82880
-/+ buffers/cache: 163536 852980
Swap: 524280 0 524280
—w—
w
w [options] [user]
Print summaries of system usage, currently logged-in users, and what those users are doing. w is essentially a combination of uptime, who, and ps -a. Display output for one user by specifying user.
[root@localhost-ziyi home]# w
14:51:16 up 1 day, 19:31, 2 users, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.0.101 09:23 41:52 0.02s 0.02s -bash
root pts/1 192.168.0.101 12:24 0.00s 0.09s 0.00s w
*搜索文件命令(4个)***
find which whereis locate**
whereis: Locate the binary, source, and manual page files for specified commands/files.
locate没有find好使,别学了
用户管理命令(10个)
useradd userdel usermod visudo groupadd 在/usr/sbin下
passwd chage id sudo在/usr/bin下
su 在 /bin下
useradd -u(指定uid) -g(指定组) -e(Account expiration date. Use the format MM/DD/YYYY) -p(passwd) username
userdel -f(force) -r(Remove the home directory of user and any files contained in it) username
usermod -u(更改用户uid) -g(更改用户组)-p(更改用户密码) username
passwd -d(delete) username
chage -d(Date of last password change. This may be expressed as a date in YYYY-MM-DD format, or as the number of days between January 1, 1970 and the last password change.)
—id—
[root@localhost-ziyi home]# id
uid=0(root) gid=0(root) groups=0(root)
[root@localhost-ziyi home]# id lzc
uid=500(lzc) gid=500(lzc) groups=500(lzc)
基本网络操作命令(10个)
***ping netstat在/bin下*
telnet ssh scp wget在/usr/bin下
route ifconfig ifup ifdown在/sbin下**
—netstat—
TCP/IP command. Show network status.
#netstat -lntup|grep 873
l:show only listening sockets;
n:nmeric,show hosts addresses as numbers, and users as numbers;
t:only tcp sockets
u:only udp sockets
p:show the process ID and name of the program owning the socket.
—telnet—
远程登录协议.因其使用的密码是明文,所有已被ssh取代
—ssh— —scp—
#ssh -p 52113 [email protected]
#推scp -rP 52113 /data/file.txt [email protected]:/tmp:r目录 大P是端口的意思, 而且必须接目录
#推scp -P52113 -r /data/ [email protected]:/tmp:没空格也行,/data/old.txt 为本地
#拉 scp -rP52113 [email protected]:/tmp /data/
ssh [options] hostname [command]
Securely log a user into a remote system and run commands on that system. The version of ssh described here is the OpenSSH client. ssh can use either Version 1 (SSH1) or Version 2 (SSH2) of the SSH protocol. SSH2 is preferable, as it provides stronger encryption methods and greater connection integrity. The hostname can be specified either as hostname or as user@hostname. If a command is specified, the user is authenticated, the command is executed, and the connection is closed. Otherwise, a terminal session is opened on the remote system. See Escape characters,” later in this section, for functions that can be supported through an escape character. The default escape character is a tilde (~). The exit status returned from ssh is the exit status from the remote system, or 255 if there was an error.
Commonly, authentication is handled with standard username/password credentials, but it can also be useful to authenticate with a key exchange. This is done by generating a key on the client with ssh-keygen and populating the known_hosts file on the remote host.
Options
-1
Try only SSH1.
-2
Try only SSH2.
-4
Use only IPv4 addresses.
-6
Use only IPv6 addresses.
-c blowfish|3des|des|ciphers
Select the cipher for encrypting the session. The default is 3des. For SSH2, a comma-separated list of ciphers can also be specified, with the ciphers listed in order of preference. des is supported only for legacy SSH1 compatibility and otherwise should not be used.
-F configfile
Specify a per-user configuration file (default is $HOME/.ssh/config).
-g
Allow remote hosts to connect to local forwarded ports.
-i idfile
Use idfile to read identity (private key) for RSA or DSA authentication. Default is HOME/.ssh/idrsaor HOME/.ssh/id_dsa for SSH2, or $HOME/.ssh/identity for SSH1. You can specify more than one -i option on the command line or in the configuration file.
-k
Disable Kerberos ticket and AFS token forwarding. Can be set on a per-host basis in the configuration file.
-p port
Specify the port on the remote host to which ssh is to connect. Can be specified on a per-host basis in the configuration file.
-q
Run quietly, suppressing warnings and error messages.
-v
Verbose mode. Useful for debugging. Specify multiple -v options to increase verbosity.
Files
ssh uses the following files in the user’s home directory:
HOME/.ssh/identity.pub, HOME/.ssh/id_dsa.pub,
$HOME/.ssh/id_rsa.pub
The public key for user authentication for SSH1 RSA, SSH2 DSA, and SSH2 RSA, respectively.
—wget—
-P: prefix, –directory-prefix=prefix . Set the directory prefix to the specified value.
—route—
route ifconfig ifup ifdown在/sbin下***
深入网络操作命令(6个)
route mail mutt nslookup dig wget
有关磁盘空间的命令(6个)
mount umount df du fsck dd
关机和查看系统信息的命令(7个)
shutdown reboot ps top kill date
安装和登录命令(3个)
shutdown halt reboot
系统管理相关命令(9个)
top free vmstat mpstat iostat sar kill chkconfig last
系统安全相关命令(13个)
passwd su sudo umask chgrp chmod chown chattr lsattr ps
whoami
查看系统用户登陆信息命令(6个)
w who users last lastlog fingers
查看硬件相关命令(6个)
ethtool mii-tool dmidecode dmesg lspci
其它(14个)
chkconfig echo yum watch alias unalias date clear history eject
time nohup nc xargs
监视物理组件的高级 Linux命令
内存:top free vmstat mpstat iostat sar
CPU:top vmstat mpstat iostat sar
I/O:vmstat mpstat iostat sar
进程:ipcs ipcrm
负载:uptime
关机:
shutdown -h now ——>立刻关机(生产常用)
shhutdown -h +1 ——>1 分钟以后关机
init 0
halt ——>立即停止系统,需要人工关闭电源
halt -p
poweroff ——>立即停止系统,并且关闭电源
重启:
reboot(生产常用)
shutdown -r now(生产常用)
shhutdown -r +1 ——>1 分钟以后重起
init 6
注销
logout
exit(生产常用)
ctl+d ——>快捷键(生产常用)
进程管理:(16个)
bg:后台运行 fg:挂起程序 jobs:显示后台程序 kill,killall,pkill:杀掉进程
crontab:设置定时 ps:查看进程 pstree:显示进程状态树
top:显示进程 nice:改变优先权 nohup:用户退出系统之后继续工作
pgrep:查找匹配条件的进程 strace:跟踪一个进程的系统调用
ltrace:跟踪进程调用库函数的情 vmstat:报告虚拟内存统计信息
危险的系统命令:
mv rm dd fdisk parted
linux 四剑客(4 个)
grep egrep sed awk**重点内容**