- Create a screen :
screen -S SCREEN_NAME
- Detach (getting out of the screen) : Press ctrl+A & ctrl+D respectively
- Reattach (getting in the screen) :
screen -r SCREEN_NAME/ID
- List of screens with process id :
screen -ls
- Kill a screen with process id :
screen -X -S [PID] kill
-
for PID in `ps ax | grep 'grakn' | awk ' { print $1;}'`; do kill -9 $PID; done
-
or
sudo kill -9 $(sudo netstat -anp | awk '/ LISTEN / {if($4 ~ ":8080$") { gsub("/.*","",$7); print $7; exit } }')
sudo kill -9 $(sudo lsof -ti tcp:8080)
$ ps -a PID
$ ps -p PID -o comm=
- Open a file:
$ vim FILE_NAME
- Edit: press i
- Save: press esc, then type
:wqa
and press enter - Exit without saving any change: pres esc, then type
:q!
and press enter - Undo last change: press esc, press u respectively
- Copy to remote server:
scp -r FILE_OR_FOLDER_PATH USER@HOSTNAME_OR_IP:COPY_TO_DIRECTORY
- With password in single command:
Note: Install sshpass using the following command.
sshpass -p PASSWORD scp -r FILE_OR_FOLDER_PATH USER@HOSTNAME_OR_IP:COPY_TO_DIRECTORY
sudo apt-get install sshpass
-
ls | wc -l
-
for file in *.txt; do mv "$file" "en_${file}"; done
- Let's say the word is
git
^(?:(?!git).)*$
-
sudo apt install uni2ascii ascii2uni -a U file_ascii.json > file_unicode_char.json
-
sudo apt install python-demjson jsonlint-py -f file.json > file_pp.json
- From world:
sudo iptables -A PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-ports 8080
- From own machine:
sudo iptables -t nat -A OUTPUT -o lo -p tcp --dport 80 -j REDIRECT --to-port 8080
-
Note: For all occurances use double slash (//)first="My name is Sayef" replace="isn't" edited="${first/is/$replace}"
- Replace spaces (
_
) from alljpg
file name in a directoryfor file in *.jpg; do newfile="${file/ /_}"; mv "${file}" "${newfile}"; done
-
adduser sayef usermod -aG sudo sayef su - sayef passwd sayef
- Sort according to file creation time
convert $(find . -type f -print0 -name \*.png | xargs -0 stat -c "%y|%n" | sort | awk -F'|' '{print $2}') output.pdf
-
Filter file extension
from=1; extension=jpg; for i in $(find . -type f -print0 -name \*.$extension | xargs -0 stat -c "%y|%n" | sort | awk -F'|' '{print $2}'); do mv -i -- "$i" $(printf "%04d.$extension" "$from"); let from=from+1; done
-
Regardless of file extension (but keep original extension)
from=1; for i in $(find . -type f -print0 | xargs -0 stat -c "%y|%n" | sort | awk -F'|' '{print $2}'); do mv -i -- "$i" $(printf "%04d."${i##*.} "$from"); let from=from+1; done
- Given an input directory where each sub-directory is a unique class and contains files to represent that class
$1=INPUT_DIR $2=OUTPUT_DIR $3=PERCENTAGE count=1 total=$(ls -d $1/* | wc -l) for dir in "$1"/*; do if [ -d "$dir" ]; then echo -ne ">> Processing $count/$total ...\r" n=$[$[$(ls "$dir"/* | wc -l) * $3] / 100] if [ "$n" -ne "0" ]; then files=$(ls "$dir"/* | shuf -n $n) dir=$2/$(basename $dir) mkdir -p $dir mv $files $dir fi count=$[$count+1] fi done
- Rename if already same named file exits
find source_dir/ -type f -exec cp --backup=numbered -- {} target/ \; find source_dir/ -name ".jpg" -exec cp --backup=numbered -- {} target/ \;
```
rsync -r --info=progress2 -e 'ssh -p XX' source/folder user@host:~/
```
```
#!/bin/bash
TARGET=/mnt/d/output/
HOST=user@host
PORT=xxxx
SOURCE=/root/output/
# -a : archive
# -h : human readable
# -r : recursive
# -v : verbose
# --no-perms : ignore keeping original permissions
# --no-owner : ignore keeping original owner
# --no-group : ignore keeping original group
# --no-times : ignore keeping original creation/modification time
# --info:progress2 :
# --info=name0 : progress information in one line (instead for all files individually)
# --no-inc-recursive : ignore incremental file lookup
# --update : update if file already exists
# --remove-source-files : remove source files after syncing
# --files-from : define files at once
rsync \
-ahrv \
--no-perms \
--no-owner \
--no-group \
--no-times \
--info=progress2 \
--info=name0 \
--no-inc-recursive \
--update \
--remove-source-files \
--files-from=<(ssh -q -p $PORT $HOST "find $SOURCE -name *.txt -type f -mmin +30 -exec realpath --relative-to=$SOURCE '{}' \;") \
-e "ssh -q -p $PORT" \
$HOST:$SOURCE \
$TARGET
```
- Assuming prefixes are 000, 001 up to 120.
SOURCE=/mnt/d/flat/ TARGET=/mnt/d/dirs/ for PREFIX in $(seq -f "%03g" 0 120) do mkdir -p ${TARGET}/${PREFIX} find $SOURCE -maxdepth 1 -name $PREFIX-*.txt -type f -exec mv {} $TARGET/$PREFIX \; done
for file in *.png; do mv "$file" "${file/_h.png/_half.png}"; done