Linux Survival
Search
Primary Menu
Skip to content
Home
Blog
Testimonials
Linux Links
Command List
Contact
Search for:
Linux Survival
Now we have to take a time-out to explain "pathnames". So far we have only been manipulating files that are in our current directory. But sometimes you might want to manipulate files that are not in your current directory. For example, you may be doing a lot of work in the "dogs" directory, but you remember that you wanted to rename "tigers" to "siberians". You could accomplish this by using these commands: cd .. cd cats mv tigers siberians cd .. cd dogs (continue working in "dogs") That's an awful lot of work just to perform a simple task. Fortunately, there's a way to accomplish this task with only one command instead of five. You can refer to a filename by its "pathname". This means that you specify what "path" to follow down the tree to find the file. The path to "tigers" is marked in yellow in the tree at the right. That path is represented like this: /animals/cats/tigers We built this pathname by starting at the top of the tree with the "root" ('/') and adding "animals" to it. Then we added a "slash" ('/') every time we moved down the tree another level. We can use this pathname to accomplish our task with only one command: mv /animals/cats/tigers /animals/cats/siberians Note that the command above would actually be on one line, but we don't have enough room for it on this narrow page. Typing in a full pathname can be tedious, though, especially if you are a long way down the tree. That's why it is often easier to specify a "relative pathname". It is called "relative" because it specifies a filename relative to your current location, rather than from the root directory. If you don't put a '/' at the beginning of a pathname, then Linux knows that you are using a relative pathname. For example, if you were in the "animals" directory and you wanted to rename "tigers" to "siberians", you could do so with this command: mv cats/tigers cats/siberians In this case, you specified your pathnames relative to the "animals" directory (your current directory), so you didn't need to include "animals" in them. So far we haven't shown you how to use relative pathnames from the "dogs" directory, which was our current directory in the original example. There is a way to do it by using something we learned a few pages ago. mv ../cats/tigers ../cats/siberians Recall that ".." refers to the directory above your current directory. Click the right arrow.
Page 18
Where learning Linux is easy
Module 1 Introduction
Directory Structure
List Directory
View File Contents
Create Directory
Move and Rename File
Change Directory
Get Current Location
Quiz 1
End of Module 1
Module 2 Introduction
Pathnames
Copy File
Remove File
Remove Directory
File Security
Change File Permissions
Wildcards
Groups Memberships
Quiz 2
End of Module 2
Module 3 Introduction
Home Directories
Manual Pages
User Information
Find File
Concatenate Files
Redirect Output
Print
Print Job Status
Cancel Print Job
Quiz 3
End of Module 3
Module 4 Introduction
Copy Tree
Disk Space
Remove Tree
Process Status
Pipe Output
Pattern Matching
Kill Process
Quiz 4
Conclusion