Linux中的目录
路径:也就是linux中的目录(文件夹)有绝对路径和相对路径
根目录:/
用户主目录(homedirectory):位于/home目录下,用户登录时
工作目录(workingdirectory):当前目录
当前目录查看命令:pwd(printworkingdirectory)
当前目录:./
当前目录的上一级目录:../或..
返回到上一级目录:cd..
进入当前目录下的dirfile目录:cddirfile
cd~:进入用户主目录(账号所在目录)或者直接cd回车
cd-:(回到先前的目录)
创建、删除查看和显示目录
1.创建目录
格式:mkdir[选项]目录
功能:创建目录
常用选项说明:
-m创建目录的同时设置访问权限
-p一次性创建多级目录
【例】:在rootfile文件夹下创建test文件夹,并在test文件夹下创建file文件夹。
[root@localhost rootfile]# mkdir -p test/file
[root@localhost rootfile]# ls
test
[root@localhost rootfile]# cd test
[root@localhost test]# ls
file
[root@localhost test]#
【例】:在rootfile文件夹下创建test2文件夹,并设置test2的权限为766
[root@localhost rootfile]# mkdir -m 766 test2
[root@localhost rootfile]# ls
test test2
[root@localhost rootfile]# ls -l
total 16
drwxr-xr-x 3 root root 4096 Jul 21 21:27 test
drwxrw-rw- 2 root root 4096 Jul 21 21:30 test2
注释:rwxrw-rw-分别对应三种不同用户的权限,分别有三们二进制表示,766对应111110110
2.删除目录
格式:rmdir[选项]目录
功能:删除目录
常用选项说明:
-p递归删除目录,当子目录删除后其父目录为空时,也一同删除
【例】:删除test下的file目录(文件夹),同时test也一并删除
[root@localhost rootfile]# ls
test test2
[root@localhost rootfile]# rmdir -p test/file
[root@localhost rootfile]# ls
test2
3.查看当前目录
格式:pwd
功能:pwd(printworkingdirectory),查看当前目录.
常用选项说明:
【例】:查看当前目录
[root@localhost rootfile]# pwd
/home/rootfile
5.显示目录内容
格式:ls[选项][文件目录]
功能:显示指定目录中的文件和了目录信息,当不指定目录时,显示当前目录下的文件和子目录信息
常用选项说明:
-a显示所有文件和子目录,包括隐藏文件和主目录
-l显示文件和子目录的详细信息,包括文件类型、权限、所有者和所属群组、文件大小、最后修改时间、文件名
-d如果参数是目录,则只显示目录信息,而不显示其中所包含的文件信息
-t按时间顺序显示
-R不仅显示指定目录下的文件和子目录信息,而且还递归地显示子目录下的文件和子目录信息
创建和查看文件
创建文件
格式:touchfilename
功能:创建文件
常用选项说明:
【例】:在rootfile下创建文件file.txt和test2/file2.txt
[root@localhost rootfile]# touch file.txt
[root@localhost rootfile]# touch test2/file2.txt
[root@localhost rootfile]# ls
file.txt test2
[root@localhost rootfile]# cd tes*
[root@localhost test2]# ls
file2.txt
cat命令
格式:cat[选项]filename
功能:依次读取filename中的内容
常用选项说明:
【例】:读取rootfile下Test.java和file中的文件内容
[root@localhost rootfile]# ls
file.txt test2 Test.class Test.java
[root@localhost rootfile]# vi test2
[root@localhost rootfile]# vi file*
[root@localhost rootfile]# cat Test.java
public class Test {
public static void main(String args[]) {
System.out.println("Hello Linux!");
}
}
[root@localhost rootfile]# cat Test.java file.txt
public class Test {
public static void main(String args[]) {
System.out.println("Hello Linux!");
}
}
this is a file test.
【例】:把Test.java和file.txt文件合并到combine.txt文件中
[root@localhost rootfile]# cat Test.java file.txt > combine.txt
[root@localhost rootfile]# cat comb*
public class Test {
public static void main(String args[]) {
System.out.println("Hello Linux!");
}
}
this is a file test.
more命令
格式:more[选项]filename
功能:依次读取filename中的内容,该命令与cat的不同是可以逐屏往下翻页显示,按q退出。
常用选项说明:
-p显示下一屏之前先清屏
-s文件中连续的空白行压缩成一个空白行显示
【例】:显示file.txt的内容
[root@localhost rootfile]# more file.txt
this is a file test.
【例】:显示Test.java和file.txt的内容
[root@localhost rootfile]# more Test.java file.txt
::::::::::::::
Test.java
::::::::::::::
public class Test {
public static void main(String args[]) {
System.out.println("Hello Linux!");
}
}
::::::::::::::
file.txt
::::::::::::::
this is a file test.
less命令
格式:less[选项]filename
功能:依次读取filename中的内容,该命令与more的不同是不仅可以向下翻页,还可以向上翻页,使用上下键、Enter、空格、pageDown、pageUp可以实现前后翻页,按q退出。
常用选项说明:
【例】:显示Test.java的内容
[root@localhost rootfile]# less Test.java
public class Test {
public static void main(String args[]) {
System.out.println("Hello Linux!");
}
}
head命令
格式:head[选项]filename
功能:显示文件的头几行
常用选项说明:
-n显示文件的前n行,如果没有n值,默认为10行
【例】:显示Test.java的前3行
[root@localhost rootfile]# head -3 Test.java
public class Test {
public static void main(String args[]) {
System.out.println("Hello Linux!");
tail命令
格式:tail[选项]filename
功能:显示文件的末尾几行
常用选项说明:
+n从第n行开始显示
-n显示文件的最后n行,如果没有n值,默认为最后10行
【例】:显示Test.java的最后3行
[root@localhost rootfile]# tail -3 Test.java
System.out.println("Hello Linux!");
}
}
文件查找
格式:find[选项]filename
功能:从指定的目录开始,递归地搜索其子目录,查找满足条件的文件并对之采取相关的操作
常用选项说明:
-name‘字串’要查找的文件名,可以用通配符*、?、[]
-group‘字串’文件所属的用户组名
-user文件所属的用户名
find命令提供的查询条件可以是一个用逻辑符and、or、not组成的复合条件
-a逻辑与
-o逻辑或
-!逻辑非
【例】:查找当前目录下文件名含有Test的文件
[root@localhostrootfile]#find-name'Test*'
./Test.class
./Test.java
【例】:在根目录下查找文件名为’temp’或是匹配’install*’的所有文件
[root@localhost rootfile]# find / -name 'temp' -o -name 'instal*'
/etc/rhgb/temp
/etc/yum/pluginconf.d/installonlyn.conf
/etc/vmware-tools/installer.sh
/software/tomcat5/webapps/docs/appdev/installation.html
/software/tomcat5/temp
/sbin/install-info
/sbin/installkernel
/usr/share/aclocal-1.9/install-sh.m4
/usr/share/icons/Bluecurve/96x96/mimetypes/install.png
/usr/share/icons/Bluecurve/24x24/mimetypes/install.png
/usr/share/icons/Bluecurve/16x16/mimetypes/install.png
/usr/share/icons/Bluecurve/48x48/mimetypes/install.png
/usr/share/aclocal-1.7/install-sh.m4
/usr/share/doc/cyrus-sasl-lib-2.1.22/install.html
/usr/share/doc/sgml-common-0.6.3/html/install-catalog.html
/usr/share/doc/m2crypto-0.16/demo/Zope27/install_dir
/usr/share/doc/m2crypto-0.16/demo/ZopeX3/install_dir
/usr/share/doc/libstdc++-devel-4.1.1/html/install.html
……
【例】:在rootfile下查找不含Test*的文件
[root@localhost rootfile]# find ! -name 'Test*'
.
./.Test2.swp
./1q
./.Test.java.swp
./test2
./test2/file2.txt
./combine.txt
./file.txt
文字统计命令
格式:wc[选项]filename
功能:统计文件的字节数、字数、行数
常用选项说明:
-c统计字节数
-l统计行数
-w统计字数
【例】:统计Test.java的字节数、行数、字数
[root@localhost rootfile]# wc Test.java
5 14 105 Test.java
[root@localhost rootfile]# wc -wcl Test.java
5 14 105 Test.java
复制、移动和删除文件或文件夹
cp命令
格式:cp[选项]源目录或文件目标目录或文件
功能:将给出的文件或目录复制到另一个文件或目录中
常用选项说明:
-b若存在同名文件,则覆盖前备份原来的文件
-f强制覆盖同名文件
-r或R按递归方式,保留原目录结构复制文件
【例】:复制file.txt文件到file2,若file2已经存在,则备份file2.
[root@localhost rootfile]# ls
1q combine.txt file.txt test2 Test.class Test.java
[root@localhost rootfile]# cp -b file.txt file2
[root@localhost rootfile]# ls
1q combine.txt file2 file.txt test2 Test.class Test.java
[root@localhost rootfile]# cp -b file.txt file2
cp: overwrite `file2'? n
[root@localhost rootfile]# ls
1q combine.txt file2 file.txt test2 Test.class Test.java
[root@localhost rootfile]# cp -b file.txt file2
cp: overwrite `file2'? y
[root@localhost rootfile]# ls
1q combine.txt file2 file2~ file.txt test2 Test.class Test.java
【例】:把test2文件复制到test3文件夹
[root@localhost rootfile]# ls
1q combine.txt file2 file2~ file.txt test2 Test.class Test.java
[root@localhost rootfile]#
[root@localhost rootfile]# cp -r test2 test3
[root@localhost rootfile]# ls
1q combine.txt file2 file2~ file.txt test2 test3 Test.class Test.java
mv命令
格式:mv[选项]源目录或文件目标目录或文件
功能:移动或重命名文件或目录
常用选项说明:
-b若存在同名文件,则覆盖前备份原来的文件
-f强制覆盖同名文件
【例】:将/home/rootfile下的Test.java移动到/home/rootfile/test2下
[root@localhost rootfile]# mv Test.java test2/Test
[root@localhost rootfile]# ls -R
.:
1q combine.txt file2 file2~ file.txt test2 test3 Test.class
./test2:
file2.txt Test
./test3:
file2.txt
rm命令
格式:rm[选项]文件夹或目录
功能:删除文件夹或目录
常用选项说明:
-f强制删除文件,不出现确认提示
-r或R按递归方式删除目录,默认只删除文件
【例】:删除当前目录下的test3文件夹
[root@localhost rootfile]# ls
1q combine.txt file2 file2~ file.txt test2 test3 Test.class
[root@localhost rootfile]# ls test3
file2.txt
[root@localhost rootfile]# rm -r test3
rm: descend into directory `test3'? y
rm: remove regular empty file `test3/file2.txt'? y
rm: remove directory `test3'? y
[root@localhost rootfile]# ls
1q combine.txt file2 file2~ file.txt test2 Test.class
【例】:强制删除当前目录下的test2文件夹
[root@localhost rootfile]# ls
1q combine.txt file2 file2~ file.txt test2 Test.class
[root@localhost rootfile]# rm -rf test2
[root@localhost rootfile]# ls
1q combine.txt file2 file2~ file.txt Test.class
分享到:
相关推荐
linux学习笔记之常用命令(一)——文件处理命令命令格式与文件处理命令ls命令命令格式与文件处理命令ls命令(类似windows的查看文件属性)目录处理命令目录处理命令之mkdir命令(类似windows的创建文件夹)目录处理...
ls(LiSt):目录处理命令——显示目录文件 1)语法:ls [-ald] [文件或目录] 1、-a:显示所有文件(普通文件+隐藏文件) 1)隐藏文件一般是系统文件,建议用户不要轻易操作隐藏文件 2)Linux隐藏文件的格式为:....
后端、嵌入式软件开发、嵌入式应用等岗位常用Linux命令总结,非常详细; 在本文中详细整理了本人在嵌入式岗位(后端嵌入式软件开发、嵌入式应用开发)日常工作中常用到的linux指令。其中包括:文件相关操作、系统运行...
Linux二级文件系统设计 【开发语言及实现平台或实验环境】 C++/VC++ 【设计要求】 理解Linux的文件系统的组织;掌握常用的数据结构;系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件;...
12.命令rz、sz——文件上传下载 运行命令Sudo rz,即是接收文件,xshell就会弹出文件选择对话框,选好文件之后关闭对话框,文件就会上传到linux里的当前目录 。 运行命令Sudo sz file 就是发文件到windows上(保存的...
用户信息保存在/etc/passwd文件中,可以直接用文本编辑器来修改其中的用户参数项目。也可以用usermod命令修改已经创建的用户信息,诸如用户的UID,基本/扩展用户组,默认终端等。 语法格式:usermod [选项] 用户名 ...
4.2.9其他常用命令 5 RHEL4部署Tomcat+JDK测试环境 5.1 JDK安装配置 5.1.1 JDK软件安装 5.1.2 JDK环境变量配置 5.1.3验证JDK配置 5.2 TOMCAT安装与配置 5.2.1 Tomcat安装 5.2.2 Tomcat配置uviss 5.2.3 ...
一、Linux常用命令 1、常用工具 2、目录和文件命令 3、安装和卸载软件命令 4、压缩包管理 5、文件属性、用户用户组及查找与检索命令 6、网络管理命令 7、其他命令 二、Linux vi/vim常用命令 三、Linux下软件源更新...
1. 关於档案/目录处理的命令 ls——列目录 这是最基本的档案指令。 ls 的意义为 "list",也就是将某一个目录或是 某一个档案的内容显示出来。 格式:ls -1ACFLRabcdfgilmnopqrstux -W[sv] [files] 例: #ls (不跟...
目录处理命令 ls 命令英文原意:list 命令所在路径:/bin/ls 执行权限:所有用户 功能描述:显示目录文件 语法:ls 选项[-ald] [文件或目录] -a 显示所有文件,包括隐藏文件 -l 详细信息显示 -d 查看目录属性 ...
Linux+命令行和shell脚本 虚拟机安装成功后,选择 ubuntu 64 ovf 双击再进行安装 安装完成后 虚拟机左边会出现 ubuntu 64 选择开启虚拟机 (如果报 64 位错误 需要修改 bios) 如果你的电脑没有打开虚拟化,需要重启...
linux vi 常用命令 命令行模式(command mode)功能键 1). 插入模式 按「i」切换进入插入模式「insert mode」,按"i"进入插入模式后是从光标当前位置开始输入文件; 按「a」进入插入模式后,是从目前光标所在位置...
Linux常用命令 init运行级别 Linux系统的命令操作界面 Linux命令的操作界面 命令行界面(CLI) 图形用户界面得到普及之前使用最为广泛的用户界面。不支持鼠标,通过键盘输入指令。 命令行界面也被称为字符命令行用户...
嵌入式linux常见命令 扩展命令 *.tar.bz2 ——>参数 jxfv *.tgz ——>参数 zxfv 或 zxf *.tar.gz ——>参数zxfv 注: j 表示针对bzip2压缩文件; z 表示gzip压缩文件; x 表示释放文件; f 表示使用档案文件或设备,...
五、其他常用命令 六、一个命令网站 一、Linux命令基础 1、Linux系统的终端窗口 (1)字符终端为用户提供了一个标准的命令行接口,在字符终端窗口中,会显示一个Shell提示符,通常为$。 (如果为个人客户端,可以...
CMD命令:开始->运行->键入cmd或command(在命令行里可以看到系统版本、文件系统版本) 命令大全 1. gpedit.msc-----组策略 2. sndrec32-------录音机 3. Nslookup-------IP地址侦测器 ,是一个 监测网络中 DNS...
=,-n,-z文件测试在实现比较时,字符串最好加上单双引号,变量加双引号不存在时默认为空例如:hostname命令——查看或修改当前主机名练习:如果当前主机名为
掌握: 权限管理命令 【能力目标】 能使用命令管理账户组的权限 【思政目标】 培养学生职业素养和工匠精神。 1.修改文件或目录的权限—chmod(change mode)命令 其中: ugoa——表示权限设置所针对的用户类别,可以是...
——输出命令成功与否[ EXPR ]:[[ EXPR ]]:关键字测试类型:根据比较时的操作数的类型整型测试:整数比较字符测试:字符串比较文件测试:判断文件的存
掌握: Linux文件内容查看命令 【能力目标】 会使用命令查看文件内容 【思政目标】 培养学生职业素养和工匠精神。 1.查看文本文件的内容——cat命令 说明:文件名可使用通配符 常用选项: -n——对输出内容中的所有...