Useful Linux Commands for AI Development Series #2 (Intermediate)

Image not Found

In Series #1 (Basic) , we have walked through some useful commands for topics such as File System Basics, File System Permission & Ownership, SSH (Remote Control), and Monitor System Loads (CPU, GPU, Memory). Let’s walk through more in this article.


There are two types of links: hard link & symbolic link. Hard link refers that users may create multiple names for a linked file. Whereas, software only allows the user to create one particular link, which directly points to another directory that differs from the original directory. This technique is frequently used in linking the default environment packages such as OpenCV library to a virtual environment library.

On Unix-like operating systems, the ln command creates links between files, associating file names with file data. More info here .

 1# Syntax:
 2# ln [option] [original-file] [target-file-or-folder]
 3# Parameters:
 4# -b delete,overwrite the existing links
 5# -d allow users to make hard link
 6# -f force execute
 7# -i interchangeable mode, if the file already exists, then asks if users want to overwrite
 8# -s symbolic link
 9# -v show the process
10$ ln -s path/[original-file] path/[target-file-or-folder]

Screen

The screen application is very useful if you are dealing with multiple programs from a command-line interface and for separating programs from the terminal shell. It also allows you to share your sessions with other users and detach/attach terminal sessions.

Clear current screen

1Ctrl + L

Create a new screen

1# Create a new screen session
2$ screen -S screen_name

List all available screen sessions

1# List the available screen sessions
2$ screen -list

Reatttach to a specific screen session

1# Reattach to this screen session
2$ screen -r screen_name

Kill (Terminate) a screen session

1# Kill a screen session
2$ screen -S screen_name -X quit

Python pip installation and management

pip is a package manager for Python packages, or modules if you like.

Install pip

1$ sudo apt install python3-pip
2$ sudo -H pip3 install --upgrade pip

Install python packages

1$ pip install package-name

List all installed packages

1$ pip list

Check if a packages has been installed

1$ pip show package-name

Show python path and pip path

1$ which python
2$ which pip

Git Commands

Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.

Git Config

1# Set up the config file for furture useage
2$ git config --global user.name Your Name
3$ git config --global user.email email@example.com
4# Note: --global refers that the config file will be applied to all the repos on your device.

Add private key to Git

1$ ssh-keygen -t rsa -C email@example.com
2# Log in to your Github page, open up Account Settings >> SSH and GPG keys >> Add SSH keys,
3# Paste your the content inside your id_rsa.pub file to the block
4# Give it a title

Upload your repo to Github

 1# Initialize a repo
 2$ git init
 3
 4# Add a file to the repo
 5$ git add filename.ext
 6# Add all files to the repo
 7$ git add *
 8#OR
 9$ git add --all
10
11# Commit changes
12$ git commit -am 'custom-msg'
13
14# Build a remote connection
15$ git remote add origin https://github.com/username.git
16
17# Remove the connection
18$ git remote rm origin
19
20# Sync the local repo to Github (Cloud Server)
21$ git push origin master
22# you may change master with your custom branch
23
24# Check repo status
25$ git status

Download a repo from Github

1$ git clone https://github.com/username.git
2# If you want to rename the repository, you may do
3$ git clone https://github.com/username.git new_repo_name

Get updates from a repo (Assume one or more people working on the same repo)

1# Get updates of the repo from your contributor
2$ git pull

If you have already walked through all the commands above, let’s move forward to the advanced commands tutorial at Series #3 (Advanced) . Happy Coding !


You May Also Like