Updated: 04 October 2024
Create a gzip file of backup.sql and keep the original file
gzip --keep backup.sql
Decompress an archive
gzip -d backup.sql.gz
Freelance software engineer United Kingdom
Updated: 04 October 2024
Create a gzip file of backup.sql and keep the original file
gzip --keep backup.sql
Decompress an archive
gzip -d backup.sql.gz
Updated: 27 May 2023
List, test and extract compressed files in a ZIP archive
Unzip a zip file
unzip wordpress-seo-premium-20.8.zip
Updated: 17 May 2023
Delete all contents from a file
cat /dev/null > the.file
# or
echo -n > the.file
Updated: 18 March 2024
Zip a file
zip -r curl-debug-wp-plugin.zip ./curl-debug-wp-plugin --exclude '*.git*'
Zip a folder without including the root folder
zip -rj ctd-wp-theme.zip ./ctd-wp-child-theme
Updated: 04 June 2023
rm – remove files or directories.
Delete file, skip warning if file doesn’t exist
rm -f app.js
Empty a directory
rm -r /my/directory/*
Updated: 11 January 2023
Get full path of a file (file does not need to exist)
readlink -f file.txt
Updated: 01 November 2023
List contents of directories in a tree-like format.
Install
sudo apt install tree
Ignore .git folder but show other dot folders/files, starting from current directory
tree -I .git -a .
Also show user, group and file permission
tree -ugp dir
Create tree 2 levels deep only
tree -L 2 .
Updated: 16 November 2023
Show only directories matching glob, but not their contents
ls -d /a/path/foo*
Show first 7 rows only
ls | head -7
Order by date
ls -t
Order by date, most recent at bottom
ls -tr
List all files in a directory and sub-directories
ls -R
List directories first (tab completion possible)
ls -l --group-directories-first
List filename only, in one column
ls -1
Turn on colour
ls --color=always -la