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.
# 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 "{}"# 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 10427openssl
Section titled âopensslâ# 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# 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_nameMac C/C++ Debugger
Section titled âMac C/C++ DebuggerâTell LLDB where the source code is located. The debugger uses it for all matching references.
$ (lldb) settings set target.source-map /build/dir/path /my/local/source/pathList all shared libraries associated with the current target.
$ (lldb) image listFind a specific shared library associated with the current target.
$ (lldb) image list libmylib.soCheck whether a shared library has debug symbols for a specific file.
- Find the location of your LLVM toolchain.
- 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:
$ (lldb) breakpoint set -n function_name$ (lldb) breakpoint set -f file_name.cpp -l line_number
$ (lldb) breakpoint listSymbol lookup:
$ (lldb) image lookup -vn symbolDump all threads:
$ (lldb) bt allLog thread frames:
$ (lldb) thread backtraceInspect simple variables:
$ (lldb) p$ (lldb) po# Output only the first field from each line$ cat test.txt | awk '{print $1}'POST request:
$ curl -X POST --form "file=@1.txt" -v http://example.comPOST request with authorization:
$ curl -X POST -H "Authorization: Bearer <token>" http://example.com -v -d 'post_body'Kerberos authentication:
$ curl -v -k --negotiate -u user_name:pass http://example.comNTLM authentication:
$ curl -v -k --ntlm -u user_name:pass http://example.comDownload a file:
curl -o filename.txt https://reqbin.com/echoConnect with proxy:
$ curl -x localhost:8888 -k http://example.comADB (Android debugging tool)
Section titled âADB (Android debugging tool)âCPU usage:
adb shell dumpsys cpuinfoadb shell "top -n 1"Activity stack:
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):
adb reboot bootloaderfastboot oem lockfastboot oem unlockfastboot rebootInstall APK in workspace:
adb shell pm list usersadb install -r --user 18 internal-debug-work.apkCPU ABI check:
adb shell getprop ro.product.cpu.abiSign APK:
/Library/Android/sdk/build-tools/30.0.0/apksigner sign --ks /Desktop/key AppKinetics-App-debug.apkUninstall a package:
adb uninstall <package-name>List packages:
adb shell pm list packagesCurrent activity:
adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'Grant permissions:
adb shell pm grant [package name] [permission name]adb shell pm grant uk.co.richyhbm.monochromatic android.permission.WRITE_SECURE_SETTINGSText input:
adb shell input textForce-stop app:
adb shell am force-stop <PACKAGE>Current API version:
adb shell getprop | grep ro.build.versionLaunch activity:
adb shell am start -n yourpackagename/.activitynameDevice rotation:
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0Reboot device:
adb rebootRotation:
adb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0Key event:
adb shell input keyevent 82Enable apps from unknown sources:
adb shell settings put global verifier_verify_adb_installs 0Uninstall app from work profile:
List users:
adb shell pm list usersFind app:
adb shell pm list packages --user 10 | grep "rim"Remove work profile:
Settings -> Accounts -> Remove work profile
App verification:
adb shell settings put global verifier_verify_adb_installs 0Case insensitive search
$ find . -iname "main*" -type fSearch by creation time
$ 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 agoSearch files by size
$ 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 KBSearch files only in the current directory
$ find . -name "*.jpg" -type f -maxdepth 1Modify file permissions using find command
$ find sample_dir/ -exec chown name1:name2 {} +$ find sample_dir/ -type d -exec chown 775 {} +Delete files using find command
$ find . -name "*.jpg" -type f -exec rm {} +Search for permissions
$ find . -perm 775Search for files ending with .java or .kt extension
$ find . -type f \( -name "*.java" -o -name "*.kt" \)Find a file named âneedleâ and stop searching once found
$ find / -name needle -print -quitFind all files without permission 777
$ find / -type f ! -perm 777Find all empty directories
$ find . -type d -empty$ find /tmp -type d -emptyGCC (C/C++ compiler)
Section titled âGCC (C/C++ compiler)âHelp
$ g++ --helpMeasure compilation time
$ /usr/bin/time g++ test.cpp -std=c++17Warning options
-ansi -pedantic -Wall -Wextra -Weffc++Git visual tool -> gitk
Git merge tool -> git mergetool
Git diff tool -> git difftool
Detach (move) subdirectory into separate a Git repository
DELETE REMOTE BRANCH
git push origin --delete my_remote_branchPATCH
git format-patch -1 9921ac0990fc1afc0eb871a15554840aa724f894 -o patchesSQUASH
git rebase -i HEAD~NCONFIG GLOBAL VARIABLES
git config --global user.name ""git config --global user.email ""git config --listGIT HELP
git help <verb>GIT INITIALIZE EMPTY REPO
git initTO STOP TRACK THE REPO JUST REMOVE .git DIRECTORY
rm -rf .gitADD ALL CURRENTLY UNTRACHED OR CHANGED FILES TO STAGE AREA
git add -Agit add -A my_dir/ - add modifiesd and deleted filesgit add --no-all my_dir/ - add only modified filesgit add -u (updated) - not add untracked filesgit add .GREATE BRANCH
git branch <branch-name>git checkout <branch-name>REMOVE FILE FROM A STAGE AREA
git reset <file>git resetCLONE REPO
git clone <url> <where to clone>VIEW REMOTE REPO INFO
git remote -vVIEW LOCAL AND REMOTE BRANCHES
git branch -aPUSH BRANCH TO REMOTE REPO
git push -u <remote-repo> <local-branch>MERGE BRANCH INTO MASTER
git merge <branch-name>
git pull <remote-repo-name> <branch-name>git push <remote-repo-name> <branch-name>DELETE BRANCH LOCALY OR REMOTLY
git branch -d <branch-name>git push origin --delete <branch-name>SHOW FILES WHICH WAS MEANT TO COMMIT
git log --statCHERRY-PICK
git cherry-pick <hash>RESET COMMIT
git reset --soft <hash>git reset [mixed reset]git reset --hard <hash>GET RID OFF UNTRACKED FILES/DIRECTORIES
git clean -dfSHOW your commits in the order when you last reference them
git reflogSTASH CRETATE STASH
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 clearREVERT COMMIT WITHOUT CHANGING HISTORY
git revert [git-hash-commit]Revert changes
git checkout â <file_name>Globbing
Section titled âGlobbingâSpecial charactes:
* - matches any charactes
? - macthes one character
[] - matches single or range of characters
! - not operator
- Run test
./gradlew --console plain connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.class#test_example- App build & install tasks
./gradlew installDebug./gradlew assembleDebug./gradlew assembleReleaseWith flags
./gradlew -PAPP_ABI=armeabi-v7a app:assembleDebug- Execute single build script
./gradlew -b /path/to/some_script.gradle someTask- Dependency Insight
./gradlew -q dependencyInsight --dependency artifactGroupName- Gradle dependencies check
./gradlew -q app:dependencies./gradlew app:resolvableConfigurationsSimple search in file
$ grep -inw "John Williams" note.txtSearch in current directory including all text files
$ grep -inw -C 2 "John Williams" ./*.txtSearch in curent directory and its subdirectories
$ grep -inwr -C 2 "John Williams" .Show file names which contain a match
$ grep -ilwr -C 2 "John Williams" .Show file names which contain a match with number of macthes
$ grep -icwr -C 2 "John Williams" .Invert match show lines which DOEANâT contain a match word
$ grep -ivwr "John Williams" .Show lines 5 which contains a word âgitâ in a history
history | grep -m 5 git
history | grep --max-count=5 gitShow only mathing word and donât print full line
grep -wiro -C 2 "Tom" .Search for a word in .txt files
grep -iwro --include=\*.txt "Tom"Search for a word in .txt and .cpp files
grep -iwro --include=\*.{txt,cpp} "Tom"Search for a word in .txt and .cpp files and exclude dir
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)
grep -E 'vivek|raj' temp.txtAll the lines that contain both âDevâ and âTechâ in it (in the same order (AND option)
grep -E 'Dev.*Tech' employee.txtFind only line which begging with vivek word
grep ^vivek /etc/passwdFind only line which ending with vivek word
grep vivek$ /etc/passwdhexdump
Section titled âhexdumpâView file in hex format
cat file.txt | hexdump -CInstall certificates for Java keystore (JAVA 8)
sudo $JAVA_HOME/bin/keytool -import -alias root_CA1 -keystore $JAVA_HOME/jre/lib/security/cacerts -file $downloaded_cert_filesudo $JAVA_HOME/bin/keytool -importcert -file <cert> -cacerts -keypass changeit -storepass changeit -noprompt -alias <alias>Default password for keystore: changeit
Java 11/17
$ ./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_CA1Where
Generate JNI header file from java file
$ javac -h . ClassName.javakeytool (Android tool for working with keystore)
Section titled âkeytool (Android tool for working with keystore)âGet certificate signing hash from key store
$ keytool -list -v -keystore NAME_OF_KEYSTORE -alias KEY_ALIASDisassample a class file
$ javap -v -p -s -sysinfo -constants <file name>.class