Linux Tips
Combine multiple commands
goes further than just a pipe
You can execute a command on the result of another command using command $(results of other commands) You need to put inside the parenthesis the command you wish use the result of.
Examples
kill $(ps -aux | grep 'chromium'| awk '{print $2}')kill all process with chromium in the name (because killall chromium does not work)
Change your hostname
Temporary
sudo hostname newhostnameWill get back as it was after reboot
Permanently
sudo nano /etc/hostnamesudo nano /etc/hostssudo reboothostnameshould give you your newly chosen hostname
Debug command not found
Works only in bash
This annoying message when you need something that is not installed.
sudo apt install command-not-foundwill install an utility that will provide information when you will get this error.Alternatively you can use
apt-cache search command-nameit will tell what to install
See this thread for more info
Debug apt
If you get this error
The following signatures were invalidsudo wget -q -O - https://archive.kali.org/archive-key.asc | sudo apt-key addMore info on this thread
Debug snap
If you get this error
snap-confine has elevated permissions and is not confined but should be. Refusing to continue to avoid permission escalation attackssudo apparmor_parser -r /etc/apparmor.d/*snap-confine*sudo apparmor_parser -r /var/lib/snapd/apparmor/profiles/snap-confine*More info here
Update only 1 package
apt-get install --only-upgrade <packagename>This will upgrade only that single package, and only if it is installed.
File conversions
HEIC to JPG
sudo apt install libheif-examplesinstall heif-convertFor one file
heif-convert -q 85 input.HEIC output.JPGFor multiple files
for file in *.HEIC; do heif-convert $file ${file/%.HEIC/.JPG}; done
Images to PDF
You can do this with one image or multiple to put them all in one pdf
convert *.png document.pdfconvert all png files of current folder in one pdfconvert document.jpg document.pdfconvert the filedocument.jpgin to a pdf nameddocument.pdf
Note: if you get this error, this article is great. You just need to add this line
<policy domain="coder" rights="read | write" pattern="PDF" />before</policymap>in the file/etc/ImageMagick-6/policy.xml(the path can be different depending on your version of ImageMagick)
webp to jpg
convert *.webp *.jpg
PDF to images
You can do the other way around
pdfimages file.pdf extracted-images/you can add the lag-pngto specify that you want the pictures to be in png format
Note this will get every image from the PDF file. If you want every slide as images this next command is the one you need
pdftoppm -png file.pdf file/name-you-want-to-give-to-the-images
Find things
find / -name "keyword" 2>/dev/nulllook for something named keyword in the whole system and do not show error messagesfind / -type f -name ".*" 2>/dev/nullfind hidden files in the system and do not show error messages
Other options with find
-inameif you the letter capitalization does not matter.to search in the current folder-type dif you are looking for a directory-type fif you are looking for a file-perm 777if you look for files with 777 perm! -perm 777if you look for files without 777 perm-perm /a=xto look for executables files-execto execute a command on the file found examplefind / -type d -perm 777 -print -exec chmod 755 {} \;-emptyto find empty files-user usernameuse with find to get files with the user named "username"-group groupnamesame as user but for group-mtime 5modified in the last 5 days-atime 5accessed in the last 5 days-mtime +5 –mtime -10modify in between 5 to 10 days ago-cmin -60changed in the last 60 minutes-mmin -60modified in the last 60 minutes-amin -60accessed in the last 60 minutes-size 5Mget files that are 5MB
dd
dd is a command used to convert and copy a file. It can also be useful to generate dummy files that you could need during a pentest (to test for unrestricted resource consumption for example).
# create a file containing 30 random megabytes and assign it the .pdf extension
dd if=/dev/urandom of=mypdf.pdf bs=1M count=30
# generate a file with the .exe extension, filling it with random bytes
dd if=/dev/urandom of=reverse-shell.exe bs=1M count=10Grep
If you are looking for a specific thing in a file you can grep a string on it.
cat file.txt | grep "keyword"looking for keyword in file.txt-B 2this option will show us the 2 lines before our keyword-A 2This option will show su the 2 lines after our keywordgrep -iar "keyword" .iwill ignore-case,awill Process a binary file as if it were text andris for recursive and.is for the current directory.
Compare 2 files
Packets install and mamangement
List installed packets
apt list --installed(add a grep on it for example| grep imageif you are looking for the package imagemagick)
Install a deb package with apt
sudo apt install ./packet.deb
Search for a package
apt-cache search package-nameexampleapt-cache search mingw
Unzip
If you accidentally unzipped a file and want to delete all the files you just unzipped
unzip -Z -1 <filename.zip> | xargs -I{} rm -v {}
Extract unique occurrence from 2 files
You have to files and you want to extract unique values and put them in a new file (file1 should be the one with the more lines)
awk 'FNR==NR {a[$0]++; next} !($0 in a)' file1 file2Command found on stackoverflowExplanation of how the code works: If we're working on file1, track each line of text we see. If we're working on file2, and have not seen the line text, then print it. Explanation of details:
FNR is the current file's record number NR is the current overall record number from all input files FNR==NR is true only when we are reading file1 $0 is the current line of text a[$0] is a hash with the key set to the current line of text a[$0]++ tracks that we've seen the current line of text !($0 in a) is true only when we have not seen the line text Print the line of text if the above pattern returns true, this is the default awk behavior when no explicit action is given
Change DNS config in kali
This article explains it very well.
Speed up update process in Kali
If like me you are annoyed at the time it takes to update your kali, it is possible to use a mirror.
This article explains it very well.
Note: it is not the official repositories so use with caution ;)
Add a set title function in gnome-terminal
Add this code in your bashrc
function set-title() {
if [[ -z "$ORIG" ]]; then
ORIG=$PS1
fi
TITLE="\[\e]2;$*\a\]"
PS1=${ORIG}${TITLE}
}source .bashrcThen to set a title you will just need to do
set-title mytitle
kdenlive
Useful gui tool to edit video and convert them
Convert an mkv to mp4
Drag and drop the mkv file in kdenlive
Make sure it is in the sources. Like this

In Project choose render
Choose the format you want
Then click on render to file
Record a video from command line with ffmpeg
Choose an external webcam if you have multiple
Install
v4l2-ctl
sudo apt-get update
sudo apt-get install v4l-utilsList your available cameras
v4l2-ctl --list-devices
# You should get something similar to this
Webcam intégrée: intégrée (usb-0000:00:14.0-8):
/dev/video0
/dev/video1
HD Webcam USB: (usb-0000:00:14.0-4):
/dev/video2
/dev/video3Start recording
ffmpeg -f v4l2 -i /dev/video2 output.mkvstart the recordingffmpeg -f v4l2 -framerate 30 -video_size 1280x720 -i /dev/video2 -c:v libx264 -preset fast -pix_fmt yuv420p output.mp4with more options-framerate 30image per second-video_size 1280x720resolution of capture-c:v libx264specify codec (H.264 in this example).-preset fastwill compromise between encoding speed and quality-pix_fmt yuv420pdefine pixel format
You can also add -t 00:00:20 if you want a 20 second video. Also -an will make sure that no audio is recorded if you only want video this way the output file will only have video.
And when you are done if you did not set a timer you can just ctrl c.
If you only want to visualize without recording (to do your setup) you can use ffplay -f v4l2 -i /dev/video2
Unfortunately I could not find any solution to both visualize and record except by using OBS or another software :)
Capture your screen
Capture the whole screen
ffmpeg -f x11grab -r 30 -s $(xdpyinfo | grep 'dimensions:'| awk '{print $2}') -i :0.0 -vcodec libx264 -preset ultrafast -crf 18 output.mp4-f x11grab: Tells ffmpeg to use X11 for screen capture (for Linux systems).-r 30: Sets the refresh rate of the recording to 30 frames per second.-s $(xdpyinfo | grep 'dimensions:'| awk '{print $2}'): Uses the current screen resolution as the recording dimension. xdpyinfo provides information about the X display, and this command extracts the screen resolution.-i :0.0: Specifies the screen source to capture. :0.0 refers to the main display.-vcodec libx264: Uses the H.264 video codec for the recording.-preset ultrafast: Uses an encoding preset for maximum speed, at the expense of file size (useful for minimizing delay during recording).-crf 18: Sets the encoding quality factor, where a lower value means better quality (and therefore a larger file). 18 is a good balance between quality and size.output.mp4: The output file
Recording a Specific Portion of the Screen
ffmpeg -f x11grab -r 30 -s 1280x720 -i :0.0+0,0 -vcodec libx264 -preset ultrafast -crf 18 output.mp4
Make your gnome terminal more fancy
Put this in your .bashrc
# Automatic coloration with ls and grep
alias ls='ls --color=auto'
alias grep='grep --color=auto'
# colored prompt
PS1='\[\e[0;32m\]\u@\h:\w\[\e[m\]\$ '
# Command to define a title // found on stack overflow
function set-title() {
if [[ -z "$ORIG" ]]; then
ORIG=$PS1
fi
TITLE="\[\e]2;$*\a\]"
PS1=${ORIG}${TITLE}
}Last updated