helpful terminal commands
Working as a programmer, your should be using terminal commands at some point in your day.
Here's a list of some useful terminal commands to speed up your work.
The Basics
Lets recap the basics that everyone should be familiar with.
mkdir NAME .. cd NAME .. touch file.txt .. echo "some text..." > file.txt .. ls -lah .. cat file.txt .. cp path/from path/to .. rm -rf path/to/file.txt .. clear
Use touch to create a new file or update a file's date/time.
And echo "some text..." > file.txt to write data to that file.
Use ls to list files, add the -lah to get hidden files and file sizes in a human format.
Use cat to get the contents of a file, for large files your better off using tail.
Copy a file with cp, adding from location and to location.
Delete a file with rm -rf, add the flags to do it forcefully and recursively.
To much info, clear the screen with clear. OSX users can use CMD+K, works also.
Tail
tail -n 100 path/to/file.txt tail -f path/to/file.txt
Delete a process
ps aux kill -9 PID
Once you have the PID, use kill -9 to stop that process immediately. If your wondering why -9, stackoverflow.com/a/9951578 .
The Magic of GREP
Grep is useful for filtering output to only get what you need. It is an incredible powerful tool.
ps aux | grep node ls -l | grep Oct ... cmd | grep WHAT
With grep, you can also filter thru entire directories using grep -r 'text_goes_here' path_goes_here to find that one file your looking for.
Need to exclude files? Use --exclude={*.zip,*.txt}.
Or try grep -rnw . -e 'text_to_find to find files.
Read the manual (gnu.org/software/grep/manual/grep.html ) for all the details.
Compressing Files (.zip
/ .tar)zip -r package.zip . -x "*.DS_Store" tar cfv filename.tar *
tar is similar when zip is not installed.
directory loops
With a for loop, you can apply a command to a list files.
for i in *; do echo "cmd ${i}"; done;
Replace the do echo "cmd ${i}" with anything you want.
Connection snitch
lsof -i | grep -E "(LISTEN|ESTABLISHED)"
Networking Help
ping remoteserver ifconfig
Aliases in zsh
vi .zshrc ... alias ll='ls -lsha' printfn() { echo $1 }
And if you can't remember something, use history to get past commands and !LINE to recall one.