Home | Notes | Github |
---|
Written: 05-Mar-2022 (Updated: 24-Jun-2024)
cat
= concatenate, useful as it prints a files contents.
bat
is a pretty alternative.echo
= Re-prints inputman
= Manual of a command.ls
= List in current directory (or specified directory if given)cd
= Change Directorypwd
= Prints Working Directoryrm
= Remove a file, or add -r
to remove a folder (recursively).
gio trash
= moves files to the recycling bin.history
= shows you all your previous commandsmkdir
- Make directory.cp [SOURCE] [DESTINATION]
- copy files. Add -r
for recursive.ln -s [ORIGINAL] [DESTINATION]
- create link to files. Remove the -s
for hard links. [DESTINATION]
is optional, if you don’t add it ln
will assume you want the link in the current directory.List of some - of the more useful - environmental variables. Run env
to list them all.
$HOME
= Home path, eg /home/me
$PWD
= Current directory.$USER
= User name e.g. me
$PATH
= List of folders which contain commands that can be called.$PS1
= Control the coloring etc. of the command prompt (i.e. the $
before commands in the examples).>
= Print output to file (erasing previous contents).>>
= Append outputs to file.|
= Pipes output from one command to the next.Basic Usage:
find {dir} {comand}
I like to search by regex, for example, searching for pictures:
find . -iregex '.*\.\(png\|jpg\)'
find
in current directory (.
) with the regex1 for a file with any name length engin in .jpg
or .png
2.
Moving after finding, apped the -exec
option
find /home -type f -name '*.pdf' -exec mv -t /destination {} +
Find all the filename extensions, courtesy of so:
find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u
To concatenate a pdf
s together try one of [these] and report back!
Split a PDF into the pages you want:
pdftk full-pdf.pdf cat 12-15 output outfile_p12-15.pdf
Download MP3s wiht youtube-dl
:
youtube-dl -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o output.mp3 $URL_STR
Download Videos with youtube-dl
(Resolution <= 720p):
youtube-dl -o "Location/%(title)s.%(ext)s" --restrict-filenames --no-playlist -f "\[height <=? 720\]" "$URL"
Downloading a playlist and converting to mp3
(where $PLAYLIST_STRING
is the “string” for the playlist in the URL):
youtube-dl -i $PLAYLIST_STRING -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 -o "%(title)s.mp3"
Use ffmpeg
to convert .mp3
to .wav
:
ffmpeg -i input.mp3 -acodec pcm_s16le -ac 1 -ar 16000 output.wav
Convert images (1.jpg
, 2.jpeg
and so on) to a video:
ffmpeg -framerate 60 -i %d.jpg -c:v libx264 -r 60 -vf format=yuv420p output.mp4
Use the following to convert images to that naming format (note it might be better to find a method with preceding zeros):
ls -v | cat -n | while read n f; do mv -n "$f" "$n.jpg"; done
Combining that into one script (run in the folder):
mkdir temp
ls -v *.JPG | cat -n | while read n f; do cp -n "$f" "./temp/$n.jpg"; done
$(cd temp/ && ffmpeg -framerate 30 -i %d.jpg -c:v libx264 -r 60 -vf format=yuv420p output30.mp4)
$(cd temp/ && ffmpeg -framerate 60 -i %d.jpg -c:v libx264 -r 60 -vf format=yuv420p output60.mp4)
mv temp/output60.mp4 ./output60.mp4
mv temp/output30.mp4 ./output30.mp4
#rm temp/
Convert .md
to a presentation in pdf
format:
pandoc -t beamer presentation.md -o output.pdf
This need different headers for each of the slides.
To Convert .md
to latex pdf
documents:
pandoc MANUAL.txt --pdf-engine=xelatex -o example13.pdf
For more demos use the pandocs demo page.
Getting Failed login attempts:
grep "Failed password" /var/log/auth.log
Very useful in general. Code to screenshot part of the screen:
import image_name.png
Code to OCR part of the screen
import png:- | tesseract - - quiet | xclip -sel clip
Convert .heic
to .png
heif-convert heic_name.heic png_name.png
Diff images (examples on stack exchange):
compare -compose src tux_orig.png tux_modified.png tux_difference.png
I like flameshot. It’s simple, and effective for screen capture. For your instant screenshot to a folder:
flameshot full -p /path/to/captures
For a screenshot with a handy interface:
flameshot gui
Use scp
to copy files using ssh from/to remote servers. From local to remote:
scp local/file.txt username@123.123.1.23:/path/to/remote/dir/
From remote to local:
scp username@123.123.1.23:/path/to/file.txt /local/directory
Add -r
to do folders.
To transfer between servers (that don’t have linked keys) use the -3
flag. Thank you stack exchange. This copies it all via your machine (so make sure you’ve got the disk space).
scp -3 user@server1:/path/to/file user@server2:/path/to/file
Use rsync
to send files to remote computer. It’s more advanced than scp
for better and worse.
rsync -azP file-or-folder user@site-or-ip:folder
Note: It has the same [SOURCE]
[DESTINATION]
syntax as scp
Note: Those flags are just what I default to. Read the man
page for more info.
Do something for each file in a dir. E.g. count lines of each file:
for f in *; do wc -l $f ;
tee allows you to pipe to a file, and to stdout
ls -l | tee filename.txt
pwgen -cBsy 20 -N 1
Here’s a useful tool for testing sed
patterns.
To list the extensions of all the files in a directory use the following (courtesy of stack overflow):
find . -name '*.?*' -type f | rev | cut -d. -f1 | rev | tr '[:upper:]' '[:lower:]' | sort | uniq --count | sort -rn
Use nmap
as per this answer:
nmap -sn 192.168.1.0/24
Separate single multi-page pdf
into individual pdf
files of it’s pages (it will label them out1.pdf
, out2.pdf
and so on):
pdfseparate multipage.pdf out%d.pdf
Combine pdf
files into one (in this case input1.pdf
followed by three copies of input2.pdf
) (source):
pdftk A=input1.pdf B=input2.pdf cat A B B B output out.pdf