Command Line 101

pwd
$ pwdPrint 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/themeChange 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.txtCopy
$ cp example.txt /home/user2/public_html/example-copy.txtmv
$ mv example2.txt theme/example2.txtMove
Rename
$ mv example.txt example-renamed.txtrm
$ rm example3.txtRemove
Remove Directory
$ rm -rf examplemkdir
$ mkdir fooMake Directory
touch
$ touch fooCreate File
nano
Text Editor

cat
$ cat long.txtConcatenate and Print File
head
$ head long.txtDisplay first part of a file
$ tail -n 5 long.txt$ tail long.txt$ head -n 3 long.txttail
Display last part of a file
less
$ less long.txtDisplay File Contents, Paginated
find
$ find . -name "*.js"Find all files with .js extension
$ find . -type f -perm 755Find all files with 755 permissions
$ find . -name respond.jsFind file
grep
$ grep bomp example.txtGlobal Regular Expression Print
$ grep --color=auto bomp example.txt$ grep "bomp bah bomp" example.txtgrep
$ grep -nis bomp example.txtGlobal Regular Expression Print
$ grep -rnis hex2rgb *>
$ grep -nis bomp example.txt > results.txtRedirect Output
|
$ mysqldump <options> | gzip > example.sql.gzPipe Output
man
$ man findManual (Help!)
Shortcuts
~/.bash_profile
SSH
$ ssh -p 2222 root@host.servername.comSSH
Connect
SSH Keys
SSH Keys
Generating Keys
$ ssh-keygenSSH 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.pubMac
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.confRe-run last command with sudo
$ sudo !!Resources
Tools
iTerm2
Terminal App Replacement
Command Line 101
By Adam Walter
Command Line 101
- 2,024