Linux基础命令——cd
目录:
当前目录或工作目录
主目录或家目录:HOME
root: /root
普通用户:/home/USERNAME
例如:/home/tom
~ 用户的家目录
cd命令:chang directory
切换工作目录
回到当前用户的家目录
~]# cd
或
~]# cd ~
切换至指定用户的主目录
~]# cd ~USERNAME
在上一次目录和当前目录之间来回切换
~]# cd -
当前目录用.表示
~]# cd .
当前目录的父目录用..表示
~]# cd ..
相关的环境变量:
PWD 保存了当前目录;
OLDPWD 上一次所在的目录;
pwd命令:显示当前目录
Print the name of the current working directory
~]# pwd/root
ls命令:显示指定路径下的文件列表
list directory contents
ls [OPTION]... [DIR]...-a,--all 显示所有文件,包括隐藏文件;-l 长格式-h,--human-readable 单位换算-d 显示目录自身的相关属性,通常与-l一起使用;-r,--reverse 逆序显示-R,--recursive 递归显示~]# ls -ld /rootdr-xr-x---. 26 root root 4096 12月 7 12:10 /root
stat命令:获取指定文件的元数据
display file or file system status
stat [OPTION]... FILE...
~]# stat /etc/passwd
cat,tac命令:查看文件内容命令
concatenate files and print on the standard output
cat [OPTION]... [FILE]...-E 显示行结束符$-n 对显示出的每一行进行编号~]# cat -n /etc/issue 1CentOS release 6.5 (Final) 2Kernel on an m 3~]# cat -E /etc/issueCentOS release 6.5 (Final)$Kernel on an m$$~]# tac /etc/issueKernel on an mCentOS release 6.5 (Final)
file命令:查看文件的类型命令
determine file type
file /PATH/TO/SOMEFILE
~]# file /etc/issue/etc/issue: ASCII text
echo命令:回显命令
display a line of text
-n 禁止自动添加换行符号;-e 允许使用转义符; 换行 制表符echo "$VAR_NAME" 变量会替换,双引号为弱引用echo ‘$VAR_NAME' 变量不会替换,单引号为强引用~]# echo "$PWD"/root~]# echo '$PWD'$PWD
which命令:显示命令对应的程序文件路径
shows the full path of (shell) commands.
which [options] [--] programname [...]~]# which cat /bin/cat
whatis命令:使用mkwhatis命令将当前系统上所有的帮助手册及与之对应的关键字创建为一个数据库
search the whatis database for complete words.
whatis keyword ...~]# whatis manman (1) - format and display the on-line manual pagesman (1p) - display system documentationman (7) - macros to format man pagesman.config [man] (5) - configuration data for manman [manpath] (1) - format and display the on-line manual pagesman-pages (7) - conventions for writing Linux man page