Skip to content

Instantly share code, notes, and snippets.

@wildlarva
Last active August 20, 2023 02:09
Show Gist options
  • Save wildlarva/e476b549a54035524bed84bda77ec251 to your computer and use it in GitHub Desktop.
Save wildlarva/e476b549a54035524bed84bda77ec251 to your computer and use it in GitHub Desktop.
Useful commands

Useful commands

utils

file

tree

list contents of directories in a tree-like format

ex. tree -d -L3

list contents of directories. it only displays directories. the display depth is 3.

basename

get base name of path

ex. basename /home/wildlarva/mytext.txt
=> mytext.txt

ex. basename /home/wildlarva/mytext.txt .txt
=> mytext

dirname

get directory of path

ex. dirname /home/wildlarva/mytext.txt
=> /home/wildlarva

readlink

display value of a symbolic link it can be also used for displaying absolute path

ex. readlink -f somefile

output absolute path of somefile

namei

trace a pathname until a terminal point is found

ex. namei ~/Practices/C/hello/a.exe

namei outputs results like below

f: /home/wildlarva/Practices/C/hello/a.exe
 d /
 d home
 d wildlarva
 l Practices -> /cygdrive/d/Practices/
   d /
   d cygdrive
   d d
   d Practices
 d C
 d hello
 - a.exe

mmv

rename multiple files

ex. mmv "*.txt" "#1.csv"

change extension of all .txt files in current directory to .csv.

lsof

list open files

ex. lsof -c zsh

list open files opened by zsh.

iotop

top-like I/O monitor

terminal

clear/reset

clear screen

text/pipe

cut

get some sections from each line of files

ex. cut /etc/group -d ':' -f1,3

get group names and ids of /etc/group

xargs

build and execute command lines from standard input TODO

tail

output the last part of files

ex. tail -f somefile

output appended data as the file grows.

sort

sort lines of text files

ex. sort -nk3 somefile

sort lines of somefile (compare field 3 as numeric value)

uniq

omit repeated lines

ex. sort -nk1 somefile | uniq

omit repeated lines of somefile

tee

output stdin to both of files and stdout

seq

print a sequence of numbers

ex. seq 14

print 1..14

ex. seq 20 10 100

print 20,30,40,..,100

wc

print line, word, byte counts

ex. wc -l filea fileb

print line counts of filea and fileb

date/time/calendar

time

performance util

ex. time ls

output ls execution time

date

print date

ex. date +%Y%m%d

print text including year, month and day

user/system information

uname

print system information

ex. uname -a

print all information

ex. uname -m

print architecture name (same as arch)

ex. uname -n

print host name (same as hostname)

devel

binary

readelf

displays information about elf files

ex. readelf -s

show symbol table

ex. readelf -S

show section headers

ex. readelf -l

show segments

ex. readelf -h

show file header

objdump

displays information from object files

ex. objdump -Srl someprg

show assembly and relocation information

nm

list symbols from object files TODO:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment