Linux

Some useful apps:

  • ranger – file browser
  • mc – file browser
  • youtube-dl – YouTube downloader
  • ncdu – disk usage
  • neofetch – sys info
  • hollywood – just for fun
  • cmatrix – just for fun
  • tmux – terminal multiplexer
  • fzf – fuzzy finder
  • calcurse – calendar

*. cygwin, switch path
cd /cygdrive/C/…

*. ssh connect
ssh -i key.pem user@address
ssh -i key.pem ubuntu@192.168.0.5
ssh 192.168.0.99 -l admin

*. upload/download file via ssh
scp -i key.pem file.zip user@address:path
scp -i key.pem user@address::file.zip .
scp -i key.pem index.zip ubuntu@192.168.0.5:/home/ubuntu/
scp -i key.pem ubuntu@192.168.0.5:/home/ubuntu/tmpfile.tar.gz .

*. create ssh access with a public/private key
test -f ~/.ssh/id_rsa.pub || ssh-keygen -t rsa #press enter twice if given prompts, then “ssh-add”
scp ~/.ssh/id_rsa.pub admin@10.0.1.198:/tmp/ #type password
ssh admin@10.0.1.198 #type password
cat /tmp/id_rsa.pub >> ~/.ssh/authorized_keys
rm /tmp/id_rsa.pub

*. find file
find . -name testfile.txt
find /home -name *.jpg

*. Apache logs (Ubuntu):
tail -f /var/log/apache2/access.log
tail /var/log/apache2/access.log
tail /var/log/apache2/error.log

*. create fetch file in dcmimport folder:
for i in *; do touch FETCHI$i.SEM; done

*. Finding the Top 5 Big Files
find . -type f -exec ls -s {} \; | sort -n -r | head -5

*. How to create a compressed tar.gz file from multiple files and folders in Linux?
tar -czf new-tar-file-name.tar.gz file1 file2 folder1 folder2
tar -xzf tar-file-name.tar.gz

*. check free space
df -h

*. folder size
du -hs /path/to/folder
du -h –max-depth=1 /path/to/folder
du –max-depth=1 /path/to/folder | sort -nk1
du -hsc *

*. delete directory
rm -rf dir

*. find file older then 100 days
find . -mtime +100

*. delete files older then 100 days
find . -mtime +100 -exec rm {} \;

*. recursive user of grep
grep -r “string” /some/path

* restart mysql
sudo service mysql restart

* start mysql
mysql -u root -p
mysql> use database;

* restart apache
sudo /etc/init.d/apache restart

* check listening port
sudo netstat -nap | grep :5000 | grep LISTEN

* git on NAS stogare
– on the server (via ssh):
git init –bare Project_1.git

– on a client:
cd /cygdrive/D/Projects/
git config –list
git clone admin@nas_address:/share/git/Project_1.git
git status
git add …
git commit -m “…”
git push
git pull

some useful tips (mostly for myself)