Command Line 101
pwd
$ pwd
Print Working Directory
ls
$ ls
./ ../ example.txt hobbit.txt theme/
$ ls -alh
total 48
drwxr-xr-x@ 5 vitaldesign 501 170B Jun 23 15:45 ./
drwx------+ 11 vitaldesign 501 374B Jun 25 16:08 ../
-rw-r--r--@ 1 vitaldesign 501 1.3K Jun 23 15:26 example.txt
-rw-r--r--@ 1 vitaldesign 501 19K Jun 23 15:29 hobbit.txt
drwxr-xr-x@ 28 vitaldesign 501 952B Jun 23 15:45 theme/
List Files
cd
$ pwd
/Users/vitaldesign/Desktop/bash101
$ cd theme
$ pwd
/Users/vitaldesign/Desktop/bash101/theme
Change Directory
cd
$ cd ..
Change Directory
$ cd -
$ cd ~
$ cd /
Move up one directory
Move back to last directory
Move to user's home directory
Move to server's root directory
Paths
$ find . -name "wp-config.php"
.
Current Directory
Paths
$ find / -name "wp-config.php"
/
Server Root
$ find /home/madeb9/public_html -name "wp-config.php"
Paths
$ find ~ -name "wp-config.php"
~
User Home
$ find ~/public_html -name "wp-config.php"
cp
$ cp example.txt example-copy.txt
Copy
$ cp example.txt /home/user2/public_html/example-copy.txt
mv
$ mv example2.txt theme/example2.txt
Move
Rename
$ mv example.txt example-renamed.txt
rm
$ rm example3.txt
Remove
Remove Directory
$ rm -rf example
mkdir
$ mkdir foo
Make Directory
touch
$ touch foo
Create File
nano
Text Editor
cat
$ cat long.txt
Concatenate and Print File
head
$ head long.txt
Display first part of a file
$ tail -n 5 long.txt
$ tail long.txt
$ head -n 3 long.txt
tail
Display last part of a file
less
$ less long.txt
Display File Contents, Paginated
find
$ find . -name "*.js"
Find all files with .js extension
$ find . -type f -perm 755
Find all files with 755 permissions
$ find . -name respond.js
Find file
grep
$ grep bomp example.txt
Global Regular Expression Print
$ grep --color=auto bomp example.txt
$ grep "bomp bah bomp" example.txt
grep
$ grep -nis bomp example.txt
Global Regular Expression Print
$ grep -rnis hex2rgb *
>
$ grep -nis bomp example.txt > results.txt
Redirect Output
|
$ mysqldump <options> | gzip > example.sql.gz
Pipe Output
man
$ man find
Manual (Help!)
Shortcuts
~/.bash_profile
SSH
$ ssh -p 2222 root@host.servername.com
SSH
Connect
SSH Keys
SSH Keys
Generating Keys
$ ssh-keygen
SSH Keys
Adding to Remote Server
Append to authorized_keys (file already exists)
$ cat ~/.ssh/id_rsa.pub | ssh user@123.45.56.78 'umask 077; cat >> ~/.ssh/authorized_keys'
Create .ssh/authorized_keys and add key (brand new server)
$ cat ~/.ssh/id_rsa.pub | ssh user@123.45.56.78 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
SSH Keys
Adding to Remote Server (cPanel)
$ pbcopy < ~/.ssh/id_rsa.pub
$ cat ~/.ssh/id_rsa.pub
Mac
Windows
Copy key to clipboard
SSH Keys
Adding to Remote Server (cPanel)
SSH Keys
Adding to Remote Server (cPanel)
SSH Keys
Adding to Remote Server (cPanel)
SSH Keys
Adding to Remote Server (WHM/root user)
Follow same procedure as cPanel, starting here:
SSH
Configuration
$ ssh dev
SSH
Configuration
Host nickname
Hostname server.example.com
IdentityFile ~/.ssh/id_rsa
User username
Port 1234
$ ssh nickname
~/.ssh/config
SSH Keys
Adding to GitHub
sudo
Super User Do
Allows any user to run commands as root
$ sudo nano /etc/httpd/conf/httpd.conf
Re-run last command with sudo
$ sudo !!
Resources
Tools
iTerm2
Terminal App Replacement