13. Quick command reference¶
13.1. Shell commands¶
As we have discussed elsewhere, there is one fundamental aspect of using the command line that you must never forget. It is perhaps the single most powerful method available to save time. That method is…
tab-complete
Tab-complete can be used to auto-complete commands, directory names, and file names. If you are not sure whether your file is named results_QC.txt or results_qc.txt then on the command line you can simply type results and then tab, and the computer will auto-complete the name (assuming there is a file or directory or command that begins with results).
13.1.2. Peek inside files¶
# Quickly show content of a file "temp.txt"
# exist the view with "q", navigate line up and
# down with "k" and "j" and "spacebar"
less temp.text
# Show the first ten lines of a file "temp.txt"
head temp.txt
# Show the last ten lines of a file "temp.txt"
tail temp.txt
13.1.3. Moving and copying¶
# Copy a file
cp myfile.txt mynewfile.txt
# Copy a directory
cp -r mydir mynewdir
# Rename a file
mv myfile.txt renamed.txt
# Move a file
mv myfile.txt newplace/
# Make a new directory
mkdir mydir
13.1.4. Deleting¶
# Delete a file
rm myfile.txt
# Delete a directory
rmdir mydir
# Delete a directory with thigns in it (*careful!*)
rm -r mydir
13.1.5. For when you forget¶
# Where in the directory tree am I?
pwd
# I don't know what a command does
man unknown_command
# I can't find my file but I know
# the file is called "pattern"-something
find . -name "pattern"
# What was that command I used ten minutes ago?
history
# I used a command ten minutes ago I can't
# remember but it's something like "pattern"
history | grep "pattern"
# Find a line in a file that has a certain pattern
grep "pattern" myfile.txt
13.2. Conda¶
# List all packages installed
conda list [-n env]
# List environments
conda env list
# Create a new environment
conda create -n [env-name] package [package1-name package2-name ...]
# Activate an environment
conda activate [name]
# Deavtivate env
conda deactivate