Updated: 17 May 2023
Delete all contents from a file
cat /dev/null > the.file
# or
echo -n > the.file
Jersey & Guernsey, United Kingdom
Updated: 17 May 2023
Delete all contents from a file
cat /dev/null > the.file
# or
echo -n > the.file
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