Skip to content

Commit 5b7d6e3

Browse files
committed
initial commit
1 parent a0f64e7 commit 5b7d6e3

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Bash Alias and Function
2+
3+
This project contains useful bash aliases and functions. Bash aliases are essentially shortcuts that save you from having to remember long commands and save you a lot of typing when working on the command line.
4+
5+
To make the alias or function persistent you need to declare it in the ~/.bashrc file. If you want to make your ~/.bashrc more modular, you can store your aliases in a separate file. Some distributions, such as Ubuntu and Debian, include a ~/.bash_aliases file that is referenced in ~/.bashrc.
6+
7+
Pick the shortcuts you are interested in and copy the code into one of the files mentioned above.
8+
9+
## Run alias commands as root
10+
11+
Alias definition:
12+
```
13+
sudo='sudo '
14+
```
15+
16+
Usage:
17+
```
18+
sudo <youralias>
19+
```
20+
21+
How it works:
22+
If the last character of the alias value is a blank, then the next command word following the alias is also checked for alias expansion.
23+
See <https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html?ref=linuxhandbook.com#Aliases>.
24+
25+
## Mount iso file
26+
27+
Alias definition:
28+
```
29+
function mount.iso() {
30+
# $1: the iso file
31+
if [ $# -eq 1 ]; then
32+
sudo mkdir -p /media/iso
33+
sudo mount -o loop -t iso9660 "$1" /media/iso
34+
else
35+
echo Usage: mount.iso \<iso-file\>
36+
fi
37+
}
38+
function umount.iso() {
39+
sudo umount /media/iso
40+
sudo rmdir /media/iso
41+
}
42+
```
43+
44+
## Convert video files
45+
46+
Convert MP4 files to MP3 files:
47+
```
48+
alias convert.mp42mp3='for f in *.mp4; do ffmpeg -i "$f" "${f%.mp4}.mp3"; done'
49+
```
50+
51+
Convert MOV files to MP4 files
52+
```
53+
alias convert.mov2mp4='for i in *.mov; do ffmpeg -i "$i" -vcodec h264 -crf 30 -acodec aac "${i%.mov}_new.mp4"; done'
54+
```
55+
56+
Convert high quality MP4 files to MP4 files with lower quality:
57+
```
58+
alias convert.mp42mp4='for i in *.mp4; do ffmpeg -i "$i" -vcodec h264 -crf 30 -acodec aac "${i%.mp4}_new.mp4"; done'
59+
```
60+
61+
## Download m3u8 file
62+
63+
```
64+
function download.m3u8 {
65+
# $1: m3u8 url
66+
# $2: output filename
67+
if [ $# -eq 1 ]; then
68+
cd ~/Downloads
69+
ffmpeg -protocol_whitelist file,http,https,tcp,tls,crypto -i "$1" -c copy "$2"
70+
else
71+
echo Usage: download.m3u8 \<m3u8-url\> \<output-file\>
72+
fi
73+
}
74+
```
75+

0 commit comments

Comments
 (0)