:orphan: ==================================== Becoming Familiar with Unix Commands ==================================== | Familiarity with common `Unix `_ commands makes the practice exercises easier to work through. If you're already comfortable with Unix, skip ahead to the `Initial Exercise <./initial_exercise.html>`_. Otherwise, work through this short exercise first to learn the basics. | | Changing Directories ==================== The command for changing directories is ``cd``. |vspace| #. In Derecho, move to the *practice_exercises* directory in your *scratch* space: .. code-block:: :class: copyable cd /glade/derecho/scratch/$USER/practice_exercises Use this command any time you need to move to a different directory. |vspace| #. A useful shortcut for moving up one directory, regardless of your current location, is typing two periods in a row (..). .. code-block:: :class: copyable cd .. You can also move up through multiple directories at once using this command. For example, move into one of the directories inside practice_exercises, then navigate back to where you started. .. code-block:: :class: copyable cd practice_exercises/wrf/test/em_real cd ../../.. You should now be back in the */glade/derecho/scratch/$USER/* directory. | | Listing Directory Content ========================= For a list of files and directories in your current directory, use ``ls``, which includes various options. |vspace| #. Running the following lists all files and directories in your current directory. .. code-block:: :class: copyable ls |vspace| #. To list files/directories in "long format", which includes information like the file's size, owner, permissions, etc., use the following. .. code-block:: :class: copyable ls -ls |vspace| #. To list file/directories in another directory, you could use something like this example, which prints the contents of your home directory. .. code-block:: :class: copyable ls /glade/u/home/$USER |vspace| #. Hidden files, such as environment files (e.g., *.bashrc*), are often found in your home directory. Change to your home directory, then list all files, including hidden ones. .. code-block:: :class: copyable cd ls -a Notice that no directory was specified with *cd* in this case. This shortcut works only when navigating to your home directory — otherwise, you'll always need to specify a directory. | | Renaming, Moving, or Copying Files and Directories ================================================== To copy a file, use the ``cp`` command. Try copying a file into your */glade/derecho/scratch/$USER/* directory. |vspace| #. First verify that you're in the right place. .. code-block:: :class: copyable cd /glade/derecho/scratch/$USER/ cp practice_exercises/wrf/test/em_real/namelist.input . Notice the full path was needed to locate the file, followed by a "." at the end. This command copies the *namelist.input* file from its current location (*practice_exercises/wrf/test/em_real/*) to the current directory - the (".") meaning "here." |vspace| #. You can also move the file to a location other than "here." .. code-block:: :class: copyable cp practice_exercises/wrf/test/em_real/namelist.input practice_exercises There should now be a copy of *namelist.input* in the *practice_exercises/* directory. Use *ls* to verify. .. code-block:: :class: copyable ls practice_exercises |vspace| #. To move or rename a file, use *mv*. Rename *namelist.input* in your current directory. .. code-block:: :class: copyable mv namelist.input copied_namelist.input List the files in the directory (type ``ls``) to the file name changed to *copied_namelist.input*. |vspace| #. Now move that file to another directory. .. code-block:: :class: copyable mv copied_namelist.input practice_exercises |vspace| #. List the contents in the *practice_exercises/* directory (``ls practice_exercises``). Along with other files/directories, you should see both *namelist.input* and *copied_namelist.input*. | | Other Common Unix Commands ========================== .. csv-table:: :header: Command, Syntax, Usage :escape: \ **mkdir** |br| **rmdir**, ``mkdir new_directory_name``, To make (mkdir) or remove (rmdir) directories **rm**, ``rm file``, Remove files **more**, ``more file``, Prints the first part of a file\, as much as will fit on one screen. Double-tap the space bar to see more or type "q" to quit. **cat**, ``cat file``, Prints the entire file to the screen **head**, ``head file``, Prints the file's first few lines to the screen **tail**, ``tail file``, Prints the file's last few lines to the screen **grep**, ``grep word file`` |br| ``grep -i word file`` |br| ``grep -i word *``, Find lines within the specified file that match the patterns used in the command |br| Add "-i" to make the search case–insensitive |br| Use "*" to search all files in the current (or specified) directory **pwd**, ``pwd``, Prints the path of your current directory **ln -sf**, ``ln -sf path/file``, Creates a symbolic (*-s*) link to a file. After\, the file appears in both locations\, but physically resides in only its original directory. *–f* ensures that if the target already exists\, it is unlinked first so the new link can be created correctly. For additional resources, check out some of these pages: * `Stanford's Basic Unix Commands `_ * `Wikipedia's List of POSIX/Unix Commands `_ * `Colorado State University's VI Commands `_ | | **You can now go back to Case Studies to run the Initial Exercise.** .. rst-class:: horizbuttons-primary-m * `Return to Practice Exercises <./practices.html>`_ .. toctree:: :maxdepth: 4 :hidden: | | | |