Create files in that hierarchy using an editor or by copying and also renaming existing files.

You are watching: To display the contents of a file called data, use the command ____.

Delete, copy and also move specified papers and/or directories.

Creating directories

We now know how to discover files and directories,but just how do we create them in the very first place?

Step one: see where we are and what we already have

Let’s go back to ours shell-lesson-data magazine on the Desktopand usage ls -F to check out what that contains:

Create a directory

Let’s develop a new directory dubbed thesis using the command mkdir thesis(which has no output):

As you could guess native its name,mkdir way ‘make directory’.Since thesis is a family member path(i.e., go not have actually a leading slash, favor /what/ever/thesis),the new directory is developed in the present working directory:

Note the mkdir is not limited to creating solitary directories one in ~ a time.The -p option allows mkdir to create a brochure with nested subdirectoriesin a single operation:

The -R choice to the ls command will list all nested subdirectories within a directory.Let’s usage ls -FR to recursively perform the brand-new directory hierarchy we just created in theproject directory:

Two methods of doing the same thing

using the shell to develop a directory is no different than using a paper explorer.If you open up the current brochure using your operating system’s graphical record explorer,the thesis brochure will appear there too.While the shell and the paper explorer space two different ways of communicating with the files,the files and directories themselves room the same.

Good names because that files and directories

Complicated surname of files and directories have the right to make her life painfulwhen working on the command line. Below we provide a few usefultips because that the name of her files and also directories.

Don’t use spaces.

Spaces can make a name more meaningful,but due to the fact that spaces are supplied to separate debates on the command lineit is far better to avoid them in names of files and also directories.You can use - or _ rather (e.g. North-pacific-gyre/ quite than phibìc pacific gyre/).To check this out, shot typing mkdir phibìc pacific gyreand view what catalog (or directories!)are made as soon as you examine with ls -F.

Don’t start the name v - (dash).

Commands law names beginning with - together options.

Stick through letters, numbers, . (period or ‘full stop’), - (dash) and also _ (underscore).

Many other personalities have special meanings on the command line.We will certainly learn around some of these during this lesson.There room special personalities that can reason your command to not work asexpected and can even result in data loss.

If you must refer to names of files or directories that have spacesor other special characters, you should surround the surname in price quotes ("").

Create a text file

Let’s adjust our working catalog to thesis making use of cd,then run a text editor called Nano to develop a file called draft.txt:

$ cd thesis$ nano draft.txt

Which Editor?

as soon as we say, ‘nano is a message editor’ us really do mean ‘text’: that canonly work-related with level character data, no tables, images, or any otherhuman-friendly media. We use it in examples due to the fact that it is one of theleast facility text editors. However, therefore trait, the maynot be powerful enough or flexible enough for the work-related you must doafter this workshop. On Unix systems (such together Linux and macOS),many programmers usage Emacs orVim (both of i beg your pardon require more time to learn),or a graphical editor such asGedit. Top top Windows, you might wish touse Notepad++. Windows likewise has a built-ineditor dubbed notepad that can be run from the command line in the sameway together nano for the objectives of this lesson.

No matter what editor you use, you will require to recognize where that searchesfor and also saves files. If you start it native the shell, it will (probably)use your existing working directory as the default location. If friend useyour computer’s start menu, it might want come save documents in your desktop computer ordocuments directory instead. Girlfriend can readjust this by navigating toanother catalog the very first time friend ‘Save As…’

Let’s form in a couple of lines of text.Once we’re happy v our text, we have the right to press Ctrl+O(press the Ctrl or Control an essential and, whileholding it down, press the O key) to write our data come disk(we’ll it is in asked what file we desire to conserve this to:press return to accept the suggested default that draft.txt).


Once our record is saved, we deserve to use Ctrl+X come quit the editor andreturn to the shell.

Control, Ctrl, or ^ Key

The Control vital is additionally called the ‘Ctrl’ key. There are various waysin which using the Control an essential may be described. Because that example, friend maysee an accuse to press the Control vital and, while holding the down,press the X key, described as any type of of:

Control-X Control+X Ctrl-X Ctrl+X ^X C-x

In nano, follow me the bottom of the display screen you’ll see ^G Get aid ^O WriteOut.This method that you have the right to use Control-G come get help and Control-O to save yourfile.

nano no leave any kind of output ~ above the display screen after it exits,but ls now shows that us have developed a paper called draft.txt:

$ ls
What walk the touch command do?When girlfriend look at her current directory using the GUI paper explorer,does the paper show up?

Use ls -l to check the files. How large is my_file.txt?

When might you want to develop a document this way?


The touch command generates a new record called my_file.txt inyour present directory. Youcan watch this freshly generated document by inputting ls in ~ thecommand line prompt. My_file.txt can also be perceived in yourGUI record explorer.

When you inspect the record with ls -l, note that the dimension ofmy_file.txt is 0 bytes. In various other words, it contains no data.If you open my_file.txt making use of your message editor the is blank.

Some programs perform not generate output files themselves, butinstead call for that empty papers have currently been generated.When the routine is run, the searches because that an existing record topopulate v its output. The touch command permits you toefficiently generate a blank text file to be provided by suchprograms.

What’s In A Name?

You may have noticed that all of Nelle’s documents are called ‘something dotsomething’, and also in this part of the lesson, we constantly used the extension.txt. This is just a convention: us can call a paper mythesis oralmost something else us want. However, most world use two-part namesmost of the time to help them (and your programs) tell different kindsof papers apart. The second component of such a surname is called thefilename extension and indicateswhat type of data the file holds: .txt signal a level text file, .pdfindicates a PDF document, .cfg is a configuration file full of parametersfor some regime or other, .png is a PNG image, and also so on.

This is simply a convention, albeit critical one. Papers containbytes: it’s up to us and also our program to interpret those bytesaccording come the rules for level text files, PDF documents, configurationfiles, images, and so on.

Naming a PNG photo of a whale as whale.mp3 no somehowmagically turn it right into a recording of whale song, though it mightcause the operating device to try to open it v a music playerwhen someone double-clicks it.

Moving files and directories

Returning come the shell-lesson-data directory,

cd ~/Desktop/shell-lesson-data/
One need to be cautious when point out the target file name, since mv willsilently overwrite any existing record with the same name, i m sorry couldlead to data loss. An additional option, mv -i (or mv --interactive),can be provided to do mv asking you for confirmation before overwriting.

Note that mv likewise works ~ above directories.

See more: Which Of The Following Describes A Holocrine Gland, Ch 4 Homework Flashcards

Let’s relocate quotes.txt into the current working directory.We use mv as soon as again,but this time we’ll use just the name of a brochure as the second argumentto phone call mv that we desire to store the filenamebut put the record somewhere new.(This is why the command is dubbed ‘move’.)In this case,the magazine name we usage is the special brochure name. The we stated earlier.