-
Notifications
You must be signed in to change notification settings - Fork 0
Useful Ubuntu Commands
sudo update-alternatives --config editor
Checking and adding environment variables.
printenv
printenv HOME
echo $HOME
printenv PATH
echo $PATH
printenv HOME PATH
# replace my username with yours in the command below
export PATH="/home/shamik/.local/bin:$PATH"
In order to configure a new environment variable to be persistent, we’ll need to edit the Bash configuration files. This can be done through three different files, depending on exactly how you plan to access the environment variable.
-
~/.bashrc
– Variables stored here will reside in the user’s home directory and are only accessible by that user. The variables get loaded any time a new shell is opened. -
/etc/profile
– Variables stored here will be accessible by all users and are loaded whenever a new shell is opened. -
/etc/environment
– Variables stored here are accessible system-wide.
# replace my username with yours in the command below
export PATH="/home/shamik/.local/bin:$PATH"
# replace my username with yours in the command below
export PATH="/home/shamik/.local/bin:$PATH"
# replace my username with yours in the command below
PATH="/home/shamik/.local/bin:$PATH"
rm -r <path of the folder>
This happens because of the number of files being too many so the following will work:
find <path of the folder> -type f -exec rm {} +
find <path to dir> -type f ! \( -name "<file extension>" -o -name "<file extension>" \)
# find ./testing_metrics/ -type f ! \( -name "*.csv" -o -name "*.parquet" \)
find <path to dir> -type f ! \( -name "<file extension>" -o -name "<file extension>" \) -delete
# find ./testing_metrics/ -type f ! \( -name "*.csv" -o -name "*.parquet" \) -delete
zip –rj <zipped folder path> <path to the folder>
zip –rju <zipped folder path> <path to the folder>
zip <zipped folder path> <file1> <file2> <file3> <file4>
unzip <file name>
unzip <file name> -d <path to the directory>
unzip –Z <folder name>
tar -cvzf <path/where/to/save/the/zipped.tar.gz> <path to dir>
# tar -cvzf roberta-large-iter2-v2.tar.gz roberta-large-iter2-V2/
tar –cvzf <path/where/to/save/the/zipped.tar.gz> -C <folder/path/> .
# tar -cvzf Data/FS\ Data/original_models_threshold_analysis.tar.gz -C Data/FS\ Data/threshold_analysis/ .
tar -cvzf <path/where/to/save/the/zipped.tar.gz> -C <file path>
# tar -cvzf Repos/iTOP-semantic-apply-model/notebooks/Concepts_Filtered_df.tar.gz -C ~/Repos/iTOP-semantic-apply-model/notebooks/ Concepts_Filtered_df.csv
It compresses the file even more than gzip.
tar -cjvf <path/where/to/save/the/zipped.tar.bz2> -C <file path>
# tar -cjvf ~/Repos/iTOP-semantic-apply-model/notebooks/final_df.tar.bz2 -C ~/Repos/iTOP-semantic-apply-model/notebooks/ final_df.csv
tar -xvzf <tar file> -C <path to extract>
# tar -xvzf roberta-large-iter2-v2.tar.gz -C roberta-large-iter2-V2/
wget -P </path/to/directory> <http://example.com/path/to/file>
sudo chown <owner>:<group> <filepath>
# sudo chown shamik:shamik abc.txt
sudo lsblk
Generally sda
will be the boot disk and if you have only one disk, which can be attached then it will be sdb
. However, if you have multiple disks, which can be attached it will be autoincremented to sdc
,sdd
,... In case you detach and then re-attach the disk then the disk name will be autoincremented too e.g., for sdb
it will become sdc
as there's only one disk.
sudo mkdir /mnt/disks/<name of your choice>
sudo mount -o discard,defaults /dev/sdb /mnt/disks/<name of your choice>
- Install Ghostscript with the command
sudo apt install ghostscript
. - Once installed, you can use this command to compress PDF file sizes:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
- In the command, replace output.pdf and input.pdf with your chosen filenames. The
dPDFSETTINGS
is where you’ll choose the file size. Change the suffix=/screen
to suit your needs:
-
-dPDFSETTINGS=/screen
— Low quality and small size at 72dpi. -
-dPDFSETTINGS=/ebook
— Slightly better quality but also a larger file size at 150dpi. -
-dPDFSETTINGS=/prepress
— High quality and large size at 300 dpi. -
-dPDFSETTINGS=/default
— System chooses the best output, which can create larger PDF files.
- Once you input your preferences, simply run the command. Your new compressed PDF will be saved in the same folder as the original.
find ./ -name '*.pdf' -exec sh -c 'pdftotext "{}" - | grep --with-filename --label="{}" --color "pattern"' \;