Skip to content

Instantly share code, notes, and snippets.

@jcarolinares
Last active February 3, 2023 02:23
Show Gist options
  • Save jcarolinares/c63260ff68f099738d06b0e03aa61948 to your computer and use it in GitHub Desktop.
Save jcarolinares/c63260ff68f099738d06b0e03aa61948 to your computer and use it in GitHub Desktop.
This is a simple guide for non-pro bash users to do random but annoying tasks in just seconds

Useful commands to use in Shell or others:

This is a simple guide for non-pro bash users to do random but annoying tasks in just seconds

Your boss will be happy and you'll be less stressed ;)

Files

Search a file name using a string:

find | grep "<string>"

Search for a string coincidence inside files:

grep -R "<string>" <path>

It will show all the files that have that string inside it.

To count the number of coincidences:

find . -type f  -exec grep -i "1424421066776" {} + | wc -l

PDFs

Search a phrase or keyword in multiple PDF:

for i in *.pdf; do echo $i; pdftotext "$i" - |grep -i -n 'frase'; done

Source (Spanish): [http://www.ubuntizando.com/busca-texto-en-multiples-pdf-a-la-vez/]

Extract, fusion or PDFs and others

Extract images from a PDF

Example

 pdfimages -f 15 -l 181 input.pdf base_output_name

Where -f is the beginning page, and -l is the finish page

If you want to extract all the images from various pdf files inside a folder you can use:

for i in *.pdf; do echo $i; pdfimages -j -p "$i" base_image_output_name; done

Where ** -j** means jpg images and -p means include page numbers in output file names

Fusion two or more PDF files

Example:

pdfunite file_1.pdf file_2.pdf file_n.pdf fusion_output.pdf

Another useful way to do this, is putting all the pdf files that you want to fusion in one folder and write:

pdfunite *.pdf fusion_output.pdf

Separate the pages from a pdf file in different pdf files

Example:

pdfseparate -f 3 -l 34 input_file.pdf output_file_%d.pdf

Where -f is the beginning page, and -l is the finish page and %d means the number of page

Source (Spanish): [https://www.atareao.es/ubuntu/trabajando-con-pdf-desde-el-terminal-en-ubuntu/]

How to edit the metada of a PDF

Example:

exiftool -Title="This is the Title" -Author="Happy Man" -Subject="PDF Metadata" file.pdf

You will need to install the libimage-exiftool-perl package

Source: [https://askubuntu.com/questions/27381/how-to-edit-pdf-metadata-from-command-line#39906]

Computer info

How to know which hardware do you have

Use the command ls hw

sudo ls hw

The prompt will give you all the details of your CPU, USB etc.

3D printing

How to find a 3D design in the mains repositories in only one search using Google.com

Using the Google advanced search:


site:thingiverse.com OR site:yeggi.com OR site:cgtrader.com OR youmagine.com OR grabcad.com OR stlfinder.com DINOSAUR

Source (English): [https://blog.astroprint.com/the-ultimate-3d-printing-cheat-sheet/]

Youtube

How to download a simple video

Using youtube-dl:

youtube-dl http://youtube.com/thevideourl

youtube-dl has a lot of options that you can find writing "youtube-dl --help":

  • -c Continues with a failed download
  • -i ignore fails and continues with the next video

How to download a simple video with subtitles

There's a lot of options but the most common and easier is:

youtube-dl  --all-subs http://youtube.com/thevideourl

How to download a playlist:

You must convert this url to this:

http://http://www.youtube.com/watch?v=V7RHrn2jvgg&playlist?list=PLB5DD0DDCDE1C3C47

http://http://www.youtube.com/playlist?list=PLB5DD0DDCDE1C3C47

Use the following command:

youtube-dl -ci --all-subs http://youtube.com/playlisturl

Where -c means download the failed videos, -i means ignore the errors and keep going and --all-subs will download all the available subtitles

Source (Spanish): [http://www.tuxylinux.com/descargar-playlist-de-youtube-con-youtube-dl/]

How to download a list of videos saved in a file

First of all you have to create a .txt file where each line is one of the youtube videos url

Use the following command:

youtube-dl -a links.txt

Where "links.txt" is the name of the file. Remember that you can combine this option -a with others parameters as -c, -i, etc.

Source (Spanish): [https://blog.desdelinux.net/youtube-dl-tips-que-no-sabias/]

How to download only the audio of a video

Use the option --extrac-audio and --audio-format

Use the following command:

youtube-dl --extract-audio --audio-format mp3 link

Where --extract-audio download the video and extract the audio and --audio-format convert the audio to the desired format (mp3, ogg, etc.). To extract audio you'll need the last version of youtube-dl: [https://yt-dl.org/update]

Source (Spanish): [https://gilberto286.wordpress.com/2013/06/05/como-extraer-el-audio-de-un-video-de-youtube-utilizando-youtube-dl-en-ubuntu/]

Email

How to send an email

You can send an email from the terminal using the command mail

mail -s "Test Subject" [email protected] < /dev/null

Where -s is the option for writting a subject.

If you want toi send an email with a body you can write:

mail -s "Test Subject" [email protected]

After that, writte your email and press ctr+d to finish and send the email

Source (Spanish): [https://victorhckinthefreeworld.com/2014/04/23/enviar-correo-desde-la-linea-de-comandos-con-mail/]

Network

How to know the devices connected to your network

You can try:

sudo nmap -sP 192.168.1.1-254

Keep in mind that the main IP(192.168.1.1 to 192.168.1.254) could change in your network.

Source (Spanish): [https://nideaderedes.urlansoft.com/2013/12/23/linux-como-puedo-saber-que-maquinas-hay-conectadas-en-mi-red-local/]

How to create a local webserver of the actual folder

Just write:

python -m SimpleHTTPServer

A simple webserver will be created with the contents of the actual folder. Go to http://localhost:8000 in your browser to see it. Source (Spanish): [http://mundogeek.net/archivos/2016/11/07/los-10-comandos-mas-utiles-de-linux/]

Files

How to download all the links inside a webpage

wget -r -np -l 1 -A zip http://example.com/download/

Where -l 1 defines the number of subpages to look, and -A the formats to download.

Source: [https://stackoverflow.com/questions/13533217/how-to-download-all-links-to-zip-files-on-a-given-web-page-using-wget-curl]

How to create a folder with different subfolders

mkdir -p /path-main-folder/folder{1..4}

It will create the main-folder or the existing path, and inside it, the folders named as "folder1, folder2, etc"

Source: [https://zillowtech.com/install-yarn-on-ubuntu.html]

How to split a file in various parts

Use csplit:

csplit filename.mp4 4 -f filename_part

Where 4 is the number of parts and -f with the following name (filename_part) determines the base name

How to fusion the parts again:

cat filename_part0[0-3] > filename.mp4

Source (Spanish): [https://www.linuxadictos.com/csplit-coge-hacha-parte-los-ficheros-grandes-partes.html]

How to compare files:

The most quickly way to see the difference between two files is using the command diff:

diff filename1.txt filename2.txt

The pront will show the differences founded in each line.

How to create numerated folders:

mkdir ./base_folder_name{1..N}

Where N is the last folder number

Source (Spanish): [https://www.enmimaquinafunciona.com/pregunta/71792/bucles-en-bash-para-crear-carpetas-numeradas-secuencialmente]

How to delete the trash files from terminal

Sometimes the trash folder doesn't work properly. You can delete the files using the command:

sudo  rm -rf ~/.local/share/Trash/*

REMEMBER THAT ONCE YOU DELETED THE FILES YOU CANNOT RECOVER THEM

Kill process

Kill a process knowing the name

Use pkill

pkill nautilus

Kill a process cliking in its windows

Use xkill

xkill

Timers

How to execute a command after some time:

The most easy way to do this is using the sleep command:

sleep 5 m

In this case, we're waiting 5 minutes

Where 5 is the amount of time, m the unit (minutes=m, seconds=s, hours=h)

To execute a command after this time just use &&

sleep 5 m && echo "Time finished"

Deb packages

How to install a deb package

dpkg -i package.deb

Where -i means install.

Source (Spanish): [https://hipertextual.com/archivo/2014/02/instalar-paquetes-deb-con-dpkg/]

How to know the packages installed on your system

dpkg --get-selections

To filter the list just use grep

dpkg --get-selections | grep keyword

How to remove a deb package

dpkg -r package.deb

Where -r means remove.

Source (Spanish): [https://hipertextual.com/archivo/2014/02/instalar-paquetes-deb-con-dpkg/]

How to purge a deb package

dpkg -p package.deb

Where -p means remove.

Source (Spanish): [https://hipertextual.com/archivo/2014/02/instalar-paquetes-deb-con-dpkg/]

How to remove a damaged package

sudo  dpkg --remove --force-remove-reinstreq package_name

Source (Spanish): [http://www.ubuntu-es.org/node/25860]

Duck and go search engine

Cheatsheets

Inside Duck and go just search:

<yourlanguageorthing> cheatsheet

You'll see a cheatsheet with all the commands that you need.

Example:

markdown cheatsheet

Google docs

How to create a quick new document

In your browser just write one of this URLs:

Documents: doc.new, docs.new, documents.new
Cheatsheets: sheet.new, sheets.new, spreadsheet.new
Presentations: slide.new, slides.new, deck.net, presentation.new
Websites: site.new, sites.new, website.new
Forms: form.new, forms.new

Source (Spanish): [https://www.genbeta.com/truco/como-crear-forma-instantanea-cualquier-tipo-documento-google-docs]

How to know when a bash command has finished

Put your command and the following notify-send command

make  && notify-send "Task complete."

Source: [https://askubuntu.com/questions/611874/how-do-you-make-your-terminal-play-a-sound-or-offer-a-notification-when-it-has-f]

How to create a random password of a selected length

strings /dev/urandom | grep -o '[[:alnum:]]' | head -n LENGTH | tr -d '\n'; echo

Where you have to put in length the desired number. Example with a passworf of 8 characters:

strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 8 | tr -d '\n'; echo

Source (Spanish): [https://blog.desdelinux.net/aprendiendo-shell-scripting-grep/]

How to convert a mp4 video to a gif

ffmpeg -i input.mp4 -pix_fmt rgb24 output.gif

Where -pix_fmts it's an optional argument that shows the available pixel formats

Source: [https://askubuntu.com/questions/770165/how-to-convert-edit-mp4-file-to-gif-in-ubuntu-16-04]

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