26 Apr 2024
These are my notes for Linux related stuff that didn't quite deserve their own post as of yet. Hopefully you'll also find something in here useful. Enjoy.alias composer='php /usr/local/bin/composer'
This means that whenever I write “composer” in the console, what I'm really writing is “php /usr/local/bin/composer”. You can see all your aliases with the alias
command, and remove specific aliaseses again with this command:
unalias composer
alias composer='php /usr/local/bin/composer'
The ~/.bash_aliases-file is loaded via the ~/.bashrc-file. So when you make changes to the ~/.bash_aliases-file make sure to reload the ~/.bashrc-file. This is done with the following command:
source ~/.bashrc
crontab -e
Each line has 5 time-and-date fields followed by a command. The field are: minutes, hours, day of month, month and day of week. I usually use cron.help to define new running frequencies.
cd /path/to/directory && mycommand
Change it to your directory and mycommand to your desired command.
tail /var/log/cron
This is very useful when adding new commands to your crontab and ensuring that they work. Alternatively use grep to search through the log.
sudo dnf update -y
sudo dnf upgrade -y
sudo reboot
wget https://raw.githubusercontent.com/rocky-linux/rocky-tools/main/migrate2rocky/migrate2rocky.sh
chmod +x migrate2rocky.sh
sudo ./migrate2rocky.sh -r
sudo reboot
file --mime-type certificate.pdf
Replace certificate.pdf with whatever file, you are examining. The command will give output similar to this:
certificate.pdf: application/pdf
grep -sIir TEXT *
Replace TEXT with whatever you are searching for and * with your desired folder.
sudo apt install cifs-utils
sudo mkdir /media/share
Now create a credentials file.
nano /etc/samba/credentials
Set the samba username and password in the file like this:
username=smb_username
password=smb_password
sudo mount -t cifs -o rw,credentials=/etc/samba/credentials //192.168.1.10/share /media/share
Replace the ip address with your server. This will mount the share until system boot.
umount /media/share
sudo nano /etc/fstab
Where you add the following to the end of the file:
//192.168.1.10/share /media/share cifs credentials=/etc/samba/credentials
Replace the ip address with your server.
sudo fdisk -l
Displays how much space is left.
df -H
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFsettings=/display -dNOPAUSE -dQUit -dBATCH -r150 -sOutputFile=outputfile.pdf -dCompressFonts=true -sProcessColorModel=DeviceGray -sColorConversionStrategy=Gray inputfile.pdf
Simply replace inputfile.pdf and outputfile.pdf with your input and output filenames.
wmctrl -r Firefox -e 0,0,0,1600,1200
scp filename user@ip:location
Which would like like this for a simple textfile:
scp stuff.txt root@192.168.0.23:/home/root/Documents
You can also copy entire directories like so:
scp -r .\Desktop\MyFolder\* root@192.168.0.23:/home/root/Desktop/MyFolder/
The above examples show you how to copy from your own computer to another computer, however you can also reverse the direction, so you are downloading from the remote computer unto your own. Simply reverse the direction as shown here:
scp -r user@ip:location destination
Simply adjust the above to your situation, e.g. replace destination with /home/user/Downloads. Note: rerunning the command just overwrites the existing files, so you always have the latest version.
~/.ssh/config
by adding something similar to this:
# mydatabase
Host mydatabase
User databaseuser
Hostname 123.123.123.123
Change mydatabase with whatever name you want to use, databaseuser with your username, and 123.123.123.123 with the actual IP address.
ssh -i ~/.ssh/id_rsa -N -L 13306:localhost:3306 root@ip
-i is for identity file.
N is unknown.
L is location. 13306 is the local port. localhost:3306 is the location and port from the viewpoint of the remote.
RockyLinux notes
Published 2024-05-05
DevOps
Linux
Notes
Various notes gathered after converting to RockyLinux from CentOS.
Read the post →How to easily web scrape any website with Python
Published 2024-05-03
Datahoarding
Notes
Python
Web development
Learn how to easily web scrape any website using Python. I go through the various techniques I use.
Read the post →Python notes
Published 2024-05-03 — Updated 2024-05-14
Notes
Python
Different tips, tricks and how-to's while developing various scripts in Python.
Read the post →