Skip to content

Unix tools for common dev tasks

This guide highlights essential Unix utilities and debugger commands for everyday development workflows. Use it to quickly reference powerful command-line tricks and streamline common tasks.

man page

Terminal window
# Find and archive PNG images
$ find Pictures/ -name "*.png" -type f -print0 | xargs -0 tar -cvzf png.tar
# Find and delete directories named Pictures
$ find Downloads -name "Pictures" -type d -print0 | xargs -0 /bin/rm -v -rf "{}"

man page

Terminal window
# View all processes
$ ps axu
$ ps -A
# View all processes for a user
$ ps -u {USERNAME}
# View a process by PID
$ ps a -p {PID}
# Kill a process named some_name
$ ps aux | grep some_name | grep -v grep | awk '{print $2}' | xargs kill -9
# List all currently running processes
$ ps -ef
# List open file descriptors
$ ls -l /proc/pid/fd
# Show running JVM instances
$ ps -ef | grep java
# View a process using a custom output format
$ ps -L -o pid,tid,state,time,%cpu,%mem,start_time 10427

wiki page

basic guide

Terminal window
# Generate an RSA private key
$ openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out pkey.pem
# View the private key
$ openssl pkey -in pkey.pem -text
# Generate a public key from a private key
$ openssl rsa -pubout -in pkey.pem -outform PEM -out pubkey.pem
# View the public key
$ openssl rsa -pubin -in pubkey.pem -text
# View certificates (PEM or CRT file)
$ openssl x509 -in aaa_cert.pem -noout -text
$ openssl x509 -in ca.crt -noout -text
# Create a CA certificate from a private key
$ openssl req -new -x509 -sha256 -key pkey.pem -out ca.crt -days 3650
# Create a CSR for a certificate authority
$ openssl req -new -key client_private.key -out client_request.csr
# Issue a new certificate from a CSR
$ openssl x509 -req -in client_request.csr -CA ca.crt -CAkey ca_private.key -out client.crt -days 365 -sha256

man page

Terminal window
# Show symbols
# List symbols from an object or executable file
$ nm -g -C --defined-only *.o
$ nm a.out | c++filt -t | less
$ nm -a a.out | c++filt
# List symbols in a library file
$ nm -gDC lib_name.so | grep --color symbol_name

Tell LLDB where the source code is located. The debugger uses it for all matching references.

Terminal window
$ (lldb) settings set target.source-map /build/dir/path /my/local/source/path

List all shared libraries associated with the current target.

Terminal window
$ (lldb) image list

Find a specific shared library associated with the current target.

Terminal window
$ (lldb) image list libmylib.so

Check whether a shared library has debug symbols for a specific file.

  1. Find the location of your LLVM toolchain.
  1. Find the location of the .so library you want to check.

Run the command and specify the file name you want to inspect.

Set breakpoints:

Terminal window
$ (lldb) breakpoint set -n function_name
$ (lldb) breakpoint set -f file_name.cpp -l line_number
$ (lldb) breakpoint list

Symbol lookup:

Terminal window
$ (lldb) image lookup -vn symbol

Dump all threads:

Terminal window
$ (lldb) bt all

Log thread frames:

Terminal window
$ (lldb) thread backtrace

Inspect simple variables:

Terminal window
$ (lldb) p
$ (lldb) po

man page

Terminal window
# Output only the first field from each line
$ cat test.txt | awk '{print $1}'

man page

POST request:

Terminal window
$ curl -X POST --form "file=@1.txt" -v http://example.com

POST request with authorization:

Terminal window
$ curl -X POST -H "Authorization: Bearer <token>" http://example.com -v -d 'post_body'

Kerberos authentication:

Terminal window
$ curl -v -k --negotiate -u user_name:pass http://example.com

NTLM authentication:

Terminal window
$ curl -v -k --ntlm -u user_name:pass http://example.com

Download a file:

Terminal window
curl -o filename.txt https://reqbin.com/echo

Connect with proxy:

Terminal window
$ curl -x localhost:8888 -k http://example.com

CPU usage:

Terminal window
adb shell dumpsys cpuinfo
adb shell "top -n 1"

Activity stack:

Terminal window
adb shell dumpsys activity top | grep --color -A 4 "ACTIVITY"

APK locations:

Internal storage: /data/app/app.package.name-t2tip43AexOplAoWlN1KCQ==/base.apk

System storage: /data/data/app.package.name

External storage: /Android/data/app.package.name

Unlock bootloader (Settings -> OEM unlocking -> ON):

Terminal window
adb reboot bootloader
fastboot oem lock
fastboot oem unlock
fastboot reboot

Install APK in workspace:

Terminal window
adb shell pm list users
adb install -r --user 18 internal-debug-work.apk

CPU ABI check:

Terminal window
adb shell getprop ro.product.cpu.abi

Sign APK:

Terminal window
/Library/Android/sdk/build-tools/30.0.0/apksigner sign --ks /Desktop/key AppKinetics-App-debug.apk

Uninstall a package:

Terminal window
adb uninstall <package-name>

List packages:

Terminal window
adb shell pm list packages

Current activity:

Terminal window
adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'

Grant permissions:

Terminal window
adb shell pm grant [package name] [permission name]
adb shell pm grant uk.co.richyhbm.monochromatic android.permission.WRITE_SECURE_SETTINGS

Text input:

Terminal window
adb shell input text

Force-stop app:

Terminal window
adb shell am force-stop <PACKAGE>

Current API version:

Terminal window
adb shell getprop | grep ro.build.version

Launch activity:

Terminal window
adb shell am start -n yourpackagename/.activityname

Device rotation:

Terminal window
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0

Reboot device:

Terminal window
adb reboot

Rotation:

Terminal window
adb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0

Key event:

Terminal window
adb shell input keyevent 82

Enable apps from unknown sources:

Terminal window
adb shell settings put global verifier_verify_adb_installs 0

Uninstall app from work profile:

List users:

Terminal window
adb shell pm list users

Find app:

Terminal window
adb shell pm list packages --user 10 | grep "rim"

Remove work profile:

Settings -> Accounts -> Remove work profile

App verification:

Terminal window
adb shell settings put global verifier_verify_adb_installs 0

man page

Case insensitive search

Terminal window
$ find . -iname "main*" -type f

Search by creation time

Terminal window
$ find . -type f -mmin -10 # Find files created less than 10 minutes ago
$ find . -type f -mmin +1 -mmin -10 # Find files created more than 1 minute and less than 10 minutes ago
$ find . -type f -mtime -10 # Find files created less than 1 day ago

Search files by size

Terminal window
$ find . -size +5G # Find files larger than 5 GB
$ find . -size +5M # Find files larger than 5 MB
$ find . -size +5k # Find files larger than 5 KB

Search files only in the current directory

Terminal window
$ find . -name "*.jpg" -type f -maxdepth 1

Modify file permissions using find command

Terminal window
$ find sample_dir/ -exec chown name1:name2 {} +
$ find sample_dir/ -type d -exec chown 775 {} +

Delete files using find command

Terminal window
$ find . -name "*.jpg" -type f -exec rm {} +

Search for permissions

Terminal window
$ find . -perm 775

Search for files ending with .java or .kt extension

Terminal window
$ find . -type f \( -name "*.java" -o -name "*.kt" \)

Find a file named “needle” and stop searching once found

Terminal window
$ find / -name needle -print -quit

Find all files without permission 777

Terminal window
$ find / -type f ! -perm 777

Find all empty directories

Terminal window
$ find . -type d -empty
Terminal window
$ find /tmp -type d -empty

optimization

Static vs dynamic libraries

Help

Terminal window
$ g++ --help

Measure compilation time

Terminal window
$ /usr/bin/time g++ test.cpp -std=c++17

Warning options

Terminal window
-ansi -pedantic -Wall -Wextra -Weffc++

Git visual tool -> gitk

Git merge tool -> git mergetool

Git diff tool -> git difftool

Install p4merger

Install 2 p4merger

Detach (move) subdirectory into separate a Git repository

DELETE REMOTE BRANCH

Terminal window
git push origin --delete my_remote_branch

PATCH

Terminal window
git format-patch -1 9921ac0990fc1afc0eb871a15554840aa724f894 -o patches

SQUASH

Terminal window
git rebase -i HEAD~N

CONFIG GLOBAL VARIABLES

Terminal window
git config --global user.name ""
git config --global user.email ""
git config --list

GIT HELP

Terminal window
git help <verb>

GIT INITIALIZE EMPTY REPO

Terminal window
git init

TO STOP TRACK THE REPO JUST REMOVE .git DIRECTORY

Terminal window
rm -rf .git

ADD ALL CURRENTLY UNTRACHED OR CHANGED FILES TO STAGE AREA

Terminal window
git add -A
git add -A my_dir/ - add modifiesd and deleted files
git add --no-all my_dir/ - add only modified files
git add -u (updated) - not add untracked files
git add .

GREATE BRANCH

Terminal window
git branch <branch-name>
git checkout <branch-name>

REMOVE FILE FROM A STAGE AREA

Terminal window
git reset <file>
git reset

CLONE REPO

Terminal window
git clone <url> <where to clone>

VIEW REMOTE REPO INFO

Terminal window
git remote -v

VIEW LOCAL AND REMOTE BRANCHES

Terminal window
git branch -a

PUSH BRANCH TO REMOTE REPO

Terminal window
git push -u <remote-repo> <local-branch>

MERGE BRANCH INTO MASTER

