1/125
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
pwd lets you:
see which directory you're presently in
Which command would take you directly to the file RNAsamp.txt, which is located in your home directory?
cd ~/RNAsamp.txt
Which keyboard shortcut lets you move your cursor to the start of a line (on a Mac at least)?
CTL+A
Which of the following options makes the list command put file size output using metric units (KB, MB, etc.) rather than just listing in bytes?
-h
Which of the following is an allowable file name?
yanni.best_hits
How do you create a new file using nano?
nano newfile.txt
You open a .txt file using nano, but there are all sorts of unexpected characters in addition to your expected text. What happened?
It was a .txt file, but saved as Rich Text Format
What happens when you execute this command? cat file1.txt file2.txt
You read file1 and file2 back to back as one output
I can't remember all these goofy key commands in less! What do I type (while I'm in less) to allow me to learn them?
h
How do I output the first 10 lines of the Unix manual entry on ls?
head man ls
Create a new directory called "birds" and then create a new directory called "jays" inside of that
mkdir - p birds/jays
What does mv introns1.txt introns2.txt accomplish?
renames introns1.txt to the name "introns2.txt"
What does cp file1.txt file2.txt accomplish if both files are already existing?
contents of file2 replaced by contents of file1; file1 remains intact
What is the purpose of "$" in the command echo $a ?
indicates that a is a variable
What does this command do? less ../file1.txt
it reads file1.txt located in the directory above the pwd
How would you sort the contents of a file, such as species names, and then store the sorted list?
sort species.txt > sortedspecies.txt
How could you combine the contents of two files into one file?
less file1.txt >> file2.txt
What would this display? species.txt | sort
nothing, because it wasn't read by cat or less before being piped to "sort"
Why do you need to use sort before you use uniq, as in: specieslist.txt | sort | uniq ?
unique checks for duplicates only in the next line
Are these equivalent? sort < animallist.txt vs. sort animallist.txt
yes
What does the command "wc" output?
number of lines, words, characters
What does sort -r do?
reverses the alphanumeric sort order
Which is the appropriate format to perform a calculation using the "bc" app in Unix?
echo '(1+2)*3' | bc
"animallist.txt" contains several lines, each line naming the animal and briefly describing it. What would this command return? grep mouse animallist.txt
Just the lines in animallist.txt that had the word "mouse" in them
What does this command return, using a file fruit_facts.txt that consists of several lines of text describing various fruits? grep -vi apple fruit_facts.txt
all the lines not containing apple or Apple
What would this command return? ls animals_folder/ | grep animal
The filenames in animals_folder that have the text "animal" in them
How many players listed on the Baylor football roster document posted on Canvas are juniors ("Jr.")? Use grep to solve this! Hint: -c
24
Using that Baylor football roster, how many Safeties ( listed as "S") on the team? Hint: -w
8
I foolishly wrote "grep docx -R" and, mercifully, Unix gave me a warning. How do I now exit this warning mode and return to my normal command line? [Read your notes; don't experiment on your computer]
^c
A "folder" is called a _______ in Unix talk
"directory"
pwd
"present working directory" — This tells you what folder (aka "directory") you're presently in
ls
"list" — This lists all the files in your pwd
ls dir1
"list" the files in directory "dir1", which must reside in your pwd or this won't work
cd dir1
"change directory" to directory dir1 — This changes your location into another directory within the
pwd
cd ~
Goes to your home directory
cd /
Goes to root of hard drive
cd /dir1/subdir1/subsubdir1
from the root directory, go to subdir1, then go to subsubdir1 within that. This is
called the absolute path of the target directory subsubdir1.
cd dir2/subdir2/subsubdir2
from the pwd, go to dir2, then to subdir2, then to subsubdir2. This is called the
relative path.
cd ..
Goes to the parent directory of the pwd
cd ../..
Goes to parent of the parent directory of the pwd
cd -
Goes to the previous pwd. Very useful for jumping back and forth between distant directories.
CTL+A
move cursor to start of a line
CTL+E
move cursor to end of a line
up & down arrows
rotate through previous commands
Tab
auto completion
Tab Tab
lists all the possible auto completion hits and then starts a fresh line, waiting for you to type in the hit
that you choose
Note the backslash (\) that "escapes" the character immediately downstream
This is a character, like a space,
that would trip up Unix. You are supposed to write in these backslashes yourself , but tab completion does it for you automatically
up arrow:
previous commands. Keep pushing until you retrieve the previous command you want. Then use your
back and front arrow to navigate through the command and delete and type to modify it
CTL+L
Clear screen, but you can still scroll up to see old lines
CMD+K
Really clears screen; all old lines gone
CTL+C
Escape from a program if you're stuck; gets you your prompt back
exit
Type this to get out of Unix
You still have to quit Terminal by
CMD+Q(or go to the Mac File menu at the top bar and choose "quit")
Q to quit
Format for the command line
Typed commands run everything in Unix.
Commands have options that modify how they work
and arguments that the command works on
Here is the format:
command -options arguments
ls -a ~/mydir
Here, ls is the command (list), -a is the option (list
all the files, even the hiden ones), and ~/mydir is the
argument. Mydir is the directory, residing in the home directory (~), whose files you want listed. The front slash indicates that ~ is the parent directory and mydir is the child directory within it
Options can be written two ways:
-a (written as a single letter) or --all (written in expanded form)
You can have multiple options: for example, the
ls ("list") command can take these three options all at once:-l -a -h
or -lah.
You would write it like this: ls -lah
ls -lah
In this case, -l is the option to print out the
long version of the output, and -h is the option to print out a "human-readable" version with file sizes in normal kilobytes rather than in bytes
Options can have their own arguments: -w 50
or -w50
this sets the width option of a certain command to 50
Rules for naming files:
no symbols except . _ - (but not as first character of name). Never use spaces. Good to use file appendages:
.txt, .py, etc. Not required, because Unix doesn't use file extensions. But including them helps humans identify the file type. Don't use a Unix command name as a file name
Text Editors:
These are the equivalent to Microsoft Word for Unix, but far simpler and without the GUI
nano, which has now completely replaced pico
Basic and easy to use. To save changes made to a file (or a new file): ^x, then y (yes), then Return.
nano oldfile.txt
Now you can edit the existing file oldfile.txt
nano newfile.txt
Now it will create newfile.txt, a new file. You will be put into a nano window. Now you can write whatever text you want. Hit Return key to get a new
line. Navigate using your arrow keys.
^K
cuts text in nano
^U
uncuts (pastes) text in nano
^
is the control button in nano
T or F: Text files should have only text, not formatting, in order for them to work properly in the following examples.
True
Text files:
Be sure you set the preference for having the extensions (like .txt or .docx) displayed in the file name
Reading Files:
You can use nano to read just fine, but there are tools solely for reading files. "Reading" means outputting to the screen
cat:
originally used to concatenate several files and output them to the screen as one. Now, most often used just to read a single file (cat oldfile.txt)
What is the problem with cat?
whole file outputted at once; have to scroll back to read it
more:
outputs paginated text, but doesn't allow you to go backwards through the pages completely replaced by
less
example of command less:
less oldfile.txt
less:
allows backwards scrolling. Memory efficient (loads one page at a time, not whole document). Man pages use less
less f
forward
less b
backwards
less q
quit
less g
go to the start of the doc
less G
go to the end of the doc
less h
to get help with the long list of key commands
example command head:
head oldfile.txt
head:
outputs first 10 lines of a file
tail:
outputs last 10 lines of a file
head or tail:
to check out the contents and format of a huge file
The man pages:
The Unix manual entry for each command ("man pages"). Automatically opens in
less, so need to know how to navigate in
less
man ls
opens the man pages for the command ls
man less
opens the man pages for the command
less
man cat
opens the man pages for the command
cat
mkdir testdir1
Makes a directory in your pwd
mkdir existingdir1/testdir2
Makes a directory within an existing directory in your pwd
mkdir -p testdir1/testdir2
Creates a directory and then another directory within the new directory
mkdir -vp testdir1/testdir2
creates a directory and then another directory within the new directory and outputs the result: testdir1/testdir2 (verbose)
mv oldfile.txt testdir1/oldfile.txt
Moves existing file to another directory (in brown is optional; you could rename it this way)
mv testdir1 testdir2
Moves testdir1 into testdir2. So you move directories the same way as files
T or F: Don't use the rename function; in Unix, we use mv (as above) if moving it
True
Do not use rename function in Unix. Example of renaming a file:
mv oldfile1.txt oldfile2.txt
mv -n
no overwriting