Mastering WSL Flashcards
(25 cards)
What command will print the working directory?
pwd
What command is needed to list a directory’s content?
ls
How do I get a detailed list of a directory’s contents?
ls -l
What command will show hidden files in a directory?
ls -a
What command will get you instantly to the home directory?
cd ~
What command will let you make a new directory?
mkdir name
What command will create an empty file?
touch file_name
Examples
touch notes.txt # creates notes.txt or updates its timestamp
touch a.txt b.txt c.txt # creates multiple files
What command will let you move or rename a file?
mv old_filename new_filename
For example, suppose you have a file called results.dat and you want to rename it to final_results.dat:
mv results.dat final_results.dat
To move the file you can use:
mv myfile.txt /mnt/c/Users/bryan/Desktop/renamed_file.txt
How do you delete a file?
rm file_name
Examples:
rm mydata.txt # deletes a single file
rm *.o # deletes all files ending in .o
rm file1 file2 file3 # deletes multiple files at once
Flags:
-f : force (no prompts, even if the file is write-protected).
rm -f filename
-i : interactive (asks before deleting each file)
rm -i filename
Note: The rm does not place files in the recycle bin, it permanently deletes them.
How do you delete a directory and its contents?
- If the directory is empty:
rmdir dirname
- If the directory contains files/subdirectories:
rm -r dirname
-r = recursive (deletes contents and then the directory itself)
Common Options:
rm -rf dirname
-f = force (no confirmation prompts)
Use with care! This will delete everything inside the directory, no questions asked
Examples:
rmdir logs/ # removes empty ‘logs’ directory
rm -r temp_data/ # removes ‘temp_data’ and all its contents
rm -rf /mnt/c/Users/bryan/tmp # force-deletes ‘tmp’ in a mounted Windows path
How do you view (but not edit) a file’s contents from the wsl terminal?
cat file_name
Extra notes:
Short for “concatenate”
Original purpose: join multiple files and output them
cat file1.txt file2.txt > merged.txt
You can also use cat to append to an existing file:
cat notes.txt»_space; log.txt
How do you edit files from within a wsl terminal?
nano file_name
How do you display your username in wsl?
whoami
How do you show the computer’s system information?
uname -a
What command will refresh package lists?
sudo apt update
What’s the difference between sudo apt update and sudo apt upgrade?
sudo apt update: Refreshes package lists (checks what’s available)
sudo apt upgrade: Installs available updates for installed packages (no removals).
Use together:sudo apt update && sudo apt upgrade for regular system updates.
For more aggressive updates (with adds/removals), use: sudo apt full-upgrade.
What commands will install and remove specific packages?
> sudo apt install package_name
> sudo apt remove package_name
How do you search for a specific file?
Use the find function. The basic usage to find a Fortran program is
find /path/to/search -type f -name “filename.ext”
Suppose you want to search for main.f90 somewhere in your ~/projects/ folder:
find ~/projects -type f -name “main.f90”
If you don’t know the full name (but part of it):
find ~/projects -type f -iname “main”
-iname makes the search case-insensitive.
* is a wildcard.
To search multiple directories you can list multiple search roots:
find ~/dir1 ~/dir2 ~/dir3 -type f -name “target_file.txt”
What are some useful gfortran compiler flags.
-Wall – Show all warnings (useful for debugging).
-O3 – Optimize for speed.
-g – Include debugging information.
-fcheck=all – Enable runtime checks (like array bounds).
-march=native (optimizes compiled binaries based on host machine architecture)
-fopenmp – Enable OpenMP for parallel computing.
How do you compile a FORTRAN program with debuging symbols?
gfortran -g program.f90 -o program
What are the different types of Linux shells?
- Bash (bourne again shell - most popular, usually the default.)
- Zsh (Z shell - extended version of bash with more plugins and themes)
- Ksh (Korn Shell - good for scripting)
- Fish (Friendly interactive shell)
From a wsl terminal, what is the command that lets you know what type of shell you are running?
echo $0
or
echo $SHELL
What is the purpose of the $ when used with “echo?”
In Bash (and most shells), the $ symbol is used to access the value of a variable
Example:
greeting=”Hello”
name=”Bryan”
(No spaces around = sign)
echo “$greeting, $name!”
Will output:
Hello, Bryan!
—————————————
Extra notes.
In scripts, you can also do
filename=”report”
echo “Saving to ${filename}.txt”
Braces ({}) help disambiguate when appending text directly to a variable.
What are some of the uses of the command “echo?”
Basic echo usage
echo “Hello world”
This prints:
Hello world
⸻
Writing to a file with >
echo “Line of text” > file.txt
• Creates the file if it doesn’t exist. • Overwrites the file if it does exist.
Example:
echo “First line” > notes.txt
Now notes.txt contains just:
First line
⸻
Appending to a file with»_space;
echo “Another line”»_space; file.txt
• Adds to the end of the file instead of overwriting.
Example:
echo “Second line”»_space; notes.txt
Now notes.txt contains:
First line
Second line
⸻
Including variables
name=”Bryan”
echo “Hello, $name!” > greeting.txt
File will contain:
Hello, Bryan!
⸻
Special formatting
• Add -n to suppress newline:
echo -n “No newline”
• Use \n, \t with -e:
echo -e “Line 1\nLine 2”