Skip to content

Instantly share code, notes, and snippets.

@raviwu
Last active April 3, 2016 03:49
Show Gist options
  • Save raviwu/82008698ce30499ab36b to your computer and use it in GitHub Desktop.
Save raviwu/82008698ce30499ab36b to your computer and use it in GitHub Desktop.
notes for command line tools

Basic tools

See Usage of specific command: man

man command checks out the manual for the command, for instance use man echo to see the description of the echo command.

Commen quit from mass or manufal windows

Use q to quit the manual mode, normally q works for the similar mode entered by other command like ri Array.

Use ctrl + C to kill current exucution of code, break the unfinit loop, etc.

Use echo "some string" > file.txt to through "some string" to "file.txt". use echo "another thing" >> file.txt to concat the "another string" into the "file.txt". By default echo appends \n to the end of the string.

Simple output of a file: cat

Output the file content on the command line use cat command.

cat file_1.txt file_2.txt > combined_file.txt can pass the file_1.txt and file_2.txt content to the combined_file.txt.

Inspecting a file

head file_name.txt list the first 10 lines of a file

tail file_name.txt list the last 10 lines of a file

wc file_name.txt list the "line counts", "word counts", and "bytes" of the file

less file_name.txt has /search_word function to inspect the file less wiki page

View the files within directory: ls

ls -l list out files in long format

ls -la list out all files in long format, including the hidden files

ls -rtl list out files in long format, with reversed order by recent modify time.

ls -lh list out files in long format, with human readable file size count (K instead of bytes).

File manipulation: mv, rm, cp, diff

mv file_a.txt file_b.txt rename file_a.txt to file_b.txt

rm file_a.txt remove file_a.txt rm -rf file_a.txt force remove file_a.txt

cp file_a.txt file_b.txt copy file_a.txt to file_b.txt

diff file_a.txt file_b.txt to show the difference between two file. There won't be output if the two files has no difference.

Check if programme installed: which

which ruby checks whether ruby is installed in the computer

user grep to catch the specified string in file

grep -i string file.txt means catch all case insensitive "string" in "file.txt"

grep string file.txt | wc pipes the result of grep and pass it to wordcount programme

grep -ri string directory can find string from the very deep level, starts from the directory, case insentitive

managing process status with ps

ps aux | grep string in processes status shows in aux options and pipe result to grep then grep the "string" form ps aux result

kill -15 <pid> to kill the individual process with process id

pkill -15 -f spring can kill all process contains string spring

directories

home directory is normally /Users/username/ alias ~/

use sudo command to get root permission for operation

mkdir to make new directory

pwd to print current working directory

find . -name '*.txt' to find files whose names match the pattern *.txt, starting in the current directory . and then in its subdirectories

open file.ext will open the file.ext with default programe to the .ext files

open . will then execute finder and open current directory

combining commands in single line

command line1 ; command line2 ; command line 3 use ; to combine three commands in single line, and execute the three commands one after another

command line1 && command line2 && command line3 works similar as ; seperator, using && can make the following command execute only if previous command successfully executed.

Configure the shell

edit .zshrc file with the resired configs and save it

source .zshrc to reload the config

.bashrc is the config file for bash shell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment