Assuming /media/G
and /media/E
are 2 different shared folders mounted allready and you
are now inside Linux in VBox then do
rsync -av --delete /media/G /media/E
alias ls='ls --color=never'
#!/bin/bash for file in *.png; do filename=${file%.*} convert "$filename.png" "$filename.eps" done
To change extension from .PNG to lowe case .png
#!/bin/bash for file in *.PNG; do f=${file%.*} mv "$f.PNG" "$f.png" done
grep -H -r "string I am searching for" *
This should also work
grep -H -r 'string I am searching for' *
also this
find . -type f -exec grep -l 'string' {} \;
find . -name "*.txt" -print0 | xargs -0 egrep 'string'
find . -name "*.txt" -exec egrep -l '^string' {} \;
find . -type f -print0 | xargs -0 grep -H 'documentclass'
find . -type f -name *.tex -print0 | xargs -0 grep -l 'documentclass'
This example looks for all png files in current folder and will make thumbnails (shrink) any image that has a width larger than say 200 pixels. The height of the image is adjusted so that aspect ratio remain the same as originally was.
Edit as needed
#!/bin/bash shopt -s nullglob FILES=*.png for file in $FILES do f=${file%.*} echo "file is $file and f is $f" convert "$f.png[200x>]" "$f"_thumb.png done
This example is as above except that the resizing is limited to enlarging the images to say 200 pixels. Edit as needed
#!/bin/bash shopt -s nullglob FILES=*.png for file in $FILES do f=${file%.*} echo "file is $file and f is $f" convert "$f.png[200x<]" "$f"_thumb.png done
Reference:
Can use the file
command. But the ouptput has to be parsed. easier to use imageinfo
>sudo apt-get install imageinfo #install if needed >w=`imageinfo --width foo.png` >echo $w 81 >h=`imageinfo --height foo.png` >echo $h 24
Reference:
Useful trick to know
convert big.gif -coalesce coalesce.gif convert -size 200x100 coalesce.gif -resize 200x10 small.gif
reference: http://stackoverflow.com/questions/718491/resize-animated-gif-file-without-destroying-animation
Thanks to http://www.turnkeylinux.org/blog/png-vs-jpg
apt-get install imagemagick #one file convert -flatten -background white file.png file.jpg #batch for f in *.png; do n=$(echo $f|sed 's/.png/.jpg/'); convert -flatten -background white $f $n done
Make sure first the windows folder is added to shared folder in VBox settings for the VM. Then boot the VM. Now inside Linux create a mount point where to mount the shared folder to
>sudo mkdir /media/nabbasi >ls -l /media drwxr-xr-x 2 root root 4096 Jun 22 17:02 nabbasi >cd /media >sudo chown -hR me:me nabbasi >ls -l drwxr-xr-x 2 me me 4096 Jun 22 17:02 nabbasi
Now mount the shared folder, making sure it is owned by me
>sudo ./win_mount.sh >cat win_mount.sh mount -t vboxsf -o uid=1000,gid=1000 nabbasi /media/nabbasi
Thanks to http://www.torrent-invites.com/showthread.php?t=194756
sudo apt-get install mencoder mplayer cat *.avi > movie.avi mencoder -forceidx -oac copy -ovc copy movie.avi -o movie_final.avi
This will change all permissions on all files and folder
chmod -R 0755 folder_name
This will change the file, backup is made to INPUT.txt.bak
sed -i.bak '/^#/d' INPUT.txt
the -I {}
is the marker, which says the file name is {}
find . -type f -name INPUT.txt -print0 | xargs -0 -I {} sed -i.bak '/^#/d' {}
The above could also be done like this
find . -type f -name INPUT.txt -print0 | xargs -0 sed -i.bak '/^#/d'
But I found using explicit marker for the argument more clear. This is useful. If using a command that needs more than one argument, the marker is needed anyway, so might as well get used to using it. Marker can be anything. So this works also
find . -type f -name INPUT.txt -print0 | xargs -0 -I file sed -i.bak '/^#/d' file
tree -n -L 1 --charset nwildner
prints one level only and this tree -n -i -L 1 -d .
does not print indentation lines
see http://unix.stackexchange.com/questions/83593/copy-specific-file-type-keeping-the-folder-structure
ulimit -n
to find the limit, and to increase it to say 2048, type ulimit -S -n 2048
Put this in a file foo.php and put it in the folder to unzip the file on the server and type the URL to this file
<?php //phpinfo(); //echo exec('whoami'); $command = "unzip file.zip > /dev/null 2>/dev/null &"; $output = shell_exec($command); echo "<pre>Done !</pre>"; ?>
type unlimt -a
to see all limits. To change open file limit, edit the file
/etc/security/limits.conf
as root and add these lines
* soft nofile 4096 * hard nofile 4096
I rebooted after this just in case (may be reboot is not needed). Now it works. When I do
>ulimit -n 4096
Reference: thanks to lornix answer
Use sudo -E env "PATH=$PATH" command
. Reference
http://superuser.com/questions/709515/command-not-found-when-using-sudo
find /tmp/ -depth -name "* *" -execdir rename 's/ /_/g' "{}" \;
Above is thanks to Dennis Williamson from http://stackoverflow.com/questions/2709458/bash-script-to-replace-spaces-in-file-names
Seems to work well.
tr -d '\015' < file.txt > new_file.txt
Just make sure not to use the same file above, else it will be wiped out.
or just do sudo apt-get install dos2unix
and type dos2unix foo.txt
it will overwrite
the file ok.
Thanks to Avinash Raj, use this command rename 's/.*\s//' *.pdf
see
http://stackoverflow.com/questions/34469075/bulk-file-renaming-in-bash-to-remove-name-with-spaces-leaving-trailing-digits
Install sudo apt-get install djvulibre-bin
. To convert multiple files, I wrote this small
script
#!/bin/bash #dj2pdf.sh script to convert djvu files to pdf set -x for file in $1; do filename=${file%.*} ddjvu -format=pdf -quality=100 "$filename.djvu" "$filename.pdf" done
To convert one file, type dj2pdf file.djvu
and to convert multiple files, type
dj2pdf "*.djvu"
echo "void main(){printf(\"hello world\n\");}" |gcc -x c - -o /tmp/hello;/tmp/hello
thanks to Anderson M. Gomes http://unix.stackexchange.com/questions/270071/how-to-delete-all-files-with-specific-extension-in-specific-named-folders-in-lar
Here is the code
#to check $ find /path/to/source -type d -name 'rules' -exec find '{}' -mindepth 1 -maxdepth 1 -type f -iname '*.pdf' -print ';' #to delete $ find /path/to/source -type d -name 'rules' -exec find '{}' -mindepth 1 -maxdepth 1 -type f -iname '*.pdf' -print -delete ';'
An example,
wget --recursive --no-clobber --page-requisites --html-extension --convert-links --restrict-file-names=windows --domains the_domain_name.com --no-parent http://blabla_blabla
Answers thanks to https://stackoverflow.com/questions/13032701/how-to-remove-folders-with-a-certain-name
cd top_level rm -rf `find . -type d -name folder_name_to_remove`
Or
cd top_level find . -type d -name foo -a -prune -exec rm -rf {} \;
cd top_level find . -name "file_name" -print find . -name "file_name" -delete
This will list all files in tree, showing date file changed with latest changed at bottom of listing shown.
find . -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort
awk '{ if ( length > x ) { x = length; y = $0 } }END{ print y }' ./file.tex
Thanks to Keith Thompson at https://unix.stackexchange.com/questions/24509/how-to-print-the-longest-line-in-a-file
Use
sudo apt install detox detox -n --dry-run * #dry run, to test, does nothing. detox *
This will change all folder names below where it is issued and changes any space in the name to underscore.
To just update a program to its latest without knowing the version number do, say want to update gfortran
sudo apt-get upgrade gfortran
To update the distribution do
sudo apt-get dist-upgrade
To start a command after some time, say 30 minutes do sleep 30m && ./my_script
To start a command after some time, say 2 hrs do sleep 2h && python ./script.py
The above can be canceled before the time elapses, and the command will not run.
Updated Nov 2024
First make sure to select shared folder when installing the Linxu guest using vmware. I
choose G:\public_html\
. This is not done by default. Had to use preference in vmare
workstation to see the shared folder. Do this before installing Linux. Just select the above
folder.
After installing the Linux guest, these are the steps
cd /mnt sudo mkdir -p g sudo mkdir -p g/public_html sudo chown -hR me:me g <--- THis is important. sudo /usr/bin/vmhgfs-fuse .host:/public_html /mnt/g/public_html -o subtype=vmhgfs-fuse,allow_other
The above makes folder /mnt/g/public_html
which maps to G:\public_html
on
windows.
if you get stuck inside Virtual box, type CTRL-ALT to get out to windows.
Make sure to turn off optimize mouse for gamming in setting if mouse is stuck inside virtual machine.
Need to issue the above mount command each time you boot linux.
https://browser.geekbench.com/v6/cpu/8902886 is geek benhc mark for xfce4 linux endouvour os, score is 2823
https://browser.geekbench.com/v6/cpu/8904701 is geek benhc mark for xfce4 linux manjaro os single scroe is 2857
desktop->Applications->Settings->Setting manager->Window manager
and select
them Daloa. THere are other light ones. But I liked this one more.
Make sure you are in vboxsers group
sudo usermod -a -G vboxusers <useruame>
logout and login. Now try to add USB 2.0 to VBox USB in settings of the window virtual machine. It should now be enabled.
in windows DOS, type
net use G: /delete
Where G:
is say the network disk
Made my /home/me/data/
as shared folder in VBox setting. So shared folder shows as data
then.
Booted VBox windows 7. Then in windows typed in DOS
Type net use G: \\vboxsvr\data
So now it shows in windows as derive G
sudo updatedb
then locate file_name
can also use find but locate is faster.
smbclient -L localhost
if it asks for password, type it. It is then running.
lpstat -p
or do http://localhost:631/printers/
and select Printers from the menu. The above is
CUSP interface.
convert 'moving_disk.gif[0]' moving_disk.png
Thanks to https://askubuntu.com/questions/22413/how-to-change-gnome-terminal-title type
PROMPT_COMMAND='echo -ne "\033]0;TITLE HERE\007"'
This will change the title in the terminal banner, normally located in the upper left corner.
To make the terminal title be the full path of the current folder, type
PROMPT_COMMAND='echo -ne "\033]0;$PWD\007"'
To make the terminal title be the last folder in full path of the current folder, type
PROMPT_COMMAND='echo -ne "\033]0;$(basename $(pwd))\007"'
Thanks to http://blog.floriancargoet.com/slow-down-or-speed-up-a-gif-with-imagemagick/
identify -verbose your.gif
grep Delay| give current delay between each frame in 100’th
of second. So it it say 50x100
then the delay is half second. To change the delay to one
second between each frame do
convert -delay 100x100 your.gif your_slow.gif
So to make the time 0.25 second between each frame do
convert -delay 25x100 your.gif your_slow.gif
It looks like 6x100
is min time betweeb frames that browsers support. But this could depend
on which browser.
cd -
goes back to last directory
reset
clears and resets the terminal
apt update
then want to do it again by adding sudo
then no need to
retype everything, just type sudo !!
then the !!
will copy the last command
history
followed by !nn
where nn
is the command number show in history,
will run that command
cmd1; cmd2; cmd3
The above will stop if one of these commands fail. If you
use cmd1&& cmd2&& cmd3
then it will not stop if one command fail. so using ;
is more safe.
command
column t| is useful command to format messy output into columns so
easier to read
use the command find . -type f -mmin -150
to find files that changed within 150
minutes ago. And the command find . -type f -mmin +150
to find files that changed
longer than 150 minutes ago.
on xfce, right click on the desktop->applications->settings manager->windows manager->
then select a theme. The theme Moheli looks good.
Install sysbench
which is avaliable in all installation managers.
Use >sysbench --help
for help. No man pages?
Then do
>sysbench cpu run sysbench 1.0.20 (using system LuaJIT 2.0.5) Running the test with following options: Number of threads: 1 Initializing random number generator from current time Prime numbers limit: 10000 Initializing worker threads... Threads started! CPU speed: events per second: 3983.04 General statistics: total time: 10.0005s total number of events: 39839 Latency (ms): min: 0.23 avg: 0.25 max: 20.25 95th percentile: 0.26 sum: 9943.89 Threads fairness: events (avg/stddev): 39839.0000/0.00 execution time (avg/stddev): 9.9439/0.00
And
>sysbench memory run sysbench 1.0.20 (using system LuaJIT 2.0.5) Running the test with following options: Number of threads: 1 Initializing random number generator from current time Running memory speed test with the following options: block size: 1KiB total size: 102400MiB operation: write scope: global Initializing worker threads... Threads started! Total operations: 74842059 (7482566.83 per second) 73087.95 MiB transferred (7307.19 MiB/sec) General statistics: total time: 10.0013s total number of events: 74842059 Latency (ms): min: 0.00 avg: 0.00 max: 10.37 95th percentile: 0.00 sum: 4017.76 Threads fairness: events (avg/stddev): 74842059.0000/0.00 execution time (avg/stddev): 4.0178/0.00
or
>sysbench --threads=5 memory run sysbench 1.0.20 (using system LuaJIT 2.0.5) Running the test with following options: Number of threads: 5 Initializing random number generator from current time Running memory speed test with the following options: block size: 1KiB total size: 102400MiB operation: write scope: global Initializing worker threads... Threads started! Total operations: 89536061 (8944801.69 per second) 87437.56 MiB transferred (8735.16 MiB/sec) General statistics: total time: 10.0028s total number of events: 89536061 Latency (ms): min: 0.00 avg: 0.00 max: 46.68 95th percentile: 0.00 sum: 27564.97 Threads fairness: events (avg/stddev): 17907212.2000/1640514.61 execution time (avg/stddev): 5.5130/0.11
or
>sysbench --threads=5 cpu run sysbench 1.0.20 (using system LuaJIT 2.0.5) Running the test with following options: Number of threads: 5 Initializing random number generator from current time Prime numbers limit: 10000 Initializing worker threads... Threads started! CPU speed: events per second: 6707.45 General statistics: total time: 10.0036s total number of events: 67111 Latency (ms): min: 0.23 avg: 0.74 max: 56.90 95th percentile: 2.22 sum: 49553.41 Threads fairness: events (avg/stddev): 13422.2000/856.28 execution time (avg/stddev): 9.9107/0.03
And
>sysbench --threads=5 --file_test_mode="seqwr" fileio run sysbench 1.0.20 (using system LuaJIT 2.0.5) Running the test with following options: Number of threads: 5 Initializing random number generator from current time Extra file open flags: (none) 128 files, 16MiB each 2GiB total file size Block size 16KiB Periodic FSYNC enabled, calling fsync() each 100 requests. Calling fsync() at the end of test, Enabled. Using synchronous I/O mode Doing sequential write (creation) test Initializing worker threads... Threads started! File operations: reads/s: 0.00 writes/s: 36.47 fsyncs/s: 101.22 Throughput: read, MiB/s: 0.00 written, MiB/s: 0.57 General statistics: total time: 10.1126s total number of events: 753 Latency (ms): min: 0.00 avg: 66.82 max: 655.80 95th percentile: 337.94 sum: 50315.70 Threads fairness: events (avg/stddev): 150.6000/63.87 execution time (avg/stddev): 10.0631/0.04
To use on windows go to https://github.com/akopytov/sysbench but need WSL to use.
The compiled tests are
ompiled-in tests: fileio - File I/O test cpu - CPU performance test memory - Memory functions speed test threads - Threads subsystem performance test mutex - Mutex performance test
Reference https://linuxconfig.org/how-to-benchmark-your-linux-system
Installed geekbench on Linux Majoaro using the installation manager (from AUR).
Then did
>geekbench --help Geekbench 5.4.5 Tryout : https://www.geekbench.com/ Usage: geekbench [ options ] Options: -h, --help print this message --unlock EMAIL KEY unlock Geekbench using EMAIL and KEY --cpu run the CPU benchmark --sysinfo display system information and exit [0911/024243:WARNING:src/halogen/cuda/cuda_library.cpp(1465)] Cannot find or load CUDA library. [0911/024243:WARNING:src/halogen/cl/opencl_library.cpp(691)] Cannot find or load OpenCL library. [0911/024243:WARNING:src/halogen/vulkan/vulkan_common.h(28)] VulkanException: vkCreateInstance(&info, nullptr, &instance) returned -9 (VK_ERROR_INCOMPATIBLE_DRIVER) If no options are given, the default action is to run the CPU benchmark.
To run the tests did
>geekbench --sysinfo System Information Operating System Manjaro Linux Kernel Linux 5.15.53-1-MANJARO x86_64 Model innotek GmbH VirtualBox Motherboard Oracle Corporation VirtualBox BIOS innotek GmbH VirtualBox Processor Information Name Intel Core i9-12900K Topology 1 Processor, 6 Cores Identifier GenuineIntel Family 6 Model 151 Stepping 2 Base Frequency 3.19 GHz L1 Instruction Cache 32.0 KB x 6 L1 Data Cache 48.0 KB x 6 L2 Cache 1.25 MB x 6 L3 Cache 30.0 MB x 6 Memory Information Size 50.9 GB
Then now run the full test
>geekbench Geekbench 5.4.5 Tryout : https://www.geekbench.com/ Geekbench 5 requires an active Internet connection when in tryout mode and automatically uploads benchmark results to the Geekbench Browser. Buy a Geekbench 5 license from the Primate Labs Store to enable offline use and unlock other features: https://store.primatelabs.com/v5 Enter your Geekbench 5 license using the following command line: geekbench --unlock <email> <key> Running Gathering system information System Information Operating System Manjaro Linux Kernel Linux 5.15.53-1-MANJARO x86_64 Model innotek GmbH VirtualBox Motherboard Oracle Corporation VirtualBox BIOS innotek GmbH VirtualBox Processor Information Name Intel Core i9-12900K Topology 1 Processor, 6 Cores Identifier GenuineIntel Family 6 Model 151 Stepping 2 Base Frequency 3.19 GHz L1 Instruction Cache 32.0 KB x 6 L1 Data Cache 48.0 KB x 6 L2 Cache 1.25 MB x 6 L3 Cache 30.0 MB x 6 Memory Information Size 50.9 GB Single-Core Running AES-XTS Running Text Compression Running Image Compression Running Navigation Running HTML5 Running SQLite Running PDF Rendering Running Text Rendering Running Clang Running Camera Running N-Body Physics Running Rigid Body Physics Running Gaussian Blur Running Face Detection Running Horizon Detection Running Image Inpainting Running HDR Running Ray Tracing Running Structure from Motion Running Speech Recognition Running Machine Learning Multi-Core Running AES-XTS Running Text Compression Running Image Compression Running Navigation Running HTML5 Running SQLite Running PDF Rendering Running Text Rendering Running Clang Running Camera Running N-Body Physics Running Rigid Body Physics Running Gaussian Blur Running Face Detection Running Horizon Detection Running Image Inpainting Running HDR Running Ray Tracing Running Structure from Motion Running Speech Recognition Running Machine Learning Uploading results to the Geekbench Browser. This could take a minute or two depending on the speed of your internet connection. Upload succeeded. Visit the following link and view your results online: https://browser.geekbench.com/v5/cpu/17190798 Visit the following link and add this result to your profile: https://browser.geekbench.com/v5/cpu/17190798/claim?key=464173
The result is
The above was run on Virtual box. It shows it is slow peformance. So I disabled Hyper-V on windows 10. Using instructions given in https://www.wintips.org/fix-virtualbox-running-very-slow-in-windows-10-11/ (make sure to follow all instructions, include issuing the command line and rebooting windows).
In addition to the above, I made sure in VBox setting to use KVM for virtualization. See https://superuser.com/questions/945910/how-to-select-paravirtualization-interface-in-virtualbox
The peformance now is much better.
This is the most stupid and annoying feature in Linux desktop and impossible to find how to turn it off. Googling around, this worked
xfconf-query -c xfwm4 -p /general/tile_on_move -s false
No wonder Linux will never ever make it on the desktop.
awk '{ print length(), NR | "sort -rn" }' index.tex | head -n 1
This prints 2 numbers on the screen. The first number is the actual length and the second number is the line number itself in the file.
Thanks to Attila O. https://askubuntu.com/questions/375832/how-to-get-longest-line-from-a-file
Suppose we wanted to replace text in any line in files in some tree.
Do
#!/bin/bash cd $HOME/my_tree find . -name "fricas_listA.txt"|while read fname; do echo "processing $fname" sed -i 's/algorithm="fricas"/algorithm=""fricas""/g' $fname done
The above replaces algorithm="fricas"
by algorithm=""fricas""
everywhere in all
files called fricas_listA.txt
in the tree. To apply this to all text file, replace
-name "fricas_listA.txt"
by -name "*.txt"
Suppose we wanted to delete all lines that has some word, say window
in them.
Do
#!/bin/bash cd $HOME/my_tree find . -name "*.txt"|while read fname; do echo "processing $fname" sed -i '/windows/d' $fname done
Suppose we wanted to delete only the word window
from any line.
Do
#!/bin/bash cd $HOME/my_tree find . -name "*.txt"|while read fname; do echo "processing $fname" sed -i 's/windows//g' $fname done