如何在Linux中使用相对路径 (relative path linux)

在Linux操作系统中,文件路径是指用来定位一个文件或目录的字符串。对于经常在Linux中工作的人来说,熟练掌握文件路径的使用是非常重要的。

文件路径可以分为绝对路径和相对路径两种。相对路径是相对于当前工作目录而言的路径,而绝对路径则是从根目录开始的路径。相对路径一般都比较简短,对于有些操作,使用相对路径比绝对路径更加方便。

下面我们来详细讲解。

1. 确定当前工作目录

在使用相对路径时,我们需要先确定当前工作目录。可以通过使用pwd命令来确定当前目录的路径。

$ pwd

/home/user/documents

在这个例子中,当前工作目录是/home/user/documents。

2. 使用相对路径访问文件

使用相对路径来访问文件非常简单。如果我们要在当前工作目录下访问相对路径为subdir/file的文件,只需要在命令行中输入文件名即可。

$ cat subdir/file

在这个例子中,cat命令用来打印出subdir目录下的file文件的内容。

3. 使用相对路径访问文件夹

使用相对路径来访问文件夹同样非常简单。如果我们要在当前工作目录下访问相对路径为subdir的文件夹,只需要在命令行中输入文件夹名即可。

$ cd subdir

在这个例子中,cd命令用来进入subdir目录。

4. 相对路径表示父目录和当前目录

有时候,我们需要使用相对路径来表示父目录和当前目录。在Linux中,表示当前目录的符号为.(一个点),表示父目录的符号为..(两个点)。

例如,如果我们要在当前工作目录下打印出父目录中的file文件的内容,只需要输入下面的命令。

$ cat ../file

在这个例子中,../表示父目录下的文件。

5. 相对路径中的~表示根目录

在Linux中,~符号表示用户的根目录。如果我们要在任何目录下都能访问用户根目录下的file文件,只需要输入下面的命令。

$ cat ~/file

在这个例子中,~表示用户根目录。

相对路径在Linux中的使用非常方便,可以简化文件路径的编写,同时也有利于提高工作效率。熟练使用相对路径可以让我们更加深入地理解Linux的文件系统,更好地掌握它的使用方法。

相关问题拓展阅读:

如何设置linux环境变量?

1、控制台中设置,不赞成这种型差方式,因为他只对当前的shell 起作用,换一个shell设置就无效了:

直接控制台中输入 : $PATH=”$PATH”:/NEW_PATH (关闭shell Path会还原为原来的path)

对所有的用户的都起作用的环境变量

2、修改 /etc/profile 文件,如果你的计算机仅仅作为开发使用时推存使用这种方法,因为所有用户的shell都有权使用这个环境变量,可能会给系统带来安全性问题。这里是针对所有的用户的,所有的shell

vi /etc/profile

在/etc/profile的最下面添加: export PATH=”$PATH:/NEW_PATH”

针对当前伏培特定的用户起作用的环境变量

3、修改bashrc文件,这种方法更为缺租唯安全,它可以把使用这些环境变量的权限控制到用户级别,这里是针对某一特定的用户,如果你需要给某个用户权限使用这些环境变量,你只需要修改其个人用户主目录下的 .bashrc文件就可以了。

vi ~/.bashrc

在下面添加:

Export PATH=”$PATH:/NEW_PATH”

可以多看看《linux就该这么学》希望可以帮到你

黑马程序员老师告诉你:

暂时的:export MYNAME=”new name”

echo $MYNAME

new name

永久的:通过改变/etc/慎腔profile实现

EG: export CLASSPATH=./java_HOME/lib;$JAVA_HOME/jre/宽顷衫lib

更改文件后执行 source /乎返etc/profile。

虚拟机怎么安装vmware tools

现在的人们都会在电脑上装一个虚拟机,来安装别的操作系统,比如像“Red

Hat

Linux”不过在虚拟机运行的时候,在跟虚拟机外面的操作系统切换时很痛苦啊!每次都得按“Ctrl”+“Alt”才能完成两者之间的切换!忒痛苦,有木有啊!各位童鞋。不过可以安装一个虚拟机的插件就可以再两者之间完成鼠标平滑的切换,超爽。不过呢,有很多人在VMware

Workstation虚拟机安装VMware

Tools时总是安装不上,不知道是什么原因!我之前也是安装了无数道,可是还是一纤册样!失败。后来我去问了我大学了老师,知道原来我的老师也是经过了无数道的失败才找到原因的!所以我把失败的原因告诉大家,免得大家在苦恼了!

装不上VMware

Tools的原因是VMware

Workstation虚拟机版本的问题!只有“VMware

Workstation虚拟机7.0”版本才能装上去。之前我用的是“VMware

Workstation虚拟机5.0”版本,所以一直都没装上去。后来,我用了“VMware

Workstation虚拟租竖粗机1.0”在创建虚拟机的时候我把版本改成“VMware

Workstation虚拟机6.5-7.x”就可以了!

步骤如下:

进入虚拟机,待虚拟机完全启动好后!点击虚拟机的菜单“虚拟机(M)”选择“设置”

然后在设置里面的“硬件”下面选择“CD/DVD(IDE)”!

