本文主要讨论的是Ubuntu上常用的命令行。
熟记这些命令,让你的手在键盘上飞起来吧~

常用的命令清单
Files Commands
-
pwd Print Working Directory
pwd显示当前工作目录的路径。 -
ls List
ls -l以详细列表的形式显示当前工作目录下的所有普通文件。
ls -a显示当前工作目录下的所有文件,包括隐藏文件。
ls -la以详细列表的形式显示当前工作目录下的所有文件,包括隐藏文件。 -
cd Change Directory
cd <directory>更改当前工作目录。 -
mkdir Make Directory
mkdir <dir>创建一个新目录。 -
rm Remove
rm <file>删除指定文件file。
rm -r <dir>递归删除指定目录dir下的所有子目录和文件。
rm -f <file>强制删除指定文件file,忽略不存在的文件,不给出提示。 -
rmdir Remove Directory
rmdir <dir>删除指定目录。 -
cp Copy
cp <source-file> <destination-file>将source文件复制为destination文件。
cp -r <source-folder> <destination-folder>将source文件夹复制到destination文件夹处。 -
mv MoVe
mv <source> <destination>将指定source文件或文件夹移至destination处。也可用于将source文件(夹)重命名为destination。 -
cat concatenate and print files
cat <file>在标准输出(屏幕)上查看指定文件。 -
head print HEAD (from beginning)
head -n N <file>在标准输出(屏幕)上查看指定文件的开头N行内容。默认为10行。 -
tail print TAIL (from last)
tail -n N <file>在标准输出(屏幕)上查看指定文件的最后N行内容。默认为10行。 -
grep Search for a pattern
grep "<string>" <file>在指定文件file中搜寻指定字符串string。
grep -i "<string>" <file>在指定文件file中搜寻指定字符串string(忽略大小写)。
grep -r "<string>" <dir>在指定目录下的所有文件中递归搜寻指定的字符串。 -
less print LESS
less <file>按页或按窗口打印文件内容。可使用Ctrl+F向前翻页,Ctrl+B向后翻页。 -
tar
tar -cvf <archive-file.tar> <files>将指定的files添加进.tar压缩包。
tar -tvf <archive-file.tar>查看指定压缩包内的内容。
tar -xvf <archive-file.tar>提取指定压缩文件的内容到当前工作目录。 -
zip
gzip <file>将指定文件压缩至file.gz压缩包中。
gzip -d <file>将file.gz压缩包内的文件解压缩至当前工作目录。
unzip <archive-file.zip>对指定的gzip文档进行解压。
unzip -l <archive-file.zip>查看指定gzip压缩文件里的内容。 -
find
find <dir> -name <file>在指定目录dir下搜寻与条件匹配的文件。
find <dir> -iname <file>在指定目录dir下搜寻与条件匹配的文件(忽略大小写)。 -
tree
tree <dir>以树形结构显示指定目录下的文件结构。
由于ubuntu系统中默认是没有tree的,所以需要额外安装tree命令。
sudo apt-get install tree

tree命令的安装

树形文件结构的示例
Account Commands
-
su Switch User
su <user>切换当前用户。Tip: root用户可随意切换到其它用户。 -
sudo **
sudo允许普通用户执行一些或者全部的root命令 -
w who is online
w详细的显示说所有在线用户的信息,包括总共用户数,各个用户的登录时间与在线时长等信息。 -
who who is logged in
who显示所有在线用户。 -
whoami Who am I
whoami查询当前登录用户的用户名称。 -
passwd Password
passwd更改当前登录用户的UNIX登录密码。
Package Commands
-
apt-get
apt-get install <package>安装一个新软件包。
apt-get remove <package>卸载一个已安装的软件包(保留配置文档)。
apt-get remove --purge <package>卸载一个已安装的软件包(删除配置文档)。
apt-get autoremove <package>删除包及其依赖的软件包。
apt-get autoremove --purge <package>删除包及其依赖的软件包,及其依赖的软件包的配置文件。
Process Commands
-
ps ProcesseS
ps查询当前系统中运行进程的信息。 -
kill
kill <pid>终止指定的进程pid。 -
shutdown
shutdown关闭Ubuntu系统。
shutdown -r重启Ubuntu系统。
System Info Commands
-
help
<command> --help查询指定命令的具体使用方法。 -
whatis What is this command
whatis <command>简要查询指定命令的功能。 -
top
top查询当前CPU的使用情况。
top -u <user>查询指定用户user在当前CPU中的使用情况。 -
df Disk space Free
df查看系统中磁盘的使用情况,包括硬盘已用和可用的存储空间等其它存储信息。
df -h查看系统中磁盘的使用情况,并将信息以M\G等用户常用的表示方法进行显示。 -
uname
uname -a查询关于系统的所有信息。
Network Commands
-
ping
ping <address>检测网络连接与服务器状态。 -
telnet
telnet <host> [port]远程登录host主机,可通知指定的端口port登录。 -
curl
curl <URL>将指定url返回的数据打印在默认终端(屏幕)上。 -
netstat
netstat [options]显示与IP、TCP、UDP和ICMP协议相关的统计数据,检验本机各端口的网络连接情况。netstat命令中可用的options。 - 修改hosts
vi /etc/hosts根据你的需要修改Host文件吧。
Reference
29个你必须知道的Linux命令 http://www.imooc.com/article/1285
每个程序员都应该知道的8个Linux命令 http://www.imooc.com/article/1276
常用命令行cheet sheet
Commands https://github.com/iamcoach/console/blob/master/COMMANDS.md
