Skip to content

jlcasti9/Coding-Information

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

Useful Linux Commands and Tips


How to Transfer Files from Windows to Linux using SCP (Secure Copy Protocol)

  1. Open a terminal on your Linux machine.
  2. Copy a file from Windows to Linux:
    scp /path/to/local/file username@linux_host:/path/to/remote/directory
  • /path/to/local/file – path to the file on Windows
  • username – your Linux user
  • linux_host – IP or hostname of the Linux machine
  • /path/to/remote/directory – destination folder on Linux

Creating a Python Virtual Environment (venv) in Linux

  1. Open a terminal.

  2. Install the venv package (if needed):

    sudo apt install python3-venv
  3. Navigate to your project directory.

  4. Create the virtual environment:

    python3 -m venv myenv

    Change myenv to whatever name you like.

  5. Activate it:

    source myenv/bin/activate

How to create a requirements.txt file in Linux

  1. Open a terminal.

  2. Navigate to your project directory.

  3. Activate your virtual environment if you have one:

    source myenv/bin/activate

    Replace myenv with your virtual environment name.

  4. Run the following command to create a requirements.txt file:

    pip freeze > requirements.txt

    This will list all installed packages and their versions in the current environment.


How to install packages from requirements.txt in Linux

  1. Open a terminal.

  2. Navigate to your project directory.

  3. Activate your virtual environment if you have one:

    source myenv/bin/activate

    Replace myenv with your virtual environment name.

  4. Ensure you have a requirements.txt file in your project directory.

    If you don't have one, you can create it using the previous section's instructions.

  5. Run the following command:

    pip install -r requirements.txt

How to run a Python Script in Linux

  1. Open a terminal.

    Ensure you have activated your virtual environment if you are using one.

  2. Navigate to the directory containing your script.

  3. Run the script using Python 3:

    python3 script_name.py

    Replace script_name.py with the name of your Python script.


How to run a Python Script and keep it running in the background

  1. Open a terminal.

    Ensure you have activated your virtual environment if you are using one.

  2. Navigate to the directory containing your script.

  3. Run the script in the background:

    nohup python3 script_name.py &

    Replace script_name.py with your script's name.


How to see the output of a Python script running in the background

  1. Open a terminal.

  2. Navigate to the directory where you ran the script.

  3. Check the output file:

    cat nohup.out

    This file contains the output of your script.

  4. If you want to see the output in real-time, you can use:

    tail -f nohup.out

Finding a Process ID (PID) in Linux

  1. Open a terminal.

  2. List running processes:

    ps aux
  3. Locate your process and note its PID (second column).

  4. Or search directly:

    pgrep process_name

    Replace process_name with the process you’re looking for.


How to Kill a Process in Linux using PID

  1. Open a terminal.

  2. Use the kill command with the PID:

    kill PID

    Replace PID with the actual process ID.

Useful VSCode Shortcuts

  • Move Line Up/Down: Alt + Up/Down Arrow
  • Add multiple cursors: Ctrl + Alt + Click or Ctrl + Alt + Up/Down Arrow
  • Delete Line: Ctrl + Shift + K
  • Comment/Uncomment Line: Ctrl + /
  • Select current line: Ctrl + L
  • Navigate to a specific line: Ctrl + G
  • Go to Definition: F12
  • Select all occurrences of a operation: Ctrl + F2
  • Trim Trailing Whitespace: Ctrl + K then Ctrl + X
  • Copy Line Up/Down: Shift + Alt + Up/Down Arrow
  • Open Command Palette: Ctrl + Shift + P
  • Open Markdown Preview: Ctrl + Shift + V

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published