2.10 环境变量PATH
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
# echo "PATH=$PATH:/tmp" >> /etc/profile
Environment stuff goes in /etc/profile
System wide environment and startup programs, for login setup
# vi .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
2.11 cp命令
cp
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
-l, --link
hard link files instead of copying
# cp -l test test_hd
-R, -r, --recursive
copy directories recursively
# cp -r 1.d/ 2.d/
-s, --symbolic-link
make symbolic links instead of copying
# cp -s test test_so
-v, --verbose
explain what is being done
# cp 2.d 5.d -rv
"2.d" -> "5.d"
"2.d/1.d" -> "5.d/1.d"
2.12 mv命令
mv - Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
-i, --interactive
prompt before overwrite
# mv -i 1 2
mv:是否覆盖"2"?
2.13 文档查看cat_more_less_head_tail
cat - Concatenate FILE(s), or standard input, to standard output.
-E, --show-ends
display $ at end of each line
# cat -E /etc/passwd
root:x:0:0:root:/root:/bin/bash$
bin:x:1:1:bin:/bin:/sbin/nologin$
daemon:x:2:2:daemon:/sbin:/sbin/nologin$
-n, --number
number all output lines
# cat -n /etc/passwd
1 root:x:0:0:root:/root:/bin/bash
2 bin:x:1:1:bin:/bin:/sbin/nologin
3 daemon:x:2:2:daemon:/sbin:/sbin/nologin
tac - Write each FILE to standard output, last line first.
With no FILE, or when FILE is -, read standard input.
# tac /etc/passwd
chrony:x:998:996::/var/lib/chrony:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
more is a filter for paging through text one screenful at a time.Users should realize that less(1) provides more(1) emulation plus extensive enhancements.
SPACE Display next k lines of text. Defaults to current screen size.
RETURN Display next k lines of text. Defaults to 1. Argument becomes new default.
f Skip forward k screenfuls of text. Defaults to 1.
b or ^B Skip backwards k screenfuls of text. Defaults to 1.
´ Go to place where previous search started.
/pattern Search for kth occurrence of regular expression. Defaults to 1.
n Search for kth occurrence of last regular expression. Defaults to 1.
:f Display current file name and line number.
less - opposite of more
SPACE or ^V or f or ^F
Scroll forward N lines, default one window (see option -z below).
ENTER or RETURN or ^N or e or ^E or j or ^J
Scroll forward N lines, default 1.
b or ^B or ESC-v
Scroll backward N lines, default one window (see option -z below).
F Scroll forward, and keep trying to read when the end of file is reached.
g or < or ESC-<
Go to line N in the file, default 1 (beginning of file).
G or > or ESC->
Go to line N in the file, default the end of the file.
/pattern
Search forward in the file for the N-th line containing the pattern.
?pattern
Search backward in the file for the N-th line containing the pattern.
n Repeat previous search, for N-th line containing the last pattern.
N Repeat previous search, but in the reverse direction.
head Print the first 10 lines of each FILE to standard output.
-n, --lines=[-]K
print the first K lines instead of the first 10;
with the leading '-', print all but the last K lines of each file
# head -2 anaconda-ks.cfg
#version=DEVEL
# System authorization information
# wc -l anaconda-ks.cfg
51 anaconda-ks.cfg
# head -n -50 anaconda-ks.cfg
#version=DEVEL
-q, --quiet, --silent
never print headers giving file names
-v, --verbose
always print headers giving file names
# head -v anaconda-ks.cfg
==> anaconda-ks.cfg <==
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
tail Print the last 10 lines of each FILE to standard output.
-f, --follow[={name|descriptor}]
output appended data as the file grows;
-n, --lines=K
output the last K lines, instead of the last 10;
or use -n +K to output starting with the Kth
# tail -2 anaconda-ks.cfg
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
# wc -l anaconda-ks.cfg
51 anaconda-ks.cfg
# tail -n +51 anaconda-ks.cfg
%end
tailf、tail -f、tail -F三者区别
tail -f 等同于--follow=descriptor,根据文件描述符进行追踪,当文件改名或被删除,追踪停止
tail -F 等同于--follow=name --retry,根据文件名进行追踪,并保持重试,即该文件被删除或改名后,如果再次创建相同的文件名,会继续追踪
tailf 等同于tail -f -n 10(貌似tail -f或-F默认也是打印最后10行,然后追踪文件),与tail -f不同的是,如果文件不增长,它不会去访问磁盘文件,所以tailf特别适合那些便携机上跟踪日志文件,因为它减少了磁盘访问,可以省电
tailf命令几乎等同于tail -f,严格说来应该与tail --follow=name更相似些。当文件改名之后它也能继续跟踪,特别适合于日志文件的跟踪(follow the growth of a log file)。与tail -f不同的是,如果文件不增长,它不会去访问磁盘文件(It is similar
to tail -f but does not access the file when it is not growing. This has the side effect of not updating the access time for the file, so a filesystem flush does not occur periodically when no log activity is happening.)。tailf特别适合那些便携机上跟踪日志文件,因为它能省电,因为减少了磁盘访问嘛(tailf
is extremely useful for monitoring log files on a laptop when logging is infrequent and the user desires that the hard disk spin down to conserve battery life.)