点击蓝字 | 关注我们
今日汇总部分Linux常用的命令及用法。
pwd:用于显示用户当前所在的目录。
[tatwit@localhost ~]$ pwd
/home/tatwit
[tatwit@localhost ~]$
cd:用来放在不同的目录中进行切换。
[tatwit@localhost ~]$ cd /
[tatwit@localhost /]$ cd etc
[tatwit@localhost etc]$
[tatwit@localhost etc]$ cd ~
[tatwit@localhost ~]$
ls:用来列出文件或目录信息。
[tatwit@localhost ~]$ ls
公共 模板 视频 图片 文档 下载 音乐 桌面
[tatwit@localhost ~]$
[tatwit@localhost ~]$ ls -a (参数表示显示所有文件,包含隐藏文件)
. 公共 视频 文档 音乐 .bash_history .bash_profile .cache .dbus .ICEauthority .mozilla .Xauthority
.. 模板 图片 下载 桌面 .bash_logout .bashrc .config .esd_auth .local .pki
[tatwit@localhost ~]$
ll命令(小写LL):用于显示当前目录下的文件和目录的详细信息。)
[tatwit@localhost ~]$ ll
总用量 0
drwxr-xr-x. 2 tatwit tatwit 6 11月 27 12:12 公共
drwxr-xr-x. 2 tatwit tatwit 6 11月 27 12:12 模板
drwxr-xr-x. 2 tatwit tatwit 6 11月 27 12:12 视频
drwxr-xr-x. 2 tatwit tatwit 6 11月 27 12:12 图片
drwxr-xr-x. 2 tatwit tatwit 6 11月 27 12:12 文档
drwxr-xr-x. 2 tatwit tatwit 6 11月 27 12:12 下载
drwxr-xr-x. 2 tatwit tatwit 6 11月 27 12:12 音乐
drwxr-xr-x. 2 tatwit tatwit 6 11月 27 12:12 桌面
[tatwit@localhost ~]$
mkdir:用于创建一个目录。
[tatwit@localhost ~]$ mkdir newdir
[tatwit@localhost ~]$
[tatwit@localhost ~]$ ls
公共 模板 视频 图片 文档 下载 音乐 桌面 newdir
[tatwit@localhost ~]$
rmdir:用于删除空目录
tatwit@localhost ~]$ ls
公共 模板 视频 图片 文档 下载 音乐 桌面 newdir
[tatwit@localhost ~]$
[tatwit@localhost ~]$ rmdir newdir
[tatwit@localhost ~]$ ls
公共 模板 视频 图片 文档 下载 音乐 桌面
//如果目录非空的则显示失败。
[tatwit@localhost ~]$ rmdir AAA
rmdir: 删除 'AAA' 失败: 目录非空
touch:用于新建文件。
[tatwit@localhost ~]$ touch test
[tatwit@localhost ~]$ ls
公共 模板 视频 图片 文档 下载 音乐 桌面 test
[tatwit@localhost ~]$
cp:主要用于文件或目录的复制。是非常重要也非常常用的命令。
cp命令的常用参数选项如下:
-a:尽可能将文件状态、权限等属性按原状予以复制。
-f:如果目标文件或目录存在,先删除它们再进行复制(即覆盖),并且不提示用户。
-i:如果目标文件或目录存在,提示是否覆盖已有的文件。
-R:递归复制目录,即包含目录下的各级子目录。
-d:若来源文件为链接文件的属性(linkfile),则复制链接文件属性而非文件本身。
-l:进行硬式链接(hardlink)的链接文件建立,而非复制文件本身。
-p:连同文件的属性一起复制过去,而非使用预设属性。
-r:递归持续复制,用于目录的复制行为。
-s:复制成为符号链接文件(symbolic link),即“快捷方式”文件。
-u:若 destination 比 source旧才更新destination.
[tatwit@localhost newdir]$ ls
hello.py
[tatwit@localhost newdir]$ cp hello.py abc.py
[tatwit@localhost newdir]$ ls
abc.py hello.py
[tatwit@localhost newdir]$
mv:主要用于文件或目录的移动和改名。
常用参数:
-i:如果目标文件或目录存在则提示是否覆盖目标文件或目录
-f:无论目标文件或目录是否存在直接创建文件或目录,如果存在则覆盖。不提示。
rm:主要用于文件。
常用参数:
-i:删除文件或目录时提示用户
-f:删除时不提示用户
-R:递归删除目录。
[tatwit@localhost newdir]$ mkdir testdir
[tatwit@localhost newdir]$ ls
hello.py testdir
[tatwit@localhost newdir]$ mv testdir dir123
[tatwit@localhost newdir]$ ls
dir123 hello.py
[tatwit@localhost newdir]$ rm -r dir123 hello.py
[tatwit@localhost newdir]$ ls
[tatwit@localhost newdir]$
下面是一张Linux命令的思维导图,图片来源网络供大家参考。
END
Linux
网络安全
网络设备
关注我
获取更多IT技能!