Basic Linux Commands
作为非科班出身的技术人员, 关于Linux命令也应该掌握些基本的, 所以整理一下.
Files & Navigating
ls
- list all files/folders on current directory (列出当前目录下所有文件和文件夹)
ls -l
- formatted listing in line (详细列出所有文件及信息, 每个文件或文件夹占一行)
ls -la
- formatted listing including hidden files (详细列出所有文件包括隐藏文件及信息, 每个文件或文件夹占一行)
cd dir
- change directory to dir (改变当前目录到dir文件夹)
cd ..
- change to parent directory (改变当前目录到父级目录)
cd ../dir
- change to dir in parent directory (改变当前目录到父级目录下的dir文件夹)
cd
or cd ~
- change to home directory (回到home目录下)
cd -
- change directory to last directory (返回进入之前所在的目录)
pwd
- show current directory (显示当前目录路径)
mkdir dir
- create a directory named dir (创建一个名为dir的文件夹)
rm file
- remove file (删除文件)
rm -f file
- force remove file (强制删除文件)
rm -r dir
- remove directory dir (删除文件夹)
rm -rf dir
- force remove directory dir (强制删除文件夹)
rm -r *
- delete all files and directories except hidden files under the current directory(删除当前目录下除隐含文件外的所有文件和子目录)
rm -rf /
- launch some nuclear bombs targeting your system (删除系统….千万别这么做)
cp file1 file2
- copy file1 to file2 (将file1复制为file2)
mv file1 file2
- rename file1 to file2 (将file1重命名为file2)
mv file1 dir/file2
- move file1 to dir as file2 (将file1移动到dir并重命名为file2)
touch file
- create file or update file (创建文件, 或如果文件存在的话更新文件, 如时间戳等, 但不会清空文件已存在的内容)
cat file
- output contents of file (输出文件内容)
cat > file
- write standard input into file (写入文件内容, 覆盖原有)
cat file1 file2 > file
- combine file1 and file2 into file (将文件file1和file2合并后放入文件file中)
cat >> file
- append standard input into file (在文件后追加内容)
tail -f file
- output contents of file as it grows (当文件内容增加时会打印出来, 一般用于日志监控)
Networking
ping host
- ping host (测试主机之间网络的连通性)
whois domain
- get whois for domain (查询域名信息)
dig domain
- get DNS for domain (查询DNS信息)
dig -x host
- reverse lookup host (执行逆向域名查询)
wget file
- download file (下载文件)
wget -c file
- continue stopped download (断点续传)
wget -r url
- recurively download files from url (递归下载 慎用)
curl url
- outputs the webpage from url (输出页面内容)
curl -o meh.html url
- writes the page to meh.html (web页面写入本地文件)
ssh user@host
- connect to host as user (ssh连接user到host)
ssh -p port user@host
- connect using port (ssh指定端口连接)
Processes
ps
- display currently active processes (报告当前系统的进程状态)
ps aux
- detailed outputs (显示所有进程详细信息)
kill pid
- kill process with process id (pid) (以pid杀掉进程)
killall proc
- kill all processes named proc (杀掉所有名为proc的进程)
System Info
date
- show current date/time (显示当前系统日期时间)
uptime
- show uptime (显示uptime)
whoami
- who you are logged in as (显示当前登录用户)
w
- display who is online (显示当前在线用户)
du
- show directory space usage (显示当前目录下空间使用)
df
- show disk usage (显示磁盘空间使用)
uname -a
- show kernal config (显示内核信息)
top
- show processes in a dynamic real-time view (实时显示系统各进程资源使用情况)
Compressing
tar cf file.tar file1 file2
- tar files into file.tar (合并file1, file2为file.tar)
tar xf file.tar
- untar into current directory (拆解file.tar到当前目录)
tar tf file.tar
- show contents of archive (显示tar文件内容)
options:
c
- create archive (建立新的备份文件)t
- table of contents (列出备份文件的内容)x
- extract (从备份文件中还原文件)z
- use zip/gzip (使用gzip指令备份)f
- specify filename (指定备份文件名)j
- bzip2 compression (支持bzip2解压文件)w
- ask for comfirmation (确认压缩文件的正确性)k
- do not overwrite (保留原有文件不覆盖)v
- verbose (显示操作过程)
Permission
chmod 777 file
- change permissions of file (修改文件权限)
4
- read (r)2
- write (w)1
- execute (x)
order owner/group/world
chmod 777
- rwx for everyone (所有人可读可写可执行)
chmod 755
- rw for owner, rx for group and world (文件所有者可读可写可执行, 其他人可读可执行)