Unix CLI cookbook
Download assets from a list of URLs saved in a file
wget --report-speed=bits -i {path-to-file}
Or, for non-verbose mode, use the -nv
flag:
wget -nv --report-speed=bits -i {path-to-file}
Add execute permissions to a file
chmod u+x {target-file}
Note that the combination of u+x
will grant execute permissions to the file owner only, not to Group
or everyone
.
This command is particularly useful when enabling a shell script for execution.
Create a symlink
ln -s /path/to/file /path/to/symlink
Empty the contents of a file
In terminal, use this command:
cp /dev/null target-file
List the contents of a directory by creating a visual representation of the folder tree
tree -L {number} -I {"exclude-path-1|exclude-path-2"} {directory to list}
The -L
flag sets the depth of the folder tree; the -I
flag excludes one or more directories from listing. By default tree
lists the current directory, so if a listing of ./
is needed there's no need to provide a target directory argument.
tree -L 2 -I "dir1 | dir2" ./
Append text to a file
In terminal, use the cat
command with the >>
operator:
cat input-file.txt >> append-target.txt
The text will be appended at the end of the target file.
Prepend text to a file
cat ../../yaml/docset-front-matter.yml | cat - $file > tmp; mv tmp $file
Explanation:
# - Concatenate several files into the target file:
# cat file1 file2 > target_file
Sources
List all volumes
diskutil list
Iterate over files
for file in *.txt; do
mv $file $file.md
done
Sources
Generate a user-password pair with htpasswd
In a shell, use this command:
htpasswd -c -B .filename username