Copy and move
Let's create two new directories inside our work directory.
pi@raspberrypi:~/work $ mkdir dir1
pi@raspberrypi:~/work $ mkdir dir2
pi@raspberrypi:~/work $ ls -l
total 12
drwxr-xr-x 2 pi pi 4096 Sep 1 01:02 dir1
drwxr-xr-x 2 pi pi 4096 Sep 1 01:02 dir2
-rw-r--r-- 1 pi pi 16 Sep 1 00:47 testfile
pi@raspberrypi:~/work $
We can copy testfile into dir1 with cp.
pi@raspberrypi:~/work $ cp testfile dir1/testfile1
pi@raspberrypi:~/work $ ls dir1
testfile
pi@raspberrypi:~/work $
cp command takes two arguments: the path of the source file we want to copy and the path of the destination file.
All the following commands will have the same effect: copy file /home/pi/work/testfile
as file /home/pi/work/dir1/testfile1
.
As you can see, paths can be expressed in absolute (full path starting from root directory) or relative terms.
pi@raspberrypi:~/work $ cp /home/pi/work/testfile dir1/testfile1
pi@raspberrypi:~/work $ cp ./testfile /home/pi/work/dir1/testfile1
pi@raspberrypi:~/work $ cp ./testfile ./dir1/testfile1
pi@raspberrypi:~/work $ cp testfile dir1/testfile1
pi@raspberrypi:~/work $
We can move files from one directory to another with mv.
We will now move testfile to dir2.
pi@raspberrypi:~/work $ mv testfile dir2
pi@raspberrypi:~/work $ ls dir2
testfile
pi@raspberrypi:~/work $ pwd
/home/pi/work
pi@raspberrypi:~/work $ ls
dir1 dir2
pi@raspberrypi:~/work $
If you type an incomplete file name (say "dir" ) and hit TAB
key, the shell will complete the name for you. (in the
case below, you can see that there are two directories matching your selection: dir1 and dir2)
pi@raspberrypi:~/work $ ls dir
dir1/ dir2/
pi@raspberrypi:~/work $ ls dir
We can search for files with find. The arguments after "find" mean: search starting from this directory (.) for all files called "testfile" and print their names on the screen.
pi@raspberrypi:~ $ pwd
/home/pi
pi@raspberrypi:~ $ find . -name testfile -print
./work/dir2/testfile
./work/dir1/testfile
pi@raspberrypi:~ $