Celebrazio Net

Contact Us

Shell script One-Liners

Jun, 2021

Handy shell scripts - you do have a command line don't you?

# remove space from file names in current directory
for f in *\ *; do mv "$f" "${f// /_}"; done

# prepend string "Series_" to file names: 
for f in *.txt; do mv "$f" "Series_$f"; done

# built-in calculator   - on zsh at least
print $(( 2 * 7));  print $(( 2 ** 8)); 

# brace expansions:  remove bunch of files whose names contain some range
rm prefix_{000..999}

# compare ssh keys 
ssh-keygen -y -f <private key file>  
# (outputs a public key)  and then compare against .pub keys in question

# wrap output of ps: 
ps aux | less -+S

# use tr to remove some characters, and implement single spacing: 
echo "javascript | php-cli; python ; :: ruby" | tr -cd "[:alpha:][:space:]" | tr -s " "

# use tr to change type of brackets used in a file: 
tr '{}' '[]'  < inputfile  >outputfile 

# use cut and rev to remove last 3 chars of these lines: 
cat inputfile | awk '{print $3 $4}' | rev | cut -c 4- | rev 

# python one-liner test http server: 
python -m http.server 8080

# combine image output (as from a scanner) into a single PDF (req. imagemagick): 
convert file1.jpg file2.jpg file3.jpg  FileSet.pdf

"With a PC, I always felt limited by the software available. On Unix, I am limited only by my knowledge."
-- Peter J. Schoenster

1998-2024 Celebrazio.net