%%{init: {'theme': 'neutral', 'themeVariables': { 'fontFamily': 'monospace', "fontSize":"16px"}}}%%
flowchart TD
Root(<code>/</code>)
bin(<code>/bin</code>)
etc(<code>/etc</code>)
home(<code>/home</code>)
usr(<code>/usr</code>)
var(<code>/var</code>)
tmp(<code>/tmp</code>)
Root --> bin
Root --> etc
Root --> home
Root --> usr
Root --> var
Root --> tmp
Directories
When presented with a new map, the most important thing to find is your location on it (itโs hard to know where youโre going without knowing where you are). In Linux, directories are more than just containers for files; they are a critical part of the hierarchical file system, which is organized in a tree-like structure starting from the root directory (/).
Root Directory
The root directory is the topmost directory in the Linux file system hierarchy. All other directories and files are nested within it. It is represented by a single forward slash / and contains critical system directories like /bin, /etc, /home, and /var.
Subdirectories
Beneath the root directory, the Linux file system is organized into various subdirectories, each serving specific purposes:
/bin โ Contains essential user command binaries
/etc โ Stores system-wide configuration files.
/home โ Houses personal directories for each user.
/var โ Contains variable data like logs and spool files.
In Linux systems, the ~ represents the userโs โhomeโ directory.
File paths
A file path is a character string specifying the unique location of a file or directory within the hierarchical file system. File paths can be absolute (starting from the root (/) directory) or relative (starting from the current (.) directory).
Manage
In the Linux world, file and directory management is a fundamental skill. This chapter introduces some common commands that will allow you to create, copy, move, remove, and link files and directories.
mkdir
mkdir (Make Directory) builds a new folder wherever you tell it to, like making a new folder in data for inputs (data/in) or outputs (data/out)
mkdir data/in
mkdir data/outConfirm with tree -d (the -d is for directories):
tree data -d
# data
# โโโ in
# โโโ out
#
# 3 directoriescp
cp duplicates files or folders. The cp command is used to copy files or directories from one location to another. Imagine having a file (binary_data.tsv) on your root (.) directory that you want to copy to the /data/in folder; you could use cp to make a duplicate.
cp binary_data.tsv data/in/binary_data.tsvConfirm with tree
tree data/in
# data/in
# โโโ binary_data.tsv
#
# 1 directory, 1 filemv
mv, short for move, moves files or directories from one location to another. Weโll use it to move data/binary_data.tsv to data/out/binary_data.tsv:
# move file
mv data/in/binary_data.tsv data/out/binary_data.tsv Confirm move with tree:1
tree data -P *.tsv
# data
# โโโ in
# โโโ out
# โโโ binary_data.tsv
#
# 3 directories, 1 fileIt can also be used for renaming files.
# rename file
mv data/out/binary_data.tsv data/out/bin_dat.tsv # confirm rename
tree data/out
# data/out
# โโโ bin_dat.tsv
#
# 1 directory, 1 filemv is especially useful for organizing files and directories that are in the wrong place.
rm
The rm command stands for remove and is used to delete files or directories.
# remove doc folder
rm data/out
# rm: data/out: is a directoryBy default, it wonโt remove a directory without the -R or -r option.
# add option
rm -R data/outRecap
Given the principle that everything is a file in Linux, directories are treated as special types of files that contain references to other files and directories, facilitating the organization and management of data.
Understanding how to navigate, manipulate, and manage directories is essential for effective use of the Linux operating system.
The
-P *.tsvoption fortreetells it to look indatafor files or folders with a.tsvextension. Weโll cover wildcards and patterns in the ?sec-symbols-patterns chapter.โฉ๏ธAs quoted in Bioinformatics Data Skills: Reproducible and Robust Research with Open Source Tools (2015) by Vince Buffalo.โฉ๏ธ