Skip to content

Instantly share code, notes, and snippets.

@maxcollombin
Last active August 30, 2023 10:18
Show Gist options
  • Save maxcollombin/81c1b5b6f6023e3166750a314e6318c5 to your computer and use it in GitHub Desktop.
Save maxcollombin/81c1b5b6f6023e3166750a314e6318c5 to your computer and use it in GitHub Desktop.
Useful linux commands

useful linux commands

download all the files listed in a csv file:

wget -i filename.csv

find a file by name

find ~/ -name "filename.txt"

Get the size of a folder

du -h <folder_name>

Download all the files of a folder of an url:

wget --recursive --no-parent <url_folder_name>

Make a linux script executable

chmod +x myscript.sh

Use WSL in the terminal (Windows PowerShell)

wsl -d Ubuntu-22.04

Images optimization

  • jpeg:jpegtran -optimize -progressive -outfile output.jpg input.jpg
  • png: optipng -o7 input.png

Extract the contents of all archives into the current directory

for file in *.zip; do unzip -q "$file" -d "${file%.*}"; done

List all the folder of a directory

ls -d */ -1

Write a directory structure into a text file

tree > output.txt

Other useful commands

Command Description
pwd Print the current working directory.
ls List files and directories.
cd [directory] Change the current directory.
cd .. Move to the parent directory.
cd ~ Move to the home directory.
mkdir [directory] Create a new directory.
rm [file] Remove a file.
rm -r [directory] Remove a directory and its contents recursively.
cp [source] [destination] Copy files and directories.
mv [source] [destination] Move or rename files and directories.
cat [file] Display the contents of a file.
head [file] Display the first few lines of a file.
tail [file] Display the last few lines of a file.
less [file] View a file with pagination.
touch [file] Create an empty file or update the modification timestamp.
chmod [permissions] [file] Change the permissions of a file or directory.
chown [owner] [file] Change the owner of a file or directory.
chgrp [group] [file] Change the group ownership of a file or directory.
grep [pattern] [file] Search for a pattern in a file.
grep -r [pattern] [directory] Search for a pattern in files recursively.
find [directory] -name [filename] Search for files by name in a directory.
sort [file] Sort lines in a file.
wc [file] Count lines, words, and characters in a file.
tail -f [file] Continuously display the last lines of a file (useful for log files).
ps Display running processes.
ps aux Display detailed information about running processes.
top Monitor system processes in real-time.
kill [PID] Terminate a process by its process ID.
killall [process_name] Terminate all processes with a specific name.
ping [host] Send ICMP echo requests to a host.
nslookup [host] Perform DNS lookup for a domain name.
wget [URL] Download files from the web.
curl [URL] Transfer data to or from a server using various protocols.
ifconfig Display network interface configuration (deprecated, use ip command instead).
ip addr show Display IP addresses and network interfaces.
netstat Display network connections, routing tables, and network interface statistics.

compute and check SHA256 message digest

allows to check the integrity of a file

sha256sum -c checksums.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment