0% found this document useful (0 votes)
808 views

Learn Enough Command Line To Be Dangerous

This document provides an overview of basic command line commands for manipulating files, directories, and processes. It covers commands for listing, copying, moving, deleting, and inspecting files, as well as changing directories and finding files. Key commands covered include ls, cd, cp, mv, rm, cat, head, tail, grep, find, and more. The document also discusses piping commands together and searching command history.

Uploaded by

C Fox
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
808 views

Learn Enough Command Line To Be Dangerous

This document provides an overview of basic command line commands for manipulating files, directories, and processes. It covers commands for listing, copying, moving, deleting, and inspecting files, as well as changing directories and finding files. Key commands covered include ls, cd, cp, mv, rm, cat, head, tail, grep, find, and more. The document also discusses piping commands together and searching command history.

Uploaded by

C Fox
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

LEARN ENOUGH COMMAND LINE TO BE DANGEROUS

===========================================

1 BASICS
--------------

echo <string> = print text within shell (can be with/without quotes or double
quotes)
man <command> = print manual for named command
sleep <seconds> = make terminal sleep for named amount of time
help <command> = built in help facility
type <command> = shows type of command

ctrl + C = cancel shell commands if stuck


ctrl + A = move cursor to start of line
ctrl + E = move cursor to end of line
ctrl + U = delete entire line and move cursor to start of line
clear OR ctrl + L = clear shell
exit OR ctrl + D = exit shell
option + mouse click = move cursor to desired point on line
up/down arrow = scroll through previous commands
tab = tab completion of terms

2 MANIPULATING FILES
----------------------

> = redirect operator (e.g echo <string> > <filename>)


>> = append operator (e.g echo <string> >> <filename>)
cat <filename> = show contents of file on screen
cat <filename> <filename> > = combine contents of two files into new file
diff <filename> <filename> = show difference between two files

ls <filename> = list file


ls = list all files in directory
ls -a = list all files incl. hidden
ls -rtl (or ls -r -t -l) = list files (long form) in reverse modified order
ls -S = list files by size
ls -h = list files with kb, mb, gb sizes (human readable)
ls *.txt = list all files ending with .txt
ls s* = list all files starting with s

touch <file> = create empty file


mv <oldname> <newname> = rename file
cp <oldname> <newname> = copy file
rm <file> = delete file
rm -f <file> = force delete file
rm -i <file> = ask before deleting file

3 INSPECTING FILES
---------------------

curl = download file online


which = search system to see if command is available on system
curl -Ol <urltofile> = download file
curl -O = write file to system with same filename
curl -l = list only
!! = run previous command
curl -I <url> = fetch http header of website
!<command number> = run numbered command
ctrl+r = reverse index search of previous commands

head <filename> = view first 10 lines of file


tail <filename> = view last 10 lines of file
head -n <filename> = view first <n> lines of file
tail -n <filename> = view first <n> lines of file
tail -f <filename> = tailing the log file (view live activity)
ping <url> = checks server to see if its working

wc <filename> = word count (lines, words, bytes)


| = pipe command (sends output of one command into another to save time)

less <filename> = interactive view of file


up arrow/down arrow = move up/down one line
ctrl + f / space bar = page down
ctrl + b = page up
q = quit
/<term> = search file for term
n / N to scroll through searched terms
G = move to end of file
1G = move to beginning of file
*G = move to line number of file

grep <term> <filename> = search for substring within file


grep -i <term> <filename> = case-insensitive search
grep -v <term> <filename> = search for substrings NOT containing keyword within
file

top = processes consuming most resources


ps aux = process status
ps aux | grep <process> = search for named process
first number of return is process id (which can be used to kill process using)
kill -15 <pid> = kill command
pkill -15 -f <keyword> = kill all commands containing keyword
pkill -15 <pid> = kill command with selected pid

history = prints history of commands in shell

4 DIRECTORIES
-----------------------

~ = /Users/<user>
sudo = substitute user do (not superuser) Root access
mkdir = make folder
mkdir -p = make intermediate directories in single command
mv <file> <folder> = move file(s) to folder
ls <directory> = shows contents
ls -d <directory> = shows just the directory
ls -ld <directory> = shows directory in long form

cd = change directory
cd .. = move up one directory level
cd . = current directory
cd / cd ~ = change directory to home folder
cd - = change to previous directory
pwd = print working directory

find = find file/directory


find . -name '*.txt' = find in current directory file names ending with .txt
open = opens files in system default applications (mac only) (xdc-open on some
linux)

cp = copy file
cp <filename> . = copy file to current directory
cp -r <directory> = copies all files from current directory into named directory
rmdir <directory> = remove directory
rm -rf = remove recursive force = removes all directories, files (CAUTION)

grep -ri <string> <directory> = search for keyword within files (multiple
directories, case insensitive)
; = use multiple commands in single command

-----

pushd <directory> - takes your current directory and pushes it into a list for
later, then it changes to another directory. E.g Save where I am, then go here.
pushd - with no arguments - will switch between current dir and the last one
pushed. e.g quick switch

popd - takes last dir you pushed and pops if off, taking you back there.

You might also like