• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Programming / Command Line Cheat Sheet

Command Line Cheat Sheet

Last updated on April 15, 2020 by Sal Ferrarello

I’m not sure why I remember some things so well (Charlie Chaplain died on December 25, 1977) and others just don’t stick (Memorial Day and Labor Day, which one is in Spring and which one is in Fall?).  At some point, I should start recording things I remember easily and things I do not and see if I can find a pattern.

For now, I’m leaving myself these notes online for the command line commands that I use often but not often enough to remember ( these are all for Mac / *nix machines ).

tmux

Open existing session named “main” if it exists, otherwise create it.

tmux a -t main || tmux new -s main

Find

find /path -name 'filename_w_wildcards'
(see Command Line Find)

DNS Lookup

dig www.example.com @b.iana-servers.net A
(lookup A record for www.example.com on name server b.iana-servers.net)
See more details about using dig for DNS Lookups

Find Local IP Address on Wireless Network

ipconfig getifaddr en1
See more details about finding your local IP address

Search All Files in the Current ( and sub ) Directories

grep -i -r 'needle' ./

Search and Replace Over Multiple Files ( Current and Sub Directories )

find . -name "*.php" -type f -exec perl -p -i -e "s/Plugin_Name/Html_On_Cpt/g" {} \;
Find all files in the current ( and sub ) directories that end in .php and replace “Plugin_Name” with “My_Plugin_Name”

Change Directory to Previous Directory

cd -

Run the Last Command Again ( but now as root )

sudo !!

Moving Around on the Command Line

CTRL+a Move to beginning of line
CTRL+e Move to end of line
ESC,f Move forward one word
ESC,b Move backward one word

List all subfolders with formatted output

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
From: http://reviews.cnet.com/8301-13727_7-10402034-263.html

To Add

curl
wget

 

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit

Filed Under: Programming

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in