然后在选项“使用ISO映像文件(M)”的“浏览(B)”选择“VMware

Tools的映像文件”!

完成上的步骤后,点击虚拟机的菜单“虚拟机(M)”选择“安装VMware

Tools(T)”

然后点击”Computer“在弹出的窗口点击“CD-EM/DVD+RW

Drive:VMware

Tools”

然后在弹出的窗口点击红色方弊镇形。

然后在弹出的窗口点击红色方形,这是解压到哪里的路径。

然后在弹出的窗口点击红色方形,这是解压到哪里的路径。

选择上面红色方形里面的“Desktop”点击右下角红色方形“Extract”,解压到桌面上。

这时回到桌面上去,会看到解压到桌面上的文件“VMware-Tools-distrib”然后弹出窗口“vmware-tools-distrib”点击里面的“vmware-intsall。pl”运行文件!

点击后弹出运行”窗口“点击红色方形“Run

in

Terminal”

然后弹出命令窗口,选择“y”键,之后就一直按Enter回车键!

这时会出现选择分辨率的命令,根据自己的电脑分辨率就行了!

等命令窗口全部运行完后!重启系统就“OK”了

Linux VMware Tools安装步骤简易版

Linux VMware Tools安装估计有点困难,我也在网上看了好多版本的Linux安装VMware Tools,方法都一样。但是自己在安装过程中,还是遇到了点问题。但是最终还是搞定。我运行的是VMware workstation 8.0.4 , OS: CentOS 6.0

1. 在CD-ROM虚拟光驱中选择使用ISO镜像,找到VMWARE TOOLS 安装文件,如C:\program\VMware\VMware Workstation\Programs\linux.iso

当然这个ISO是你安装VMware workstation 的目录下的Linux.iso,不是你的Linux OS 镜像文件。VMware Tools一般都在这个文件里。

2. 以管理员身份进入Linux,root账号

3. 退出到windows,在虚拟机菜单栏中点击 虚拟机盯樱-> 安装 VMWARE TOOLS 子菜单,会弹出对话框,点击”确认” 安装

4. 挂载光驱:Mount -t iso9660 /dev/cdrom /mnt

加载CDROM设备,这是如果进入/mnt 目录下,你会发现一个文件:

VMwareTools-8.8..tar.gz

这个就死VMware Tools的则察Linux软件包,也是我们刚才使用的WinISO打开的Liunx.ISO

有的虚拟机上估计执行mount /dev/cdrom /mnt/cdrom

如果提示如下错误,挂载点不存在。,#mount /dev/cdrom /mnt/cdrom

mount: mount point /mnt/cdrom dose not exist

请直接执行此命令:

mount /dev/cdrom /opt

cd /opt

或者应该可以使用自动挂载,直接进入

cd /misc/cd

5. copy 此文件到临时文件夹

cp /mnt/mVMwareTools-8.8..tar.gz /tmp

6. 卸载CDROM,执行 umount /dev/cdrom

7. 进入tmp文件目录并解压此文件包

cd /tmp

tar zxf vmware-linux-tools.tar.gz

解压默认到vmware-tools-distrib目录下:此时你可以使用ls -ll 查看文件夹下的文件

8. 进入vmware-tools-distrib,安装vmware tools.

./vmware-install.pl 执行安装,

安装过程中他会一步一步的有问题回应,此过程中,你遇到后面显示,,的直接输入yes,然后回车。其他的问题不管里面是什么,直接回车就好了,不要输入。

9. 大约5分钟左右安装完成。 执行init 6重启ok。

Linux VMware Tools安装步骤图文版,大家可以参考下

展台搭建 机器视觉系统 windows7旗舰版凯盯丛 电脑重装系统 arm9开发板 科比球鞋 机器视觉

虚拟机 制作网页 网页制作模板 展台搭建 科比球鞋 电脑系统重装 windows7旗舰版

虚拟机 网站开发 安德玛篮球鞋 展台搭建 网站设计 网站设计公司 html5网页模板

网站开发 安卓软件开发 电脑装win7系统 ios编程入门 苹果刷机 外置显卡 现在做什么赚钱

html5网站 u盘安装系统 html5模板 单片机 电脑重装系统 女装免费代理 展台搭建

近视眼恢复 恢复删除文件 二合一平板电脑 u盘安装系统 平板电脑排行榜 jordan 呼叫系统

操作过程如下:

# cd /

# ls

bin dev home lost+found misc net proc in srv tftpboot usr

boot etc lib mediamnt opt root selinux sys tmpvar

# cd /media

# ls

VMware Tools

# cd VMware\ Tools/

# ls

manifest.txt VMwareTools-8.1..tar.gz

# cp VMwareTools-8.1..tar.gz /tmp

# cd /tmp

# ls

gconfd-root scim-helper-manager-socket-root

keyring-lbbFvv scim-panel-socket:0-root

mapping-root scim-socket-frontend-root

orbit-root ssh-FmnVlj2751

scim-bridge-0.3.0.lockfile-0@localhost:0.0 virtual-root.ZxmHUV

