Skip to content

Instantly share code, notes, and snippets.

@wildlarva
Last active July 2, 2021 04:57
Show Gist options
  • Save wildlarva/92dc0739642862794edb1c24641e08cc to your computer and use it in GitHub Desktop.
Save wildlarva/92dc0739642862794edb1c24641e08cc to your computer and use it in GitHub Desktop.
Rarely-used useful commands

Rarely used commands

utils

amusement

banner

print ascii art of text

ex. banner -c x text

print "text" with x characters like below

 xxxxxxx
 x  x  x                   x
    x                      x
    x     xxxxx  xxx xxx  xxxx
    x    x     x  x   x    x
    x    xxxxxxx   xxx     x
    x    x         xxx     x
    x    x     x  x   x    x  x
   xxx    xxxxx  xxx xxx    xx

diff

cmp

compare 2 files byte by byte

ex. cmp filea fileb

colordiff

colored version of diff tool TODO:

file

split

split a file into pieces

ex. split -b 3 original_file

split original_file into xaa, xab, xac, ... and cat makes pieces into a file

cat * > combined_file

csplit

split a file into pieces determined by patterns

ex. split original_file '/[0-9]*0:/' '{*}'

split a file into pieces by line number: line starts with "00:" ~ "09:" -> xx00 "10:" ~ "19:" -> xx01 "20:" ~ "29:" -> xx02 ... cat can be also used for the reverse operation

cat * > combined_file

dd

convert and copy a file TODO:

stat

display file status

ex. stat -c %s somefile

output file size of somefile

truncate

shrink or extend the size of file to the specified size

ex. truncate -s 1024 somefile

extend the size of somefile to 1024 bytes.

mktemp

make temp file and output its name TODO:

whatis

displays descriptions of commands, functions, or system calls

ex. whatis -w "*print*"

displays the descriptions of the commands which name contains "print".

ex. whatis -s1 printf

displays the description of the command "printf", not the c function. section 1 of man pages contain manual about executable programs or shell commands. you can "man man" for further information of the sections.

apropos

this is reverse version of whatis. search commands, functions, or system calls by keyword.

ex. apropos -s1 calc

encoder/decoder/checksum

base64

encode/decode base64

sum

print 16-bit checksum

cksum

print CRC checksum

md5sum

compute and check MD5 message digest

ex. md5sum -c somefile.md5

check MD5 of the files described in somefile.md5

ex. md5sum somefile > somefile.md5

print MD5 checksum to somefile.md5

terminal

showkey

dump the code sent by the keyboard (in zsh) Ctrl-V + <some key> makes the same effect.

text/pipe

expand/unexpand

convert tabs to spaces and do the reverse

ex. expand -t 4 file_with_tab > file_with_space

convert tabs to 4 spaces

ex. unexpand -t 4 file_with_space > file_with_tab

convert 4 spaces to tabs

yes

output a string repeatedly until killed

ex. yes | sh install.sh

answer 'y' to all questions install.sh asks.

true/false

ends with status true/false

ex. true

exit with 0

ex. false

exit with 1

look

display lines beginning with a given string

ex. look "Result:" somelog

find line beginning with "Results" in somelog.

join

join lines of 2 files on a common field

ex. join -a 2 -j 1 filea fileb

join lines of filea and fileb on a field 1. (space separated fields)

tac

print files in reverse

ex. echo "abc\ncde\n" | tac

this outputs like below

cde
abc

rev

print reverse lines of files

ex. echo "abc\ncde\n" | rev

this outputs like below

cba
edc

iconv

converts text from one encoding to another

ex. iconv -f utf-8 -t sjis somefile > somefile_sjis

converts encoding of somefile from utf-8 to sjis

fold

wrap each line to fit in specified width

ex. someprg | fold -w 50

wrap each line of someprg output to fit in 50 width

paste

merge lines of files

ex. echo "ab\ncd" > filea && echo "ef\ngh" > fileb && paste filea fileb

merge lines of filea and fileb like below

ab ef
cd gh

printf

TODO:

date/time/calendar

cal/pal

show calendar

mathematics

calc

advanced calculator

ex. calc "base(16), 1 + 0xf0"

output 1 + 0xf0 result in hex web site is located at http://www.isthe.com/chongo/tech/comp/calc/

user/system information

ldd

print shared library dependencies

logname

print user's login name

users

print the user names of users currently logged in.

groups

print the groups a user is in.

pinky

TODO:

nice

TODO:

renice

TODO:

iftop

monitor network bandwidth

iotop

monitor file i/o

mtr

network diagnosis tool

ex. mtr 192.168.0.3

at

schedule batch job

ex. at 1130

schedule command to execute at 11:30 of the day

logging

logger

TODO:

misc

sleep

sleep for a specified amount of time

ex. sleep 10s

sleep 10 seconds

getopt

parse command options TODO:

timeout

TODO:

apg

password generator

ex. apg -q -m 8 -x 8 -M NC -t

generate password with length 8. password consists of numbers and characters.

ttyrec/ttyplay

tty recorder and player like script

xml

checker

xmlwf

xml well formed checker TODO:

xmllint

xml advanced checker TODO:

devel

navigation

ctags

generate navigation tags file for source code

ex. ctags -R

create tags file for source codes by descending directory

debugger

bashdb

bash script debugger

ex. bashdb test.sh 1 2 3

start debugger for test.sh (args=1 2 3)

strace

trace the system calls and signals TODO:

binary

objcopy

copy and translate object files

addr2line

get source line number of addr

ex. addr2line -e someprg 0x00401040
ex. addr2line -e someprg -j .text 0x00000040

xxd

make a hexdump or do the reverse

ex. xxd somefile

output a hexdump of somefile

strip

discard symbols from object files.

ex. strip someprg

discard symbol information from someprg.

size

list section sizes

ex. size someprg

list section sizes of someprg

strings

list string from object files TODO:

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