Some Useful Commands — Linux, Python, Pip

Aakash Goel
2 min readDec 3, 2021

Search specific text in current : <grep -RilE “text1|text2”>

Name of Operating System: <uname -a> and <hostnamectl>

Output of “uname -a”
Output of “hostnamectl”

Basic ls command

* ls -ltr - reverse output order, which is particularly useful when sorting by date* ls -lS - sort by file size* ls -1 | wc -l - Return No of files

Check difference in two directory: <diff -q dir1/ dir2/>

Command to copy directory structure without content:

source=/home/folder1/target=/home/folder2/rsync -av -f"+ */" -f"- *" "$source" "$target"

Host Jupyter Notebook on Server (to make it accessible by other team members):

nohup jupyter notebook --ip=a.b.c.d --port=8089 --Notebook.token=password > /home/temp/jupyter_nb.log &

Replace Value in multiple file

## Replace "aakash" with "aakash_goel"
sed -i "s/aakash/aakash_goel/g" *.txt

Top Command

* Use Top command and Press 1 to see CPU Usage

PS Command

## Check Process Usage by CPU, Memory
ps -eo pcpu,pid,user,args | sort -k 1 -r | head -3
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -3
## Get Process ID (
ps -aux | grep python | grep abc

Nohup Command

## Run Python Program
nohup python > temp_nohup.log 2>&1 &
## Run and print in .log file using -u
nohup python -u > model.log &
## Run Shell File
nohup sh > temp_nohup.log 2>&1 &

Pip Command

pip install --upgrade pip# Upgrade to a specific version
python -m pip install pip==18.1
## Version of pip
pip --version
## get requirements.txt
/datascience/user/env/bin/pip freeze > requirements.txt
## Install all packages in req.txt
pip install -r requirements.txt