- General commands
- Loop devices
- rsync commands
- dd commands
- cURL commands
- Find commands
- Redirection
- Network
- Pandoc
- VSCode
- PDF Manipluation
- Audio Manipulation
- Video Manipulation
- Image Manipulation
dpkg --print-foreign-architectures
- Get foreign architecturedpkg --print-architecture
- Get native architecturecat /var/lib/dpkg/arch
- Available architecturesudo add-apt-repository ppa:graphics-drivers/ppa
- Add a PPA to pull new packagessudo apt-add-repository --remove ppa:graphics-drivers/ppa
- Remove a PPAapt-rdepends -r python3-pip
- Show recursive dependency listings of the packagecat /proc/cpuinfo | egrep "(flags|model name|vendor)" | sort | uniq -c
- Get CPU flag detectionmount -o remount rw /
- Remount / path with read-write accessecho 'USER_NAME ALL=(ALL:ALL) ALL' | sudo EDITOR='tee -a' visudo
- Add a user to visudo/suderosecho 'USER_NAME ALL=NOPASSWD: ALL' | sudo EDITOR='tee -a' visudo
- Add password free userid -g USER_NAME
- Get primary group id for a userid -gn USER_NAME
- Get primary group name for a userusermod -g GROUP_NAME USER_NAME
- Change group for a usersudo find /path/to/search -group GROUP_NAME -d type d
- Find out folders belong to a specific group- Find and kill a process by name
PID=$(ps -ef | grep <process_name> awk '{print $2}')
kill -9 $PID
sudo fc-cache -f -v
- Update font cachegsettings list-recursively
- List settings- Auto-mount sdcard/usb
gsettings set org.gnome.desktop.media-handling automount true
gsettings set org.gnome.desktop.media-handling automount false
- Remove a package from ubuntu
dpkg --list # Find package name
sudo apt remove <package.name> # Remove package
- Create a disk for FAT type
dd if=/dev/zero of=fat.bin bs=1M count=6
mkfs.vfat ramdisk.bin
mkdir fat
sudo mount -o loop fat.bin fat/
sudo cp <list of files> fat/
sudo umount fat
- Mount ext4 dd image
sudo losetup -f # Find out next free loop
sudo dd if=/dev/zero of=ext4.bin bs=1M count=50
sudo losetup /dev/loop0 ext4.bin
sudo mkfs.ext4 /dev/loop0
mkdir -p ext4
sudo mount -t ext4 /dev/loop0 ext4
- Shrinking disk image (using gparted)
sudo losetup -f # Find out next free loop
sudo losetup /dev/loop<0> diskimage.img
sudo partprobe /dev/loop<0> # Get available partitions
sudo gparted /dev/loop<0> # Use gparted to manipulate partition
sudo losetup -d /dev/loop<0> # Unload device
- Shrinking disk image (using gparted)
fdisk -lu diskimage.img # Get details of partitions
Disk diskimage.img: 4096 MB, 4096000000 bytes, 8000000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a1bc7
Device Boot Start End Blocks Id System
diskimage.img 2048 5872026 5869978 b W95 FAT32
Make note of the number shown under End
, now use it in following command:
truncate --size=$[(5872026+1)*512] diskimage.img
-
rsync -av --exclude '*.jpg' --exclude '*.mp4' src/ dst/
- Copy the contents ofsrc
intodst
-
rsync -av --exclude '*.jpg' --exclude '*.mp4' src dst/
- Copysrc
intodst
/
to the destination does not matter, command will create it ifdst
folder does not exist
-
rsync -av --remove-source-files --exclude '*.jpg' --exclude '*.mp4' src dst
- Copysrc
intodst
and remove copied files from the source
- Dump /dev/sda to /dev/sdb
dd if=/dev/sda of=/dev/sdb
dd if=/dev/sda of=/dev/sdb bs=64k conv=noerror,sync
- Dump disk to a compressed image
dd if=/dev/sda bs=1k | gzip > disk.gzip
gzip -d -c disk.gzip | dd of=/dev/sda bs=1k
- Create a 5MB disk image
dd if=/dev/zero of=disk.img bs=1k count=5MB
- Wipe a disk by writing zeros to it
dd if=/dev/zero of=/dev/sda bs=16M
- Write random numbers to disk
dd if=/dev/urandom of=/dev/sda bs=16M
- Send random data to framebuffer device
cat /dev/urandom > /dev/fb0
dd if=/dev/urandom of=/dev/fb0 bs=1024 count=8100
-
curl -i -X POST http://localhost:5500/link -F '[email protected]'
- Upload a file -
curl -i -X POST http://localhost:5500/link -H "Content-Type: application/json" --data '{"key":"value"}'
- Send json command -
curl --data "param1=value1¶m2=value2" http://localhost:5500/link
- Send data
- Find a file of specific name
find . -type f -name "postgis"
- Get rid of the Clock skew detected. Your build may be in-complete. Put timestamps on all files equal to current time
find . -exec touch {} \;
- Change format of the files
for i in `find . -name "*.cc" or -name "*.hpp`; do dos2unix $i; done
for i in `find . -name "*.cc" or -name "*.hpp`; do unix2dos $i; done
-
or
-- Use to OR multiple-name
flags. -
Find file(s) with a specific name (with loop and custom command)
for i in `find . -name ".mk"`; do echo $i; done
for i in `find . -name ".mk"`; do git add -f $i; done
- File file(s) of specific extension (Show full path path of the found file)
for i in `find . -name "*.cc"`; do echo $i; done
- File file(s) of specific extension (Show only file name)
for i in `find . -name "*.cc"`; do echo $(basename $i); done
NOTE: basename
is part of the POSIX spec so hoping it is supported by underlying OS otherwise
for i in `find . -name "*.cc"`; do echo ${i##*/}; done
- File file(s) of specific extension (Show only dir name)
for i in `find . -name "*.cc"`; do echo $(dirname $i); done
NOTE: dirname
is part of the POSIX spec so hoping it is supported by underlying OS otherwise
for i in `find . -name "*.cc"`; do echo ${i%/*}; done
- File file(s) of specific extension (Show file with full path but without .ext)
for i in `find . -name "*.cc"`; do echo ${i%.cc}; done
- Rename files of specific extensions
for i in `find . -name "*.cc"`; do mv $i ${i%.cc}.cc; done
- Find all files
find /usr/share/ -type f -printf "%f\n" | sort > all.txt
find /usr/share/ -type f -printf "%f\n" | sort | uniq > uniq.txt
- Find all sym links in a directory
find . -type l -ls
- Find and delete empty folders
find /path/to/folder -depth -type d -empty -delete
- Find and delete specific format file
find . ! -name '*.pdf' -type f -exec rm -f {} +
1
denotesstdout
;2
denotesstderr
.>
- Redirect output of the command onto the right side (Overwrite the contents of output.txt)>>
- Redirect output of the command onto the right side (Append to the contents of output.txt)command > output.txt
- Redirect standard output stream to output.txtcommand 2> output.txt
- Redirect error stream to output.txtcommand &> output.txt
- Redirect both (standard & error) streams to output.txtcommand > output.txt 2>&1
- Redirect standard output to output.txt and also redirect error stream to standard output streamcommand | tee output.txt
- Copy standard output stream to output.txtcommand | tee -a output.txt
- Copy & append standard output stream to output.txtcommand |& tee output.txt
- Copy both (standard & error) streams to output.txt
- Enable eth0
udhcpc -i eth0
route add default gw xxx.xxx.xxx.xx eth0
- OR -
netcfg eth0 up
netcfg eth0 dhcp
- OR -
ifconfig eth0 up
ifconfig eth0 down
dhclient eth0
auto eth0
iface eth0 inet dhcp
- Show IP address assigned to eth0
ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'
- Show network connection
route | grep -m1 ^default | awk '{print $NF}'
- Network sockets usage
netstat -ltnp | grep -w ':80'
lsof -i :80
netstat -ano -p tcp
sudo netstat -ap | grep 5000
- Convert word document to markup (Images in the document will be saved to folder #
media
)
pandoc --extract-media ./media -f docx -t markdown word.docx -o markup.md
- Export installed extensions and install back
code --list-extensions > extensions.list
cat vscode-extensions.list | xargs -L 1 code --install-extension
- Remove a page from the pdf
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
-sPageList=1-3,6- \
-sOutputFile=out.pdf in.pdf
- Split the range of pages from the pdf
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
-dFirstPage=22393 -dLastPage=23052 \
-sOutputFile=input.pdf \
output.pdf
- Search text in pdf
find docs/ '*.pdf' -exec sh -c 'pdftotext "{}" - | grep --with-filename --label="{}" --color "SwapDrawableWithDamage"' \;
pdftotext my.pdf - | grep 'pattern'
- Reduce pdf file size
convert -density 200x200 -quality 60 -compress jpeg input.pdf output.pdf
https://askubuntu.com/a/469255
- Convert png to PDFs
convert img1.png img2.png -compress jpeg -quality 50 output.pdf
convert img1.png img2.png sample-*.png -compress jpeg -quality 50 output.pdf
- Handy commands to manipulate audio files.
https://trac.ffmpeg.org/wiki/AudioChannelManipulation
- Audio track as aac
ffmpeg -i input.mp4 -vn -acodec copy audio.aac
- Audio track as mp3
ffmpeg -i input.mp4 -vn -f mp3 output.mp3
- Convert mp3 file to audio with a picture
ffmpeg -loop 1 -i picture.jpg -i input_audio.mp3 -shortest -c:v libx264 -tune stillimage -c:a copy video.mp4
for i in `find . -name "*.wav"`; do echo $(basename $i); ffmpeg -i $i -sample_fmt s16 modify_$(basename $i); done
for i in `find . -name "*.wav"`; do echo $(basename $i); ffmpeg -i $i -sample_fmt s16 -filter_complex "channelmap=map=FL-FL|FL-FR:channel_layout=stereo" modify_$(basename $i); done
for i in `find . -name "*.wav"`; do echo $(basename $i); ffmpeg -i $i -sample_fmt s16 -filter_complex "channelmap=map=FR-FL|FR-FR:channel_layout=stereo" modify_$(basename $i); done
for i in `find . -name "*.wav"`; do echo $(basename $i); xxd -i $(basename $i) > $(basename $i).c; done
ffmpeg -i old.mp3 -acodec libmp3lame -ac 2 -ab 64k -ar 44100 new-1.mp3
- MOV into MP4:
ffmpeg -i input.mov -codec copy output.mp4
- Convert codec from HEVC to H264:
ffmpeg -i input.mp4 -c:v libx264 output.mp4
ffmpeg -i input.mp4 -vf "setpts=speed_multiplier*PTS" output.mp4
- To slow down your video, you have to use a multiplier greater than 1.
ffmpeg -i input.mp4 -vf "setpts=PTS/factor" output.mp4
ffmpeg -i concat:"input1.mp4|input2.mp4" output.mp4
ffmpeg -i input.mp4 -an output.mp4
ffmpeg -i input.mp4 -vf transpose=1 output.mp4
- Change quality of the video
ffmpeg -i input.mp4 -c:v libx264 -crf 18 -c:a copy output.mp4
- CRF @ https://slhck.info/video/2017/02/24/crf-guide.html
- Play with it to see quality vs size
- Change the resolution & bit rate
ffmpeg -i input.mp4 -s 320x240 -b:v 512k -vcodec mpeg1video -acodec copy output.mp4
- Change the resolution
ffmpeg -i input.mp4 -vf "scale=iw/2:ih/2" output.mp4
- Clip the video
ffmpeg -i input.mp4 -c copy -ss 00:03:22.0 -to 00:08:49.0 output.mp4
ffmpeg -i input.mp4 -vf "subtitles=lyrics.srt:force_style='FontName=DejaVu Serif,FontSize=24'" output.mp4
for file in *.jpg; do convert "${file%%.*}".jpg "${file%%.*}".png; done
ffmpeg -vcodec png -i test1.png -vcodec rawvideo -f rawvideo -pix_fmt rgb565 test1.data
ffmpeg -f rawvideo -pixel_format rgba -video_size 1920x1080 -i input.data test.png
convert -depth 8 -interlace plane -size 100x100 rgb:input.data output.png
NOTE: ffmpeg got a complicated command.
ffmpeg -i test.png -pix_fmt nv12 test.yuv
ffmpeg -i input.mp4 output_%02d.png
-
-r 1.0
- in above command will ask to capture frame after 1 seconds instead of all. -
Output one image every 1 seconds:
ffmpeg -i input.mp4 -vf fps=1 out%d.png
-
Output one image every minute:
ffmpeg -i test.mp4 -vf fps=1/60 thumb%04d.png
-
Output one image every 10 minutes:
ffmpeg -i test.mp4 -vf fps=1/600 thumb%04d.png
- Single image to video of 1 minute length and specific video format
ffmpeg -loop 1 -i test.png -vf format=yuv420p -r 60 -t 60 output.mp4
- Multiple images to a video
ffmpeg -framerate 60 -i image-%02d.png -vf format=yuv420poutput.mp4
- Input png are named:
input_01.png
input_02.png
...input_10.png
output.mp4
will have frame rate of 25fps- Each image will be shown for 1/25
ffmpeg -framerate 1/5 -i image-%02d.png -vf format=yuv420p output.mp4
ffmpeg -framerate 1/5 -i input_%02d.png -vf format=yuv420p -r 60 test.mp4
- Show each input image for at least 5 seconds
- B & W image
for i in `find . -name "*.jpg"`; do convert $i -normalize -threshold 80% $i; done
NOTE: If file name is having spaces, $i
will not have full file name. To avoid this
IFS=$'\n'; for i in `find . -name "*.jpg"`; do echo "$i"; done
- Enhance color image
for i in `find . -name "*.jpg"`; do convert $i -channel RGB -contrast-stretch 1x1% $i; done
https://legacy.imagemagick.org/Usage/color_mods/
convert -delay 25 -loop 0 *.png test.gif