I have a lab I am doing for a Linux Operating class. The question I am stumped on is:

For the following questions, only use the cp command to copy files.

You should currently be inside your lab07 directory. Create a subdirectory inside this directory called ones and copy (working directory is lab07) all the files in the /labs/data/filenames/ that end with a 1, 2, 3, ..., 9 into this new ones directory. I.e. copy the files file.1, file.2, etc., but not the files file.11, file.21, etc. Write the full command to copy these files into this new ones directory using only relative paths.

Now, I can do the problem using an absolute path, the command is:

cp /labs/data/filenames/file.[1-9] /lab07/ones

So from this, what would be the relative path?

I've been trying different commands for HOURS and I have no idea. I get the concept behind relative paths, it's just when I actually try to do it. I can't get it right!

We are using bash/shell, on a server. I am using Xquartz11

  • 1
    (1) Is “your lab07 directory” really /lab07?  As Mirosław says, this is unlikely.  But the only way to do this is if you know the full path to “your lab07 directory”.  Do you know it?  (2) As Mirosław says, file.11 and file.21 do end with 1.  This problem is ill-defined. Sep 21, 2015 at 3:19

1 Answer 1


The "relative path" should really be called "path relative to current directory", because that's what it is. You can think of relative path as part of path that is appended to your current directory.

If you are in /labs/data/filenames/ and you want to go to dir.1 inside, you could do cd /labs/data/filenames/dir.1. But if you paste these directories one below another, you will notice that their beginning is the same (in fact, the first is completely included in the second). So you could do cd dir.1, because current working directory (/labs/data/filenames/) is stated implicitly.

Absolute paths always start at root of directory tree, so they are easy. Relative paths can start anywhere in directory tree, so if we want to go anywhere, we need a way to go upwards. This purpose is served by special directory .. (two dots), that refers to parent.

If you are in /labs/data/filenames/, command cd .. will take you to /labs/data/; command cd ../.. would take you to /labs/. cd../../../ would take you to /.

If paths that you have posted are correct (they are valid, but you are unlikely to find lab07 directly in root of filesystem on any machine), then, starting at /lab07/, you must first ascend to the root of file system, and then descend into directory where files lies. You could do it that way:

cd ../labs/data/filenames/

For the sake of not making your homework for you, I'll leave it here. Now you need to fit above relative path into cp command. Also note that you are in /lab07/ right now, so cp destination path can be shortened. You have file selection part right, no worry here.

By the way, your instructor should know that file.11 totally ends with 1. He meant "all the files that end with one-digit number" or something.

Not the answer you're looking for? Browse other questions tagged or ask your own question.