Last active
May 28, 2020 16:28
-
-
Save markus2610/c5c1796482e770ccd5904081601f84d1 to your computer and use it in GitHub Desktop.
Just basic commands I often forget
This file contains hidden or 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
[[ -f ~/.ssh/id_rsa ]] && echo exists #Test if a file exists | |
[[ -d ~/.ssh ]] && echo exists #Test if a directory exists | |
[[ $@ == *"--arg1"* ]] && echo exists #Test if text is present in string | |
git log --cherry -p HEAD...SOURCE #See how merge will be done | |
git reset 55b0788 #Move/reset HEAD to that commit | |
rm -rf src && git checkout 55b0788 #Git revert like | |
ls -lah #List files with size in MB | |
du -hcs directory_here #Show directory size in MB | |
cat *.txt > concatenatedFile.txt #Concatenate | |
wget -c http://address.com #Download with continue | |
ln -sf /from /to #Creates a symlink | |
any_program 2> error.log #Redirect errors | |
sleep 10 & echo $! #Echo background PID | |
echo $? #Echo last exit code | |
mkfifo /tmp/named_pipe && <command> < <(tail -f /tmp/named_pipe) #Creates a tunnel wich allow us to send inputs to a command | |
echo "Tell your name" && read nameVar #Allow user to input things into variable | |
mkfs.exfat /dev/sdX1 #Make sure you have run sudo apt-get install exfat-utils exfat-fuse | |
cat << EOF > ./file #Compile text then write | |
My directory is `pwd` | |
EOF | |
cat << 'EOF' > ./README #Write text as is | |
echo `pwd` | |
EOF | |
grep -n "foo" bigFile.log #Search for the word 'foo' | |
grep -m1 -n "foo" bigFile.log #Stops in the first match (good for streams) | |
echo "column1 column2" | awk '{ print $2 }' #Print second column | |
echo '123456' | sed 's/123//g' #Will print 456 | |
perl -0777 -i -pe 's/123456/123/g' filename #Easy file replace (note: could also be 's~123456~123~g') | |
tail -f file.log #Print file to the console as it gets bigger | |
tail -n 160 file.log #Print last 20 lines of a file | |
unzip "*.zip" #Uncompress all .zip files | |
tar -zxvf files.* #Uncompress tar files | |
tar -zcvf result.tar file1 file2 file* #Compress file1, file2, file... into result.tar | |
zip -r result.zip directory #Zip directory into result.zip | |
htop #Show cpu usage | |
fuser -k 8080/tcp #Kill process running on port 8080 | |
lsof -ti tcp:8080 | xargs kill > /dev/null #Kill process running on port 8080 (Works on MAC) | |
lsof -i :<port> #Is port open | |
lsof -Pn -i4 | grep LISTEN #Show open ports, -i4 means only show ipv4 address and ports -P and -n fast output | |
nmap www.google.com #Show external host ports | |
lsblk -f #Show info about partitions | |
while ! nc -z HOST 5432; do echo 'Waiting connection' && sleep 1; done; #Keep testing until port is available | |
sudo ln -sf /absolute/file /usr/bin/file #Creates a symlink | |
sudo docker kill $(sudo docker ps -q) #Kill all docker containers | |
sudo docker rm $(sudo docker ps -a -q) #Delete all stopped containers | |
sudo docker rmi $(sudo docker images -q) #Remove all images | |
docker stats $(docker ps --format={{.Names}}) #Show resource usage by container name | |
cd `docker volume inspect --format "{{.Mountpoint}}" volumeName` #CD into directory data | |
for name in $(sudo docker ps --format={{.Names}}); do echo "`docker inspect $name | grep Type` $name"; done | |
ssh root@remote_host #SSH login remote host | |
ssh -NL 5601:localhost:5601 root@remote_host #SSH tunneling - This command let you connect to remote ports through ssh | |
ssh -NR 8080:localhost:8080 root@remote_host #SSH tunneling - Tunnel MY port TO remote host | |
scp -r local_path root@destination_host:destination_folder #Copy files [localhost -> remotehost] | |
scp -r root@remote_host:remote_path local_destination #Copy files [localhost -> remotehost] | |
ssh-copy-id root@remote_host #Adds your id on remote host | |
mount --bind /media/drive_example /to/any/path #Binds a media drive to anywhere on file system | |
pulseaudio -k #Kills pulseaudio | |
cat /etc/*-release #Discover linux distribution |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment