Mastering WSL Flashcards

(25 cards)

1
Q

What command will print the working directory?

A

pwd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What command is needed to list a directory’s content?

A

ls

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do I get a detailed list of a directory’s contents?

A

ls -l

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What command will show hidden files in a directory?

A

ls -a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What command will get you instantly to the home directory?

A

cd ~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What command will let you make a new directory?

A

mkdir name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What command will create an empty file?

A

touch file_name

Examples

touch notes.txt # creates notes.txt or updates its timestamp
touch a.txt b.txt c.txt # creates multiple files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What command will let you move or rename a file?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you delete a file?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you delete a directory and its contents?

A
  1. If the directory is empty:

rmdir dirname

  1. 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you view (but not edit) a file’s contents from the wsl terminal?

A

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&raquo_space; log.txt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you edit files from within a wsl terminal?

A

nano file_name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you display your username in wsl?

A

whoami

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you show the computer’s system information?

A

uname -a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What command will refresh package lists?

A

sudo apt update

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What’s the difference between sudo apt update and sudo apt upgrade?

A

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.

17
Q

What commands will install and remove specific packages?

A

> sudo apt install package_name

> sudo apt remove package_name

18
Q

How do you search for a specific file?

A

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”

19
Q

What are some useful gfortran compiler flags.

A

-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.

20
Q

How do you compile a FORTRAN program with debuging symbols?

A

gfortran -g program.f90 -o program

21
Q

What are the different types of Linux shells?

A
  1. Bash (bourne again shell - most popular, usually the default.)
  2. Zsh (Z shell - extended version of bash with more plugins and themes)
  3. Ksh (Korn Shell - good for scripting)
  4. Fish (Friendly interactive shell)
22
Q

From a wsl terminal, what is the command that lets you know what type of shell you are running?

A

echo $0

or

echo $SHELL

23
Q

What is the purpose of the $ when used with “echo?”

A

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.

24
Q

What are some of the uses of the command “echo?”

A

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&raquo_space;

echo “Another line”&raquo_space; file.txt

•	Adds to the end of the file instead of overwriting.

Example:

echo “Second line”&raquo_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”

25
What is .bashrc?
.bashrc is a shell script that automatically runs every time you start a new interactive Bash terminal session (like when you open WSL). It is located in the home directory: ~/.bashrc To open or edit: nano ~/.bashrc You can put anything in .bashrc that you want to happen every time you start a shell, such as: 1. Setting environment variables export PATH=$PATH:~/mytools export EDITOR=nano 2. Creating aliases (shortcuts for commands): alias ll='ls -lah' alias gs='git status' After editing .bashrc, make changes take effect: source ~/.bashrc