scim-bridge-0.3.0.socket-0@localhost:0.0 VMwareTools-8.1..tar.gz

# tar -zxf VMwareTools-8.1..tar.gz

# ls

gconfd-root scim-panel-socket:0-root

keyring-lbbFvv scim-socket-frontend-root

mapping-root ssh-FmnVlj2751

orbit-root virtual-root.ZxmHUV

scim-bridge-0.3.0.lockfile-0@localhost:0.0 VMwareTools-8.1..tar.gz

scim-bridge-0.3.0.socket-0@localhost:0.0 vmware-tools-distrib

scim-helper-manager-socket-root

# cd vmware-tools-distrib/

# ls

bin doc etc FILES INSTALL installer lib vmware-install.pl

# ./vmware-install.pl

Creating a new VMware Tools installer database using the tar4 format.

Installing VMware Tools.

In which directory do you want to install the binary files?

yes

The path “yes” is a relative path. Please enter an absolute path.

In which directory do you want to install the binary files?

What is the directory that contains the init directories (rc0.d/ to rc6.d/)?

What is the directory that contains the init scripts?

In which directory do you want to install the daemon files?

In which directory do you want to install the library files?

The path “/usr/lib/vmware-tools” does not exist currently. This program is

going to create it, including needed parent directories. Is this what you want?

yes

In which directory do you want to install the documentation files?

The path “yes” is a relative path. Please enter an absolute path.

In which directory do you want to install the documentation files?

The path “/usr/share/doc/vmware-tools” does not exist currently. This program

is going to create it, including needed parent directories. Is this what you

want?

The installation of VMware Tools 8.1.3 buildfor Linux completed

successfully. You can decide to remove this software from your system at any

time by invoking the following command: “/usr/bin/vmware-uninstall-tools.pl”.

Before running VMware Tools for the first time, you need to configure it by

invoking the following command: “/usr/bin/vmware-config-tools.pl”. Do you want

this program to invoke the command for you now?

Stopping VMware Tools services in the virtual machine:

Guest operating system daemon:

Virtual Printing daemon:

Unmounting HGFS shares:

Guest filesystem driver:

Found a compatible pre-built module for vmmemctl. Installing it…

Found a compatible pre-built module for vmhgfs. Installing it…

Found a compatible pre-built module for vmxnet. Installing it…

Found a compatible pre-built module for vmblock. Installing it…

The VMware FileSystem Sync Driver (vmsync) is a new feature that

creates backups of virtual machines. Please refer to the VMware Knowledge Base

for more details on this capability. Do you wish to enable this feature?

Found a compatible pre-built module for vmci. Installing it…

Found a compatible pre-built module for vsock. Installing it…

Found a compatible pre-built module for vmxnet3. Installing it…

Found a compatible pre-built module for pvscsi. Installing it…

Detected X.org version 7.1.

Host resolution detected as “1440 x 900”.

Please choose one of the following display sizes that X will start with:

“320×200”

“320×240”

“400×300”

“512×384”

“640×400”

“640×480”

“720×480”

“800×480”

“854×480”

“720×576”

“800×600”

“1024×768”

“1280×720”

“1280×768”

“1152×864”

“1280×800”

Warning:Multiple symbols for level 1/group 1 on key

> Using XF86Sleep, ignoring XF86Standby

> Warning:Symbol map for key redefined

> Using last definition for conflicting fields

Errors from xkbcomp are not fatal to the X server

X is running fine with the new config file.

FreeFontPath: FPE “unix/:7100” refcount is 2, should be 1; fixing.

Creating a new initrd boot image for the kernel.

Starting VMware Tools services in the virtual machine:

Switching to guest configuration:

Paravirtual SCSI module:

Guest filesystem driver:

Mounting HGFS shares:

Guest memory manager:

Guest vmxnet fast network device:

VM communication interface:

VM communication interface socket family:

Blocking file system:

File system sync driver:

Guest operating system daemon:

Virtual Printing daemon:

The configuration of VMware Tools 8.1.3 buildfor Linux for this running

kernel completed successfully.

You must restart your X session before any mouse or graphics changes take

effect.

You can now run VMware Tools by invoking the following command:

“/usr/bin/vmware-toolbox” during an X server session.

To enable advanced X features (e.g., guest resolution fit, drag and drop, and

file and text copy/paste), you will need to do one (or more) of the following:

1. Manually start /usr/bin/vmware-user

2. Log out and log back into your desktop session; and,

3. Restart your X session.

To use the vmxnet driver, restart networking using the following commands:

/etc/init.d/network stop

rmmod pcnet32

rmmod vmxnet

modprobe vmxnet

/etc/init.d/network start

Enjoy,

–the VMware team

Found VMware Tools CDROM mounted at /media/VMware Tools. Ejecting device

/dev/hdc …

#

网络安全工程师演示:黑客如何安装VMware-tools虚拟雹伏族源弊机增强工具厅衫?

relative path linux的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于relative path linux,如何在Linux中使用相对路径,如何设置linux环境变量?,虚拟机怎么安装vmware tools的信息别忘了在本站进行查找喔。


数据运维技术 » 如何在Linux中使用相对路径 (relative path linux)