CLI

  • Linux Novice – Someone who wonders what RTFM means.
  • Linux User – Someone who has tried to RTFM.
  • Windows User – Someone who has never heard RTFM.
  • Linux Guru – Someone who doesn’t need to RTFM.
  • Linux Hacker – Someone who knows what isn’t in TFM.
  • Linux Jedi – The one who WTFM.

Burn an iso to CD-ROM

wodim -eject -tao speed=0 dev=/dev/sr0 -v -data bmp1.iso

Build an iso image (bmp1.iso) from the contents in a folder (temp)

genisoimage -r -o bmp1.iso temp

genisoimage -r -joliet-long -o files1.iso temp

Burn ISO to disk

wodim -eject -tao speed=0 dev=/dev/sr0 -v -data files1.iso

Add line numbers to a file (5 digits, leading zeros, separated by a colon)

nl -i1 -s’: ‘ -nrz -w5 twit3.txt >twit4.txt

Copy command-line output to clipboard

cat spock2.txt | xclip -selection clipboard

Generate a pdf from a man page

man -t vim | ps2pdf – > vim.pdf

Append an asterisk prefix to every line in a file

sed -ne ‘s/.*/* &/p’ enterprise.txt > enterprise2.txt

Rename all files with extension .OUT with the extension .txt

rename ‘s/\.OUT$/.txt/’ *

Convert a photo into an ASCII art representation directly into the terminal and save it to photo.ascii at the same time

jp2a Photo.jpg | tee photo.ascii

Change double-spaces in a text file to single spaces

cat redpine.txt | sed ‘s/ \+/ /g’ > redpine2.txt

Delete empty files in and under the current directory

find . -empty -exec rm -f {} \;

Run the last command again as root

sudo !!

Make the text in a file all uppercase

cat testa.txt | tr ‘[a-z]’ ‘[A-Z]’ > testb.txt

Replace spaces in the filename of all the files in a directory with hyphens

find . -name “* *mp3” -exec rename ‘s/\ /-/g’ {} \; Michael-Neil-&-Graham-Getty—Retrochet-II—01—Cascade-Effect-Part-1.mp3

Convert all your files saved as “*.jpg-large” back to “*.jpg”

(so Twitter thinks they are images again)

find . -depth -name “*.jpg-large” -exec sh -c ‘f=”{}”; mv — “$f” “${f%.jpg-large}.jpg”‘ \;

Find ten biggest hogs of disk space under a directory

du -s /usr/share/* | sort -nr | head

Prime factors of first 100 integers

echo {1..100} | factor

Make an image of a CD on your hard drive

dd if=/dev/sr0 of=image.iso

Mount that image on your system to use it

(The mount point must already exist) mount -o loop image.iso /mnt/temp ===

Get a weather forecast for your city

curl wttr.in/seattle

Find files by name

find . -name *wav -print

Get information about all files of a certain type

find . -name *com -exec file {} \;

Print number of processes running as each user

$ ps -ef | awk ‘{print $1}’ | sort | uniq -c

List the misspelled words in a file

enchant -l matthew

Return the name of the most-recently modified file in a directory

$ ls -t | head -1 20190506_061751k2.jpg

Strip blank lines from a text file

awk ‘NF > 0’ yeshua > yeshua2

Make all filenames in a directory lowercase

 

#!/bin/bash 
for x in `ls` 
do 
if [ ! -f $x ]; then 
continue 
fi 
lc=`echo $x | tr '[A-Z]' '[a-z]'` 
if [ $lc != $x ]; then 
mv -i $x $lc 
fi 
done 

paste into file called lowerit chmod u+x lowerit ./lowerit

Combine two files, line by line, comma delimited

$ paste -d, names.txt distances.txt

Concatenate a group of files into a single new file

for file in *; do cat $file >> linuxgal.txt; done

Find man page for a command

whereis -m genisoimage

genisoimage: /usr/share/man/man1/genisoimage.1.gz

Build a list of unique words in a file

tr ‘ ‘ \\n < notes20191108.txt | sort | uniq

Build an iso from a file

genisoimage -r -joliet-long -o -win98tib.iso /home/teresita/Desktop/iso/win98[7]20150529.tib

Burn an iso to a CD-ROM

Make a new .iso image in /mnt/burn from the contents in /mnt/hold

mkisofs -o /mnt/burn/image.iso /mnt/hold

Burn that image to another CD

cdrecord dev=/dev/sr0 /mnt/burn/image.iso

Convert RPM package to DEB package

alien file.rpm

Copy a file

cp INFILE OUTFILE

Add a CD-ROM to your list of repositories.

apt-cdrom -m add

List only non-blank lines in a file

awk ‘NF >0’ file.txt

Create a custom command to list files

alias l = ‘ls -l –color=auto’

Add line numbers to a file

cat -n file.txt

Find text in a file

awk ‘chevy’ cars.txt

Backup Master Boot Record

dd if=/dev/sda of=MBR.img bs=446 count=1

Make a file lowercase

cat FILE1.TXT | tr ‘[A-Z]’ ‘[a-z]’ > FILE2.TXT

Change the owner of a directory and all its contents

chown -R teresita DIRECTORY

Grab a copy of a website

wget -w9 -r –random-wait -l3 -np -E URL

Display time since boot

uptime

Get the sizes of all subdirectories under a directory

du -sh MYDIR

Display unique lines in a sorted file

uniq <FILE1 >FILE2

Use CUPS printer management system

localhost:631 (in a browser address bar)

MP3 to WAV conversion

madplay –output=wave:OCEANLAB.WAV OCEANLAB.MP3

Convert to OGG

oggenc *

Create a link

ln -s /initrd/mnt/dev_ro2 HOME

Extract tarball

tar -xvf /dev/hda/FILE

Make archive

tar -c DIRECTORY | bzip2 > DIR.TAR.BZ2

Make a file executable for all users

chmod u+x FILE

Turn a directory into a SquashFS file

mksquashfs /tmp/merge PUP_412.SFS

Mount your SquashFS file

mount -o loop -t squashfs PUP_412.SFS /mnt/pup

Upload a file to your webspace

wput MYFILE ftp://username:password@web.host.com

Convert a MIDI file to a .WAV file

timidity -Ow -oRUBY.WAV RUBY.MID

name=”Replace_spaces_in_a_filename_with_hyphens”>

Replace spaces in a filename with hyphens

find . -name “* *mp3” -exec rename ‘s/\ /-/g’ {} \;

Print the current month in Julian dates

cal -j

Make a new file of the individual words in another file

tr ‘ ‘ ‘\012’ <INFILE >OUTFILE

or

for WORD in `cat FILE`
do
echo $WORD
done

Strip carriage returns from a DOS file

tr -d ‘\015’ <INFILE >OUTFILE

Downshift all file names

#!/bin/bash
for x in `ls`
do
if [ ! -f $x ]; then
continue
fi
lc=`echo $x  | tr '[A-Z]' '[a-z]'`
if [ $lc != $x ]; then
mv -i $x $lc
fi
done

Rename in bulk

OLD=xxx

NEW=yyy

for F in $OLD*

do

SUFFIX=`expr $F : ‘$OLD\(.*\)’`

mv $OLD$SUFFIX $NEW$SUFFIX

done

Install from tarball

tar -zxvf ARCHIVE.TAR.GZ

./configure

Format floppy disk

fdformat /dev/sde

List directories

find . -type d -print

=== Convert avi to mpeg ===

mencoder MOVIE.AVI -of mpeg -mpegopts format=mpeg1:tsaf:muxrate=2000 -o MOVIE.MPG -oac lavc -lavcopts acodec=mp2:abitrate=224 -ovc lavc -lavcopts vcodec=mpeg1video:vbitrate=1152:keyint=15:mbd=2:aspect=4/3

Factorial function implemented by recursion.

define fact(n)

{

if (n <= 1) return (n);

return (n * fact(n-1));

}

Perform a ROT 13 conversion

#!/bin/sh
echo "$1" | tr '[A-Za-z]' '[N-ZA-Mn-za-m]'

Download streaming videos and convert them to MP3s

sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl

sudo chmod a+x /usr/local/bin/youtube-dl

youtube-dl –title –extract-audio –audio-format mp3 https://www.youtube.com/watch?v=L3FmBjX-p0I

[edit]Convert decimal to 16 bit binary and trim leading zeros

#! /bin/bash
D2B=({0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1})
echo $((10#${D2B[$1]}))

Send a man page to the terminal minus the embedded backspace characters

man genisoimage | col -b | less

Print the first sixteen binary numbers using awk to align the data

echo “obase=2;i=0;while(i<=15) {i;i+=1}” | bc | awk ‘{printf “%4s\n”, $0}’