Command Line Jive
Published on 5 September 2013 by amjNotes: [new group] [user] <-- These are not regular expressions [D|d] [0-9][G] <-- These are regular expressions
Redirecting input/output:
stdin - 0 - Standard Input (usually keyboard or file)
stdout - 1 - Standard Output (usually screen)
stderr - 2 - Standard Error (usually screen)
ex.: command 2> /dev/null redirects error messages to special device /dev/null
Verify a file is valid by using a signature (.sig|.sign) file and gpg. This requires installing the signer's public key. For example:$ gpg --keyserver keyring.debian.org --recv-keys DA87E80D6294BE9B
The output in this example looks like this:gpg: key DA87E80D6294BE9B: public key "Debian CD signing key
Then verify the downloaded file using the signature file also downloaded:" imported gpg: Total number processed: 1 gpg: imported: 1 $ gpg --verify ./SHA512SUMS.sign ./SHA512SUMS
The output in this example looks like this:gpg: Signature made Sat 10 Feb 2024 12:13:30 PM PST gpg: using RSA key DF9B9C49EAA9298432589D76DA87E80D6294BE9B gpg: Good signature from "Debian CD signing key
The output for a file that is not valid due to being changed by errors, not downloading correctly or having been edited or tampered with will look like this:" [unknown] gpg: WARNING: This key is not certified with a trusted signature! gpg: There is no indication that the signature belongs to the owner. Primary key fingerprint: DF9B 9C49 EAA9 2984 3258 9D76 DA87 E80D 6294 BE9B gpg: Signature made Sat 10 Feb 2024 12:13:30 PM PST gpg: using RSA key DF9B9C49EAA9298432589D76DA87E80D6294BE9B gpg: BAD signature from "Debian CD signing key
" [unknown]
Vi Notes on CyberCiti:
https://www.cyberciti.biz/faq/vim-text-editor-find-and-replace-all-text
Convert Unix Epoch to Human Readable Date On Linux:
date -d @1647945714
Tue Mar 22 03:41:54 AM PDT 2022
Detailed System Information:
sudo inxi -Fxxrzcm
Memory Info Only:
sudo inxi -m
Managing Alternatives: /path/to/LINK - like "ln -s" - Use absolute path, /usr/bin/x-www-browser generic name - Matches link name. For example, x-www-browser /path/to/exe - Absolute path to executable. For example, /usr/bin/firefox priority - The highest priority becomes the autonatic mode choice.
sudo update-alternatives --install /usr/bin/gnome-www-browser gnome-www-browser /home/andrew/bin/firefox/firefox 100
Reference:https://www.baeldung.com/linux/update-alternatives-command
Resizing a mp4 video using the command line:
ffmpeg -i ./20230622_210959.mp4 -vf scale=640:360 output_360-02.mp4
Checking packages with apt-cache policy:
apt-cache policy [PACKAGE]
Moving LibreOffice program debs and help pack deb to a single directory instead of two multilevel directories:
find ./ -type f -name "*deb" -exec mv -v {} ./DEBS/ \;
It still needs some refining, but I don't know why it took so many years for me to have this idea...
Bulk convert filenames from upper to lowercase:
rename 'y/A-Z/a-z/' *
Downloading Youtube Playlist Filenames to text file in the order they appear in the playlist:
yt-dlp --get-filename --flat-playlist "[Playlist URL]" > ./textfile
Adding cover images to audio files:
eyeD3 --add-image=./lpotl-01.png:FRONT_COVER ./[FILENAME]
find ./ -type f -exec eyeD3 --add-image=./lpotl-01.png:FRONT_COVER {} \;
find ./ -type f -name 202205* -exec eyeD3 --add-image=./lpotl-01.png:FRONT_COVER {} \;
metaflac --import-picture-from=./lpotl-01.png ./[FILENAME]
find ./ -type f -exec metaflac --import-picture-from=./lpotl-01.png {} \;
Checking battery status on a laptop:
acpi --battery --details
Scale a video with ffmpeg:
ffmpeg -i ./input.mp4 -vf scale=640:360 $HOME/Videos/output.mp4
How to hold a package at a specific version:
sudo apt-mark hold package_name
Shred:
shred -n 32 -v -u -z
Generate random character strings:
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 30 | head -n 10
The tr command constrains output to alphanumeric characters.The expressions [:alpha:] and [:digit:] and [:punct:] can be used to capture uppercase and lowercase letters, numbers and punctuation characters, respectively.
The fold command creates strings 30 columns wide.
The head command creates 10 strings.
Here, play with that...
echo $(( `date +%Y` - 1964 ))
Using rsync:
rsync -rvbpogt root@fembot:/apps/backups /mnt/external/
Where: -r recursive -v verbose -p preserve permissions -o preserve owner -g preserve group -t preserve time All I ever really use is rsync -rac --progress [...]addgroup quickie
sudo addgroup -gid [NEW GROUP NUMBER] [GROUP NAME]
This will append [GROUP NAME] to the list of groups [USER] is a member of. The -a is significant. ALL GROUPS the user currently belongs to will be clobbered (removed from the user's group membership list) without it. For example, my current group membership is: amanda adm dialout cdrom plugdev lpadmin admin sambashare allaccess. Without the -a my group membership will be changed to only: [group name], whish is bad.
sudo usermod -a -G [group name] [user]
This will find directories that are x GB in size. Where: [-h] is human-readable (12 GB instead of 12010400)
du -h | grep [0-9][G]
This will find lines in a file that start with the letter s and end with the letter n:
grep '^s.*n$' myfile
This will find lines in a file that start with either the letter R or c and end with the letter N:
grep '^[R,c].*N$' myfile
This will search recursively, print the file name and line number, and match whole string/word:
grep -rnw '/path/to/somewhere/' -e 'pattern'
Finding unused kernels on the system with sed:
ls /boot/ | grep vmlinuz | sed 's@vmlinuz-@linux-image-@g' | grep -v `uname -r`
Using checkinstall to compile and install packages. (Note: I hate, hate, hate and fucking HATE meson and ninja!)
This will compile and install the application, and create a .deb:
sudo checkinstall --pkgname=ncmpcpp-x86 --pkgversion="0.7" --backup=no --default --deldoc=yes
This will create a .deb only without installing the application:
sudo checkinstall --pkgname=ncmpcpp-x86 --pkgversion="0.7" --backup=no --install=no [--default] --deldoc=yes