Basic Shell/Unix Commands

I get rusty from time to time and need a quick tutorial to get myself back into the tech game. This reference doc is fairly basic but saves me the trouble of having to google (which doesn't work in China) other reference websites or Stackoverflow.

Create A New File

Create an empty file with just a file name, use touch

touch README.md

Find A File or Directory

Find a file or directory in the current path, use find

find . -name 'README.md' 

Check Directory Size

Use du to find out the size of a directory pelican

du -sh pelican

To find out the size of each subdirectory in pelican

du -h pelican

Remove Directory

rm -rf mydirectory

Use PATH Variable

Display current PATH

echo $PATH

Add a new path to system variable PATH

export PATH=/usr/local/mysql/bin:$PATH

Download File

curl -O some_URL_address_for_download_file

Copy File Between Server and Local Machine

From server to local

scp xx.xx.xx.xx:some_directory/some_file_name .

From local to server

scp some_file_name xx.xx.xx.xx:some_directory/

Use rsync is arguably a superior way of doing just the same

rsync -avP some_file_name xx.xx.xx.xx:some_directory/
rsync -avP xx.xx.xx.xx:some_directory/some_file_name .

Use Nix as Package Manager

Install Nix

curl https://nixos.org/nix/install | sh

Upon Installation finished!, follow the on-screen instruction:

. /home/userjoe/.nix-profile/etc/profile.d/nix.sh

Search for a package mySQL on Nix

nix-env -qa | grep mysql

Install the package

nix-env -i mysql-5.7.17

or

nix-env --install mysql-5.7.17

Uninstall the package

nix-env --uninstall mysql-5.7.17

or

nix-env -e mysql-5.7.17

Open help

nix-env --help

To show installed packages

nix-env -q

To show available packages

nix-env -qas
Go Top
comments powered by Disqus