Lesson 3: Working with Files in Unix
In Lesson 3 we will look at commands for copying/moving/deleting files.
Copying files:
Firstly lets look at the file copy command which is cp.
% cp fileA fileB
is the command which makes a copy of fileA in the current working directory and calls it fileB.
We could of specified to copy the file from the current working directory to a new location with a new name.
Example
% cp /usr/FileA /usr/training/FileARenamed this copies FileA from the /usr directory to /usr/training and renames the file FileARenamed.
Moving Files:
Moving files is quite similar to the cp file command except the file is permanently moved from one location to the next.
Example: Current working directory is root.
% mv fileA /usr this moves fileA permanently to the user directory from the root directory.
Removing Files:
To remove files in Unix we use the command rm.
Example:
We have a file called resume.txt on root and we want to delete this file then we would type the following.
% rm resume.txt this permanently removes the files from root.
We could also use
% rm * - this removes all files in the current working directory be careful with wildcard removals.