Terminal window
git merge <branch-name>
git pull <remote-repo-name> <branch-name>
git push <remote-repo-name> <branch-name>

DELETE BRANCH LOCALY OR REMOTLY

Terminal window
git branch -d <branch-name>
git push origin --delete <branch-name>

SHOW FILES WHICH WAS MEANT TO COMMIT

Terminal window
git log --stat

CHERRY-PICK

Terminal window
git cherry-pick <hash>

RESET COMMIT

Terminal window
git reset --soft <hash>
git reset [mixed reset]
git reset --hard <hash>

GET RID OFF UNTRACKED FILES/DIRECTORIES

Terminal window
git clean -df

SHOW your commits in the order when you last reference them

Terminal window
git reflog

STASH CRETATE STASH

Terminal window
git stash save "message"
git stash push -m "message"
git stash list
git stash apply <id>
git stash pop
git stash drop <id>
git stash clear

REVERT COMMIT WITHOUT CHANGING HISTORY

Terminal window
git revert [git-hash-commit]

Revert changes

Terminal window
git checkout — <file_name>

tutorial

Special charactes:

* - matches any charactes

? - macthes one character

[] - matches single or range of characters

! - not operator

  1. Run test
Terminal window
./gradlew --console plain connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.class#test_example
  1. App build & install tasks
Terminal window
./gradlew installDebug
./gradlew assembleDebug
./gradlew assembleRelease

With flags

Terminal window
./gradlew -PAPP_ABI=armeabi-v7a app:assembleDebug
  1. Execute single build script
Terminal window
./gradlew -b /path/to/some_script.gradle someTask
  1. Dependency Insight
Terminal window
./gradlew -q dependencyInsight --dependency artifactGroupName
  1. Gradle dependencies check
Terminal window
./gradlew -q app:dependencies
./gradlew app:resolvableConfigurations

man page

Simple search in file

Terminal window
$ grep -inw "John Williams" note.txt

Search in current directory including all text files

Terminal window
$ grep -inw -C 2 "John Williams" ./*.txt

Search in curent directory and its subdirectories

Terminal window
$ grep -inwr -C 2 "John Williams" .

Show file names which contain a match

Terminal window
$ grep -ilwr -C 2 "John Williams" .

Show file names which contain a match with number of macthes

Terminal window
$ grep -icwr -C 2 "John Williams" .

Invert match show lines which DOEAN’T contain a match word

Terminal window
$ grep -ivwr "John Williams" .

Show lines 5 which contains a word ‘git’ in a history

Terminal window
history | grep -m 5 git
history | grep --max-count=5 git

Show only mathing word and don’t print full line

Terminal window
grep -wiro -C 2 "Tom" .

Search for a word in .txt files

Terminal window
grep -iwro --include=\*.txt "Tom"

Search for a word in .txt and .cpp files

Terminal window
grep -iwro --include=\*.{txt,cpp} "Tom"

Search for a word in .txt and .cpp files and exclude dir

Terminal window
grep -iwro --include=\*.{txt,cpp} --exclude-dir=build "Tom"
grep -iwro --include=\*.{txt,cpp} --exclude-dir={build, temp} "Tom"

Find a line which contian vivek or raj word (OR option)

Terminal window
grep -E 'vivek|raj' temp.txt

All the lines that contain both “Dev” and “Tech” in it (in the same order (AND option)

Terminal window
grep -E 'Dev.*Tech' employee.txt

Find only line which begging with vivek word

Terminal window
grep ^vivek /etc/passwd

Find only line which ending with vivek word

Terminal window
grep vivek$ /etc/passwd

man page

View file in hex format

Terminal window
cat file.txt | hexdump -C

Install certificates for Java keystore (JAVA 8)

Terminal window
sudo $JAVA_HOME/bin/keytool -import -alias root_CA1 -keystore $JAVA_HOME/jre/lib/security/cacerts -file $downloaded_cert_file
sudo $JAVA_HOME/bin/keytool -importcert -file <cert> -cacerts -keypass changeit -storepass changeit -noprompt -alias <alias>

Default password for keystore: changeit

Java 11/17

Terminal window
$ ./bin/keytool -importcert -file <cert> -cacerts -keypass changeit -storepass changeit -noprompt -alias <alias>
$ sudo ./bin/keytool -importcert -file ~/Downloads/Cert.crt -keypass changeit -storepass changeit -keystore ./lib/security/cacerts -alias root_CA1

Where is a random uniq name for this cert in the java cert storage

Generate JNI header file from java file

Terminal window
$ javac -h . ClassName.java

Get certificate signing hash from key store

Terminal window
$ keytool -list -v -keystore NAME_OF_KEYSTORE -alias KEY_ALIAS

doc

Disassample a class file

Terminal window
$ javap -v -p -s -sysinfo -constants <file name>.class