Last active
January 29, 2021 18:47
-
-
Save jonashackt/52c7ab203d93fc6293ff9ef8534c3148 to your computer and use it in GitHub Desktop.
Linux cheatsheet (Ubuntu)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 0. need root access to system | |
#### Show environment variables | |
printenv | |
#### Set env var | |
export FOO=BAR | |
#### Set env var for root | |
# sudo export FOO=BAR doesnt work! (see https://askubuntu.com/questions/272637/i-have-a-problem-when-using-export-command) | |
# change to root first | |
sudo -s | |
export FOO=BAR | |
#### check Linux distro | |
cat /etc/os-release | |
#### check Ubuntu version | |
lsb_release -a | |
#### Add User with sudo priviledges | |
# Add user | |
adduser tom | |
# Add Password to new user | |
passwd tom | |
# Add sudo priviledge to tom | |
# 1st make sure, in file /etc/sudoers there´s the following lines: | |
# Allow members of group sudo to execute any command | |
%sudo ALL=(ALL:ALL) ALL | |
# create sudo group with | |
groupadd sudo | |
# Add user tom to sudo group | |
usermod -aG sudo tom | |
sudo adduser <username> sudo | |
#prevent sudo from promting for password, add following file /etc/sudoers.d/sudoers with line: | |
%sudo ALL=NOPASSWD: ALL | |
#### Install apt-get | |
wget http://security.ubuntu.com/ubuntu/pool/main/a/apt/apt_1.0.1ubuntu2.17_amd64.deb -O apt.deb | |
# Resource-Mgt | |
### get processors count | |
grep -i "physical id" /proc/cpuinfo | sort -u | wc -l | |
### get RAM size | |
free | |
# or | |
cat proc/meminfo | |
### get directory size | |
du -sh /my/directory | |
# show free space | |
df -h /my/directory | |
### Debug / Identify Upstart Errors | |
cat /var/log/syslog | |
## Alpine | |
#### install curl | |
apk --no-cache add curl | |
# show process that uses specific port | |
netstat -vanp tcp | grep 8080 | |
# DNS lookup | |
dig jonashackt.io | |
# show last added txt records | |
dig _acme-challenge.gitlab.jonashackt.io txt | |
# Recursively copy directory incl. contents from remote machine to local & preserve permissions, times, modes etc. | |
scp -rp [email protected]:/opt/foo/bar/path/yourDirectory /home/jonashackt/Downloads/ | |
# Pack archives | |
tar czf name_of_archive_file.tar.gz name_of_directory_to_tar | |
# Unpack | |
tar -xzvf name_of_archive_file.tar.gz | |
tar -xvf name_of_archive_file.tar | |
### Pass Variables to Bash Script | |
https://www.baeldung.com/linux/use-command-line-arguments-in-bash-script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment