Write and Test Commands to Do the Following. (Answers Can Vary) Create a Folder Named C:data
Navigating Files and Directories
Overview
Didactics: 30 min
Exercises: 20 minQuestions
How tin can I perform operations on files outside of my working directory?
What are some navigational shortcuts I can use to make my piece of work more efficient?
Objectives
Use a single command to navigate multiple steps in your directory structure, including moving backwards (one level upwards).
Perform operations on files in directories outside your working directory.
Work with hidden directories and subconscious files.
Interconvert between absolute and relative paths.
Utilise navigational shortcuts to motility around your file arrangement.
Moving around the file system
We've learned how to employ pwd to find our current location inside our file organisation. We've also learned how to use cd to modify locations and ls to listing the contents of a directory. Now we're going to learn some additional commands for moving around within our file system.
Employ the commands nosotros've learned so far to navigate to the shell_data/untrimmed_fastq directory, if y'all're not already there.
$ cd $ cd shell_data $ cd untrimmed_fastq What if nosotros desire to move back up and out of this directory and to our acme level directory? Can we type cd shell_data? Endeavor it and come across what happens.
-bash: cd: shell_data: No such file or directory Your computer looked for a directory or file chosen shell_data within the directory you were already in. It didn't know you wanted to look at a directory level above the one you lot were located in.
We have a special control to tell the computer to motility us back or upward one directory level.
Now we can use pwd to make certain that we are in the directory we intended to navigate to, and ls to bank check that the contents of the directory are correct.
sra_metadata untrimmed_fastq From this output, nosotros tin see that .. did indeed accept us back one level in our file organisation.
Y'all can chain these together like so:
prints the contents of /home.
Starting time navigate to the
shell_datadirectory. There is a hidden directory within this directory. Explore the options forlsto find out how to run across hidden directories. List the contents of the directory and identify the proper name of the text file in that directory.Hint: hidden files and folders in Unix kickoff with
., for example.my_hidden_directorySolution
First use the
mancommand to await at the options forls.The
-aoption is brusque foralland says that information technology causeslsto "not ignore entries starting with ." This is the option we want.. .. .hidden sra_metadata untrimmed_fastqThe name of the hidden directory is
.hidden. Nosotros can navigate to that directory usingcd.Then list the contents of the directory using
ls.The proper noun of the text file is
youfoundit.txt.
In most commands the flags can exist combined together in no detail social club to obtain the desired results/output.
Examining the contents of other directories
By default, the ls commands lists the contents of the working directory (i.e. the directory yous are in). You can always find the directory you are in using the pwd command. All the same, you can also give ls the names of other directories to view. Navigate to your dwelling directory if y'all are not already in that location.
So enter the command:
sra_metadata untrimmed_fastq This will list the contents of the shell_data directory without you needing to navigate at that place.
The cd command works in a similar way.
Try entering:
$ cd $ cd shell_data/untrimmed_fastq This volition have you lot to the untrimmed_fastq directory without having to go through the intermediate directory.
Navigating exercise
Navigate to your abode directory. From at that place, list the contents of the
untrimmed_fastqdirectory.Solution
$ cd $ ls shell_data/untrimmed_fastq/SRR097977.fastq SRR098026.fastq
Full vs. Relative Paths
The cd command takes an statement which is a directory name. Directories can be specified using either a relative path or a full absolute path. The directories on the calculator are arranged into a hierarchy. The full path tells you where a directory is in that hierarchy. Navigate to the home directory, and then enter the pwd control.
You will run into:
This is the full name of your home directory. This tells yous that you are in a directory chosen dcuser, which sits inside a directory called dwelling house which sits inside the very pinnacle directory in the hierarchy. The very tiptop of the hierarchy is a directory called / which is unremarkably referred to every bit the root directory. So, to summarize: dcuser is a directory in abode which is a directory in /. More than on root and home in the side by side department.
Now enter the post-obit command:
$ cd /home/dcuser/shell_data/.hidden This jumps forrard multiple levels to the .subconscious directory. At present get back to the home directory.
Y'all can also navigate to the .hidden directory using:
These 2 commands accept the same effect, they both take us to the .subconscious directory. The starting time uses the accented path, giving the total accost from the dwelling directory. The 2nd uses a relative path, giving just the address from the working directory. A full path ever starts with a /. A relative path does non.
A relative path is like getting directions from someone on the street. They tell y'all to "go right at the end sign, and then turn left on Main Street". That works neat if you're standing there together, merely not then well if you lot're trying to tell someone how to become there from another country. A full path is like GPS coordinates. It tells you exactly where something is no matter where you are correct at present.
You can usually utilise either a full path or a relative path depending on what is almost convenient. If nosotros are in the home directory, it is more convenient to enter the full path. If we are in the working directory, it is more convenient to enter the relative path since it involves less typing.
Over fourth dimension, it will become easier for you to keep a mental notation of the structure of the directories that yous are using and how to quickly navigate amidst them.
Relative path resolution
Using the filesystem diagram below, if
pwddisplays/Users/thing, what willls ../backupbrandish?
../backup: No such file or directory2012-12-01 2013-01-08 2013-01-272012-12-01/ 2013-01-08/ 2013-01-27/original pnas_final pnas_sub
![]()
Solution
- No: there is a directory
backupin/Users.- No: this is the content of
Users/thing/backup, but with..we asked for 1 level farther upwardly.- No: come across previous explanation. Also, we did not specify
-Fto display/at the end of the directory names.- Yes:
../backuprefers to/Users/backup.
Navigational Shortcuts
The root directory is the highest level directory in your file organization and contains files that are important for your estimator to perform its daily work. While you will exist using the root (/) at the kickoff of your absolute paths, it is important that you avoid working with data in these higher-level directories, as your commands tin permanently modify files that the operating organization needs to part. In many cases, trying to run commands in root directories volition require special permissions which are not discussed here, then information technology's all-time to avoid them and work within your home directory. Dealing with the dwelling house directory is very common. The tilde graphic symbol, ~, is a shortcut for your home directory. In our instance, the root directory is two levels above our home directory, and so cd or cd ~ will have you to /home/dcuser and cd / will accept you to /. Navigate to the shell_data directory:
Then enter the command:
This prints the contents of your home directory, without y'all needing to blazon the full path.
The commands cd, and cd ~ are very useful for quickly navigating back to your dwelling directory. We will be using the ~ character in later lessons to specify our home directory.
Fundamental Points
The
/,~, and..characters stand for important navigational shortcuts.Hidden files and directories start with
.and can be viewed usingls -a.Relative paths specify a location starting from the electric current location, while absolute paths specify a location from the root of the file system.
Source: https://datacarpentry.org/shell-genomics/02-the-filesystem/index.html
Post a Comment for "Write and Test Commands to Do the Following. (Answers Can Vary) Create a Folder Named C:data"