The Command Line 命令行
在Linux或者OS X中,输入命令行的界面叫做terminal。
-
ls显示当前目录下的文件和目录
ls -a显示所有文件,包括以"."开头的文件,即隐藏文件
ls -l列出文件详细信息,包括权限,父级目录数量,所有者名称,大小,上次修改文件日期和事件,名称
ls -t将文件依建立时间之先后次序列出
ls -alt参数组合使用
在terminal中,显示的$叫做shell提示符。
pwd显示当前目录路径cd directory"change directory",打开指定目录directorycd ..返回上一级目录mkdir media创建一个新目录touch keyboard.txt创建一个keyboard.txt文件cp frida.txt lincoln.txt复制文件,将frida.txt的内容复制到lincoln.txt中
cp biopic/ray.txt biopic/notorious.txt historical/复制ray.txt和notorious.txt文件到historical目录下
cp * satire/复制当前目录下所有文件到satire目录中
cp m*.txt scifi/复制当前目录下以"m"字母开头,".txt"结尾的文件到scifi目录下mv superman.txt superhero/移动superman.txt文件到superhero目录
mv wonderwoman.txt batman.txt superhero/移动wonderwoman.txt和batman.txt文件到superhero目录
mv batman.txt spiderman.txt将batman.txt文件重命名为spiderman.txtrm waterboy.txt删除当前目录的waterboy.txt文件
rm -r slapstick删除当前目录的slapstick文件夹
【命令可直接利用TAB键进行补全】
echo "Hello"在terminal中显示Hello信息
echo "Hello" > hello.txt向hello.txt文件写入信息cat hello.txt查看hello.txt文件信息
cat oceans.txt > continents.txt将oceans.txt的内容覆盖到continents.txt中
cat glaciers.txt >> rivers.txt在rivers.txt文件末尾添加glaciers.txt文件内容
cat < lakes.txt将lakes.txt文件内容标准输出到terminal
cat > lakes.txt在terminal标准输入内容到lakes.txt【注意:不是追加写入】cat volcanoes.txt | wc | cat > islands.txt计算volcanoes.txt文件的wc信息后,输出到island.txt文件中
"|"称作管道,即将左侧做为输入,右侧做为输出
wc命令计算文件的行数,单次数量,字符数量sort lakes.txt排序lakes.txt的内容,按字母顺序,数字顺序等等uniq deserts.txt去重deserts.txt文件内容grep Mount mountains.txt查找mountains.txt文件中包含"Mount"字符串的内容
grep -i Mount mountains.txt查找mountains.txt文件中包含"Mount"或"mount"字符串的内容
grep -R Arctic /home/ccuser/workspace/geography查找/home/ccuser/workspace/geography路径下包含字符串Arctic的文件内容
grep -Rl Arctic /home/ccuser/workspace/geography查找/home/ccuser/workspace/geography路径下包含字符串Arctic的文件sed 's/snow/rain/' forests.txt替换forests.txt文件中的snow为rain,"s"即替换操作
sed 's/snow/rain/g' forests.txt"g"表达式即全局操作nano hello.txt打开nano文本编辑器
CTRL+O保存文件
CTRL+X退出文件
CTRL+G打开帮助菜单clear清除terminal窗口source ~/.bash_profile运行.bash_profile文件alias用于设置指令的别名-
export用于设置或显示环境变量nano ~/.bash_profilealias hy="history" alias ll="ls -la" export USER="Jane Doe" export PS1=">>"CTRL+O--> Enter -->CTRL+Xsource ~/.bash_profile hy ll echo $USER【返回系统变量时候,使用$;PS1是定义命令行样式的变量,上述操作将$变成>>】
env显示系统配置
env | grep PATH显示PATH系统配置