Celebrazio Net



Contact Us

Shell script One-Liners

Feb, 2020

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}

# 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


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





1998-2021 Celebrazio.net