Home | Login and Logout | Basic Command Line Commands | File System | File Editing Through Terminal | Java Programs | Input/Output Redirection | Grep | Works Cited

The File System

Working with the file system may be broken up into several sections:

Working with Files

Viewing Files
Opening the File
Basic file viewing can be accomplished by using the less command. To open a file you must first navigate to the directory in which the file is stored. Then simply enter less [FILENAME].[EXTENSION]. This will turn your terminal window into the text of the file.

Example:
less lorempisum.txt


Navigating the File


Exiting the File
To exit the file, simply press the 'q' key. This will return you to the terminal where you had left off before entering the file.
(Newell, 2017)

Creating Files
Creating a new file is done by using the touch command. To create a new This is utilized by typing " touch path/to/directory/filename" where path/to/directory is either an absolute or relative path to the directory in which you would like to create the file, and filename is replaced by the file you would like to create.

Example:
If I wanted to create a new txt file titled "sample" in my documents folder, I would type "touch ~/Documents/sample.txt".

Deleting Files
To remove a file, simply type "path/to/directory/filename" where path/to/directory is replaced by an absolute or relative path to the directory in which the file is stored and filename is replaced by the name and extension of the file that you would like to delete. The terminal will then ask to confirm that the file should be deleted. Simply press 'y' and hit enter. If you typed rm by mistake and do not want the file to be deleted type 'n' followed by enter.

Example:
To delete the "sample.txt" file created in the file creation example, I would type "rm ~/Documents/sample.txt". Then I would press 'y' and hit enter.

Moving Files
Moving a file uses the mv command followed by two arguments. These arguments are the path to the file you would like to move, and the path to the location you would like to move it to. Together, this would look like "mv path/to/directory/filename path/to/new/directory". This will keep the filename of the file you are moving the same in the new directory as it was in the old directory. If you would like to change the name of the file to something new in the new directory you would simply add the new filename to the end of the second argument in the command. This would look like "mv path/to/directory/filename path/to/new/directory/newfilename".

Example:
Say I would like to move a file named "truck.txt" from folder1 to folder2 (both of which are subdirectories of Documents) and leave the file with the same name. To do this I would type "mv ~/Documents/folder1/truck.txt ~/Documents/folder2"

Renaming Files
Renaming files can be done using the same command as moving files. This takes advantage of the second case described in moving files where you move a file from one directory to another and change it's name. However, if you would like to leave the file in the same directory, then you would simply leave the path to the new directory as the path to the old directory. In the terminal you would type "mv path/to/directory/filename path/to/directory/newfilename".

Example:
Suppose I am in a folder containing the file "duck.txt" and would like to rename this file to "goose.txt". To accomplish this task, I would type "mv duck.txt goose.txt".

Working with Directories

Creating Directories
Creating directories is extremely similiar to creating files, however, you use the mkdir command. Therefore, to create a directory, type "mkdir path/to/parentdir/dirname". Note that path/to/parentdir is the path to the directory in which you would like to create a sub-directory. Simply replace dirname with the name you would like the directory to have.

Example:
If I wanted to create a directory inside of my home folder titled "pond", then I would type "mkdir ~/pond".

Deleting Directories
Once again, deleting a directory takes on a very similar command to deleting a file. To delete a directory, enter "rmdir path/to/directory" into the terminal.

Example:
If I wanted to remove the "pond" directory created in the previous example, I would type "rmdir ~/pond".

Moving and Renaming Directories
Moving and renaming directories is exactly the same as if you were to move or rename a file. The only difference is that the path used in the arguments of the mv command will differ slightly as it will not include a filename. For moving a file this will appear as "mv path/to/parentdir/directory path/to/newparentdir". For renaming the file this will appear as "mv path/to/parentdir/directoryname path/to/parentdir/newdirectoryname".

Examples:
Suppose that I had deleted the "pond" directory in the deleting directories example because I had actually wanted it to be named "lake". To rename this folder (remember it is located in the home directory) I would have typed "mv ~/pond ~/lake".
Now suppose I has missplaced this folder, and the intention was for the "lake" folder to be in the Documents folder. To move this folder, I would enter " mv ~/lake ~/Documents".


Written by: Daniel Amusin, Derek DeCramer, Nikhil Thammadi