The File System¶
You are probably used to the file system in Windows or MacOS, where directories can contain files and more directories. The linux filesystem is structured in the same way, as a tree, that begins at the ‘root’ directory /.
When you are working in the command line, you are located in a directory somewhere in this tree. There are two ways to refer to a location: its absolute path or its relative path.
# Absolute path
/nfs/home/fieldc
# Relative path
../../home/fieldc
The .. refers to the directory above a location, so the relative path here goes up twice, then back down to my home directory. If a path starts with ~/ then it refers to your home directory.
# Home directory
~/
Exercises¶
Use pwd to find out where you are in your command line session - it should be /nfs/home/<your eth name>
Use ls to see if you have any files in your home directory - probably not if you have never logged in before!
Use cd to go up one level and then ls to see all the home directories of other users on the server
Use ls to look into the directory of another user - can you do this?
Experiment with cd and ls to explore the directory structure on Morgan, before returning to your home directory
Getting Help¶
man will show a manual for most basic commands, providing the correct syntax to use it and the various options available.
# Read the manual
man ls
Other programs have different ways to provide help on how to use them. A online tutorial is best, or a comprehensive manual, but sometimes you only have the command line to help you.
# Help please!
python -h
python --help
Basic File Operations¶
cp copies a file from one location to another. The example will copy a file containing the genome sequence of E. coli K12 MG1655 to your home directory.
# Copy
cp source destination
cp /science/teaching/ecoli/GCF_000482265.1_EC_K12_MG1655_Broad_SNP_genomic.fna ~/
mv moves a file from on location to another. The example, because the destination is not a directory, actually renames the file. Thus you can move and rename a file with the same command.
# Move or rename
mv source destination
mv ~/GCF_000482265.1_EC_K12_MG1655_Broad_SNP_genomic.fna ~/E.coli_K12_MG1655.fna
rm removes a file, so use it with care.
# Remove
rm path
rm ~/E.coli_K12_MG1655.fna
mkdir creates a new directory with the given name.
# Make directory
mkdir genomes
Exercises¶
Using the commands you’ve been introduced to, create a new directory and copy the E. coli genome into it.
Rename the file to something less complex.
By using the man and ls commands, find out how large the E. coli genome file is.