2. Access the shell and Introduction to shell Commands (1)¶
How to access the shell¶
On a Mac or Linux machine, you can access a shell through a program called “Terminal”, which is already available on your computer. The Terminal is a window into which we will type commands. If you’re using Windows, you’ll need to download a separate program to access the shell.
Navigating your file system¶
The part of the operating system that manages files and directories is called the file system. It organizes our data into files, which hold information, and directories (also called “folders”), which hold files or other directories.
Several commands are frequently used to create, inspect, rename, and delete files and directories.
code
Let’s find out where we are by running a command called pwd (which stands for “print working directory”). At any moment, our current working directory is our current default directory, i.e., the directory that the computer assumes we want to run commands in, unless we explicitly specify something else. Here, the computer’s response is /home/USERNAME
Terminal
Let’s look at how our file system is organized. We can see what files and subdirectories are in this directory by running ls
, which stands for “listing”. ls
prints the names of the files and directories in the current directory in alphabetical order, arranged neatly into columns. We’ll be working within the shell_data subdirectory, and creating new subdirectories, throughout this workshop.
output - may vary a bit from one computer to another. Check whether the output contains shell-data
We can make the ls output more comprehensible by using the flag -F
, which tells ls to add a trailing / to the names of directories:
- Anything with a “
/
” after it is a directory. Things with a “*
” after them are programs. If there are no decorations, it’s a file.
All commands have a lots of "options" similar to -F
in ls
- Retrieving the list of "options" for a command can be done with
command --help
( For an examplels --help
). However, some command don't implement--help
and even the ones with it might not show the full set of options. Solution for this to useman
command ( or the modern day solution is to search online 😊) man
(short for manual) displays detailed documentation (also referred as man page or man file) for bash commands. It is a powerful resource to explore bash commands, understand their usage and flags. Some manual files are very long. You can scroll through the file using your keyboard’s down arrow or use the Space key to go forward one page and the b key to go backwards one page. When you are done reading, hit q to quit.
Terminal
Let’s say we want to navigate to the shell-data directory we saw above. We can use the following command to get there:
and runpwd
to check the the change in current working directory followed by ls
to list the contents of that directory
Shortcut - Tab Completion
Typing out file or directory names can waste a lot of time and it’s easy to make typing mistakes. Instead we can use tab complete as a shortcut. When you start typing out the name of a directory or file, then hit the Tab key, the shell will try to fill in the rest of the directory or file name.
Return to your home directory and navigate back to shell-data
with the help of Tab:
-
cd
command without a follow up argument will revert the working directory to/home
directory. Same can be done withcd ~
-
Now enter
- The shell will fill in the rest of the directory name for
shell-data
-
Using Tab complete can be very helpful. However, it will only autocomplete a file or directory name if you’ve typed enough characters to provide a unique identifier for the file or directory you are trying to access.
-
For example, if we now try to list the files which names start with
gen
by using tab complete:
- The shell auto-completes your command to
SRR09_
, because all file names in the directory begin with this prefix. When you hit Tab again, the shell will list the possible choices.
code
So far, we have navigated to shell-data
directory from /home
with cd
command and return to /home
via the same method. What if we want to take a look at the content of /home
directory without navigating back to it
- Confirming the current working directory is
/home/USER/shell-data/untrimmed_fastq
- use
ls ..
command where..
represents "one step up"
Copying, renaming, removing files and creating directories¶
Terminal
-
Confirm the current working directory is
/home/USER/shell-data/untrimmed_fastq
-
Let's create a sub-directory within the
..shell-data
directory and name itbackup
. This can be done with themkdir
command
ls -F
to make sure the directory was created
- create a copy of
SRR097977.fastq
file and name itSRR097977.fastq.backup
- "move"
SRR097977.fastq.backup
file tobackup/
directory withmv
command
- Check the content of
backup/
directory withls
- Delete the file in backup directory
Check whether you can delete the backup/
directory with rm
command