terminalMobaXTermHOME directoryHOME directorybuilt-in commands:
PATHPATH is a variable and ordered list of filesystem directoriesPATH set upon loginPATH is a variable and can be changedexuser should be your usernamehost should start login1. or login2. and end arc3 or arc4~ (tilde) indicates you are in your Home Directory$ (dollar) is where commands are formulated and entered| Command | Description |
|---|---|
pwd |
Print the current working directory |
man |
Load the manual |
ls |
List the contents of a directory |
mkdir |
Make a new directory |
cd |
Change directory |
pwdXX should be 01 or 02user should be your usernamepwd exercisepwd’ at the prompt by typing the letters, then press the <return> or <enter> key:ls 1/3ls:
-a option will list all the contents of a directory
. are hidden by default-l option will list each item line by line with added details-h option will report sizes in a more human readable formatls 2/3ls 3/3ls exercise– List all the details of the contents of your Home directory including the hidden files and directories:
--help and man--help is a command option that prints help about using the commandman is a command to bring up the manualman: press the h-key `man, or man itself: press <q><space_bar> to page through--help and man exerciseman: press the h-key <h>.man or any man page: press <q>.<space_bar>.ls:ls:.bash_profile
.bashrc
mkdir 1/2test so long as you are in a directory where you have permission to write:mkdir 2/2-p option allows for creating parent directoriestest2 and in this the directory test3cdtest directory (from the current directory):ls, mkdir and cd demols, mkdir and cd exercisels, mkdir and cd in your home directory./nobackup (change “exuser” to be your USERNAME):<up> and <down> arrow keys allow you to scroll previously entered commands
<return> will enter the command<Ctrl> and another key will often do things:
<Ctrl> + <c> will cancel
<Ctrl> + <a> will move the cursor to the start of what is at the prompt<Ctrl> + <e> will move the cursor to the end of what is at the prompt<Ctrl> + <r> will do a reverse search through the history of commands entered at the prompt which can then be edited or entered<Tab> can be used to help autocomplete file paths
<Tab> repeatedly two or three times to reveal optional paths
<up> and <down> arrow keys to load previously entered commands into the prompt<Ctrl> + <a>, and <Ctrl> and <e> to move the cursor between the start and end of what is at the prompt<Ctrl> + <c> to cancel<Ctrl> + <r> to reverse search through the history of commands, and select one to edit or runhistory commandhistory
history command to get a list of commands that have been executed, and then to use ![number] to repeat one of those commands..bash_history
| Command | Description |
|---|---|
mv |
Move a file or directory (can be used to rename) |
cp |
Copy a file or directory - using the -r option |
touch |
Access or create a file or directory |
rmdir |
Remove (delete) a directory |
rm |
Remove (delete) a file or a directory - using the -r option |
mvtest to test_renamedcptest is a file the following would make a copy named test_copy:test is a directory a warning would be printed:-r option can copy a directory:touch, >, >>touch is a command that will create an empty file, or update the time a file was last accessed to the current time> can be used to direct the standard output to a file.
ls to a file named README>> can be used in place of > to append to rather than overwrite the filermdirrmtest:-r option can be used.-i option allows for interactivity so the user can choose what to delete.-f option forces.rm, especially combined with -r and -f options.mv, cp, rmdir, rm, touch, >, >> exercisetest0/test01 into test0/test03test0/test02 into test0/test04test0/test03ls into ls.outls -al into ls.out| Command | Description |
|---|---|
cat |
Concatenate and print |
less |
Open into a paginated reader view |
sort |
Sort lines |
cut |
Cut lines based on a given character |
head |
Print the first lines of a file (default 10) |
tail |
Print the last lines of a file (default 10) |
wc |
Print newline, word, and byte counts |
git command:git is a distributed version control systemshell-training.cat, sort, cut and pipe |cat concatenates (streams one thing after another) and prints to standard outputsort sorts lines (by default alphabetically)cut cuts lines based on a given character|
test and test2 can be concatenated, sorted alphabetically and piped into head as follows:cat, sort, cut, pipe | exercisecat, cut, and sort to print out the Latin names from the file IOM-animals/birds.txt in alphabetical order.cut -d ',' -f 2 will split lines around the comma and yield the second field.Another option uses awk instead of cut:
awk is a scripting language used for manipulating data and generating reports
cut is restricted to a single character field separator.{FS=","} part of the awk command sets the field separator to a comma, to set as a space followed by a comma use {FS=" ,"}head and tailhead command prints the first lines of a filetail command prints the last lines of a file-n optionhead and tail exerciseList all the lines in the files in IOM-animals directory alphabetically and find the 50th item.
| Command | Description |
|---|---|
grep |
Filter lines |
sed |
Stream editor |
sed 1/2sed 2/2sed program:foo with bar on every linesed as it can modify filesgrepfoo:foo:sed and grep demoshell-training/data/ contains 300 data files, each of which should contain 100 values. One or more of these files are missing some data though…wc -w will tell you the number of values in a filesort -n will sort numericallyls command with the -l optionls -l shows:-rw-------- 1 <owner> <group> <size> <date> <time> test-file
| | | | | | |
| | | | | | +----> time last modified
| | | | | +-----------> date last modified
| | | | +------------------> size in bytes
| | | +--------------------------> group assignment
| | +----------------------------------> owner username
| +---------------------------------------> number of hard link
+----------------------------------------------> type and permissions
-rw--------
| | | | |
| | | | +--> another type
| | | +----> all user permissions (3 characters)
| | +-------> group user permissions (3 characters)
| +----------> owner permissions (3 characters)
+------------> type (1 character)
drwxr-x----
-rw--------
chmod command.-rwx------ to test.file:chgrpgroups can be used to print out what groups there are, and what group a user is part ofvar is set equal to the number 1.echo is a command that will send what comes after it to the Standard Output (stdout).$ symbol followed by the name of the variable.printenv will print all the variables in use.; there can be a new line:* can represent anything.? can represent any single character.[] can represent any single character detailed in the square brackets.a:a and ending .txt that have one character between these:a and ending .txt that have any other string with a 0 or a 1 character between these:If the following is run from the wildcards directory. What will be printed?
What will the contents of new-file.txt be and why?
.txt file:
echo command prints a different file name each iterationnew-file.txt will be the same as xyz.txt:
new-file.txt each iteration, overwriting whatever was written on the previous iteration>> instead of > would append instead of overwrite.nanovimemacsnano.dos2unix and unix2dos may be helpful to get this right..shshebang:
shebang, simply enter all the commands for the script.# will be regarded as comments
script.sh can be run using:wildcards directory.history command to see the commands you’ve enteredhistory output into tailnano to modify this into a scriptIf you have any questions or would like to learn more about Research Computing, please do not hesitate to get in touch with us.