Hello and welcome to this introductory video on Oracle Linux.
This short video is a beginners' level video covering topics on files and directories on
Oracle Linux.
After watching this video, you will learn about:
Your location and home directory
You'll learn to View content use the file command
You'll learn how to copy and remove files and directories
You'll also learn to create and remove files and directories
And finally you'll learn how to quickly search using the find command for files and directories.
Let's immediately jump into a command line terminal to learn about files and directories.
In Oracle Linux, everything is a file, even directories are files.
When working within the directory hierarchy, you always have a current working directory.
When you initially log into the system, the current directory is set to your home directory.
The pwd command is a command to find out your present or current working directory.
As you can see, we are in bob's home directory at the moment.
The ls command lists the contents of a directory.
To view the contents of a specific directory use the full pathname to that directory.
A common method for listing all files and directories in a directory along with permissions,
ownership, size, and datestamps is the ls -l command.
Sometimes you may wish to view the directories within the present directory.
The ls -F command lists files and directories removing extraneous information provided by
the -l option, as shown:
Another helpful command is the file command which helps determine certain file types.
The output from the file command is either text, data, or executable or binary.
In this case, the file myfile is an ASCII text file.
You can change your current working directory at any time by using the changes directory
or cd command:
First, let's list the files and directories again for Bob using the ls -F command again.
And then reverify the present working directory with the pwd command.
Let's change directory by using the cd command to change to the mydir directory.
Verify your present working directory with the pwd command.
As displayed, we're now in bob's mydir directory.
When you use the cd command without options, the current working directory changes to your
home directory, in this case to Bob's home directory.
Run pwd to confirm your present working directory again.
As shown, we're currently in Bob's home directory which is indicated by the ~ symbol.
Or you can type the full path after the cd command to change to a directory.
This example uses an absolute path.
As you can see, we're back in bob's directory called mydir.
An absolute pathname lists all the directories in the path, starting with the root directory.
The root directory is the top most directory on Oracle Linux.
A relative pathname lists the directories in the path relative to the current working
directory.
For example, to change directory to your temp directory use .. to go up a directory as highlighted
after cd command.
Run the pwd command again.
As you can see, we moved up the directory hierarchy and then into the temp directory.
You can use either a relative or an absolute pathname to move around the directory hierarchy.
Let's now display the contents of a text file.
First return to the home directory of Bob using the cd command followed by the ~ a quick
way for returning to the home directory
Before you attempt to open a file using the cat command, it is recommended that you first
run the file command to determine the file type.
As shown, the myfile's format is ASCII text which is an ideal format for using the cat
command.
Let's try out the cat command now on the myfile file.
As you can see, the file is simple text owned and written by bob.
The cp command copies single or multiple files and directories.
To copy a file to a new file in the same directory, use the copy command to copy myfile and calling
the copy file myfile2.
To verify the copy command worked, run ls -l command and option, respectively.
We can see the new file myfile2.
Now, use the file command again to check the type of file for myfile2.
Now let's run cat again on the myfile2 file.
As you can see, the file contents are the same as myfile.
For more information about the cp command options, see the cp man page.
To copy multiple files to a different directory, use the cp command with multiple file names
for the source and a single directory name for the target.
First use the ls -l command to view the available files.
Next cp myfile and myfile2 to the temp directory using the following command.
$ cp myfile myfile2 temp/
Run the ls -l command on the temp directory to validate the files were copied.
As we can see, the copy was successful.
The mv command helps you to move and rename files and directories within the directory
hierarchy.
Let's move or rename the temp directory to temp2.
Now use the ls -F command to view the result.
As we can see, the move command to rename the directory was also successful.
In addition to copying a file you can also copy a directory.
Copy the directory mydir and create a new directory called mydir2.
The -R is to copy the directory contents recursively from one directory to another directory.
This time use the ls -R command again to view the result, recursively.
The mkdir command makes or creates a new directory.
With this in mind, let's recreate the temp directory with the make directory command.
Now create an empty file called alpha in the temp directory.
To quickly create a new file, you can use the touch command which creates a empty file.
View the result with the ls command.
As you can see our new file alpha was created in the recreated temp directory.
To delete a file, use the rm command followed by the filename alpha in the temp directory.
To see the results, use the ls command again on the temp directory.
As displayed, the file name called alpha was deleted.
You can use the rmdir command to delete directories, if empty.
Let's delete the temp directory with the rmdir command followed by the directory temp.
Use the ls -F command to view the results.
As you can see the temp directory was deleted.
Finally, the find command searches for files that match a filename pattern, starting in
the location specified by pathname.
The find command also searches for subdirectories recursively.
When a file matches the filename pattern specified in the find command, its full directory path
is printed.
For instance, let's search for the file myfile using the find command followed by
the tilde for bob's home directory dash name for the filename myfile.
As you can see the file myfile is located in two directories /home/bob/ and the temp2
directory.
Now let's search for the directory by the name of mydir.
Again use the find command followed by the tilde for the home directory followed by the
name option and the directory mydir.
As shown, the directory mydir was found and located in /home/bob.
These are just a few commands and options for managing and searching for files and directories
on Oracle Linux.
To explore more, man pages about all of the commands are available for Oracle Linux.
Oracle provides an extensive number of resources which you can use to learn more about this
subject and others.
Look for additional videos on Oracle Linux and other topics using the link shown.
This concludes the video.
Thank you for watching.