script to automate the workflow.
1
2
wget --no-check-certificate https://www.cs.wcupa.edu/lngo/data/shell-lesson-data.zip
unzip shell-lesson-data.zip
pwd: path of working (current) directoryls: listingcd: change directory
pwd returns the absolute path to the current working directory (i.e.: where you are when you are in the terminal).
1
pwd
ls returns the list of current files and directories in the target directory.
1
ls /
1
ls --help
Space key to move down page by page
1
man ls
ls do when used with the -l option? What about if you use both the -l and the -h option?-l option makes ls use a long listing format, showing not only the file/directory names but also additional information, such as the file size and the time of its last modification.-h option and the -l option, this makes the file size human readable, i.e. displaying something like 5.3K instead of 5369.-t lists items by time of last change instead of alphabetically. The command ls -r lists the contents of a directory in reverse order.-t and -r options? Hint: You may need to use the -l option to see the last changed dates.The most recently changed file is listed last when using -rt. This can be very useful for finding your most recent edits or checking to see if a new output file was written.
ls by itself will list the contents of the current directory.
1
ls
cd allows users to change the current directory (outcome of pwd) to the target directory. man cd or cd --help to read the documentation for cd.cd is cd DESTINATION with DESTINATION can either be absolute or relative paths or special paths.
1
2
cd /
ls
~: home direcrory.: current directory..: a directory that is one level above the current directory/home/YOURUSERNAME (YOURUSERNAME: your username on molly)shell-lesson-data directory.shell-lesson-data directory and view the contents of this directory
1
2
3
4
cd ~
ls
cd shell-lesson-data
ls
ls Reading comprehensionpwd displays /Users/backup and -r tells ls to display things in reverse order, what command(s) will result in the following output:
1
pnas_sub/ pnas_final/ original/
ls pwdls -r -Fls -r -F /Users/backuppwd is not the name of a directory.ls without directory argument lists files and directories in the current directory.ls is the command, with an option -F and an argument /.-) or two dashes (--),switches or flags.options and arguments are referred to as parameters. options and arguments are being passed as parameters to the shell’s function that is responsible for executing the command.ls and -F the shell will look for a command called ls-F, which doesn’t exist.ls -s will display the size of files and directories alongside the namesls -S will sort the files and directories by sizeexercise-data.
1
2
3
4
5
pwd
cd ~
cd shell-lesson-data
cd exercise-data/writing
ls -F
thesis, and check for its existence.
1
2
mkdir thesis
ls -F
-p flag in the following commands:
1
2
3
4
5
mkdir ../project/data
ls -F ../project
mkdir -p ../project/data
mkdir -p ../project/report ../project/results
ls -F ../project
-p allows the creation of all directories on the specified path, regardless whether any directory on that path exists.
-, _, and . for annotation, but do not begin the names with them.nanovimemacs.draft.txt inside thesis.
1
2
3
4
pwd
ls
cd thesis
nano draft.txt
Ctrl + O keys: Ctrl then press O.Enter to confirm.Ctrl + X. Y or N.mv is short for move. It will move a file/directory from one location to another.
1
2
3
4
5
6
7
cd ~/shell-lesson-data/exercise-data/writing
ls thesis
mv thesis/draft.txt thesis/quotes.txt
ls thesis
mv thesis/quotes.txt .
ls thesis
ls
sucrose.dat and maltose.dat into the wrong folder. The files should have been placed in the raw folder.
1
2
3
4
5
ls -F
analyzed/ raw/
ls -F analyzed
fructose.dat glucose.dat maltose.dat sucrose.dat
cd analyzed
raw folder:
1
mv sucrose.data maltose.data ____/_____
1
mv sucrose.data maltose.data ../raw
cp stands for copy. It copies a file or directory to a new location, possibly with a new name.
1
2
3
4
cp quotes.txt thesis/quotations.txt
ls quotes.txt thesis/quotations.txt
cp -r thesis thesis_backup
ls thesis thesis_backup
statstics.txt ls command in the sequence shown below?
1
2
3
4
5
6
7
8
pwd
/home/rammy/data
ls
proteins.dat
mkdir recombined
mv proteins.dat recombined/
cp recombined/proteins.dat ../proteins-saved.dat
ls
proteins-saved.dat is located at /home/rammy/ proteins.dat is located at /home/rammy/data/recombined proteins-saved.dat is located at /home/rammy/ shell-lesson-data/exercise-data/writing directory, let’s tidy up this directory by removing the quotes.txt file we created.rm (short for ‘remove’):
1
2
3
4
5
6
cd ~/shell-lesson-data/exercise-data/writing
ls
rm quotes.txt
ls quotes.txt
rm thesis
rm -r thesis
* is a wildcard, which matches zero or more characters. shell-lesson-data/exercise-data/proteins directory: *.pdb matches ethane.pdb, propane.pdb, and every file that ends with ‘.pdb’.p*.pdb only matches pentane.pdb and propane.pdb, because the ‘p’ at the front only matches filenames that begin with the letter ‘p’.? is also a wildcard, but it matches exactly one character. So ?ethane.pdb would match methane.pdb *ethane.pdb matches both ethane.pdb, and methane.pdb.???ane.pdb matches three characters followed by ane.pdb.cubane.pdb, ethane.pdb, octane.pdb.shell-lesson-data/exercise-data/proteins and try the following commands
1
2
3
4
ls *t*ane.pdb
ls *t?ne.*
ls *t??ne.pdb
ls ethane.*
Sam has a directory containing calibration data, datasets, and descriptions of the datasets:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
.
├── 2015-10-23-calibration.txt
├── 2015-10-23-dataset1.txt
├── 2015-10-23-dataset2.txt
├── 2015-10-23-dataset_overview.txt
├── 2015-10-26-calibration.txt
├── 2015-10-26-dataset1.txt
├── 2015-10-26-dataset2.txt
├── 2015-10-26-dataset_overview.txt
├── 2015-11-23-calibration.txt
├── 2015-11-23-dataset1.txt
├── 2015-11-23-dataset2.txt
├── 2015-11-23-dataset_overview.txt
├── backup
│ ├── calibration
│ └── datasets
└── send_to_bob
├── all_datasets_created_on_a_23rd
└── all_november_files
Before heading off to another field trip, Sam wants to back up her data and send datasets created the 23rd of any month to Bob. Sam uses the following commands to get the job done:
1
2
3
4
cp *dataset* backup/datasets
cp ____calibration____ backup/calibration
cp 2015-____-____ send_to_bob/all_november_files/
cp ____ send_to_bob/all_datasets_created_on_a_23rd/
Help Sam by filling in the blanks.
The resulting directory structure should look like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
.
├── 2015-10-23-calibration.txt
├── 2015-10-23-dataset1.txt
├── 2015-10-23-dataset2.txt
├── 2015-10-23-dataset_overview.txt
├── 2015-10-26-calibration.txt
├── 2015-10-26-dataset1.txt
├── 2015-10-26-dataset2.txt
├── 2015-10-26-dataset_overview.txt
├── 2015-11-23-calibration.txt
├── 2015-11-23-dataset1.txt
├── 2015-11-23-dataset2.txt
├── 2015-11-23-dataset_overview.txt
├── backup
│ ├── calibration
│ │ ├── 2015-10-23-calibration.txt
│ │ ├── 2015-10-26-calibration.txt
│ │ └── 2015-11-23-calibration.txt
│ └── datasets
│ ├── 2015-10-23-dataset1.txt
│ ├── 2015-10-23-dataset2.txt
│ ├── 2015-10-23-dataset_overview.txt
│ ├── 2015-10-26-dataset1.txt
│ ├── 2015-10-26-dataset2.txt
│ ├── 2015-10-26-dataset_overview.txt
│ ├── 2015-11-23-dataset1.txt
│ ├── 2015-11-23-dataset2.txt
│ └── 2015-11-23-dataset_overview.txt
└── send_to_bob
├── all_datasets_created_on_a_23rd
│ ├── 2015-10-23-dataset1.txt
│ ├── 2015-10-23-dataset2.txt
│ ├── 2015-10-23-dataset_overview.txt
│ ├── 2015-11-23-dataset1.txt
│ ├── 2015-11-23-dataset2.txt
│ └── 2015-11-23-dataset_overview.txt
└── all_november_files
├── 2015-11-23-calibration.txt
├── 2015-11-23-dataset1.txt
├── 2015-11-23-dataset2.txt
└── 2015-11-23-dataset_overview.txt
1
2
3
cp *calibration.txt backup/calibration
cp 2015-11-* send_to_bob/all_november_files/
cp *-23-dataset* send_to_bob/all_datasets_created_on_a_23rd/