- format and display the on-line manual pages
man [command] #if you are lost, just RTFM!
- display effective user id
whoami #prints the current user's name
- write arguments to the standard output
echo "[text]" #prints out text
- return working directory name
pwd #prints the current directory
- list directory contents
ls #lists the contents of the current directory
ls -la #lists all the files in a longer format
ls -lS #lists all the files sorted by size
ls D* # „show only files that start with “D” (Desktop, Documents, etc)”
ls *.{txt,xml,md}
List the five most recently modified files
ls -t | head -n 5
- change directory
cd [directory] #moves to a given directory like "/Users/tib/"
cd ~ #moves to home directory
cd .. #moves up a directory
- make directories
mkdir [directory] #creates a directory
mkdir -p [dir1/dir2/dir3] #creates the whole directory structure
- copy files
cp [source] [destination] #copies the source into the destination
cp -R somedirectory nameofcopy #copy whole directory
- move files
mv [source] [destination] #moves the source into the destination
- make links
ln [source] [destination] #creates a link from the source to the destination
- remove directory entries
rm [file] #removes the given file
rm -r [directory] #removes the given file
- change file modes or Access Control Lists
chmod 644 [file] #changes file permissions
chmod -r 644 [directory] #same, but recursively
- change file owner and group
chown tib:staff [file] #changes owner & group
chown -r tib:staff [directory] #same but recursively
- locate a program file in the user's path
which [command] #looks for a command, if found prints location
- change file access and modification times
touch [file] #creates the file or updates it's appropriate times
- scriptable image processing system
sips -Z [size] [image] #scale an image to a max size
- creates an alias
alias la='ls -la' #from now you can use la as a shortcut
- exports a variable
export [name]=[value] #later on you can assess it by using $name
$_
is substitued by the shell with the parameter from the last command
git branch -d branch-name
git push --delete remote-name $_
When hitting enter on a command with $!
the shell will not execute it, but prompt the command again, with the last parameter used in place of !$
$ ls ~/Desktop
$ ls -a !$
$ ls -a ~/Desktop
ls *.txs
no matches found: *.txs
^txs^txt
ls *.txt
- concatenate and print files
cat [file] #prints out the contents of a file
less -NM filename.txt
Character | What it's doing |
---|---|
-N |
show numbers |
-M |
show metrics |
- find "the"
less +/the filename.txt
head filename.txt #Print the first 10 lines of file
tail -n 5 filename.txt #Print the final 5 lines of file
- prints count of lines, words and bytes from file
wc [file]
Character | What it's doing |
---|---|
-c |
the number of bytes |
-l |
the number of lines |
-m |
the number of characters |
-w |
the number of words |
-
find . -name "*video*.mp4" -print0 | xargs -0 -I {} mv {} new_folder
-
find . -name "*.java" -exec grep -n -H "new .*Db.* {} \;
-
find . -name "*.zip" -size +1G
-
find . -name "*.java" -not -regex ".*Db\.java -exec grep -n -H "new .*Db" {} \;
-
find . -iname "*.txt" -exec cat {} \;
Find all "....Db.java"
find . -regex ".*Db\.java
Find any file modified in the last 24 hours
find . -type f -mtime 0
Count markdouwn files
find . -iname "*.md" | wc -l
Character | What it's doing |
---|---|
find | execute the find command |
. |
from the current directory |
-name |
match the name of "*.java" |
-iname |
like name, but case insensitive |
-size |
size criteria |
-exec |
will pass found filename as a parameter |
-n |
show line numbers of the matches |
-H |
show filenames of the matches |
"new .*Db.*" |
all files with any numbers of characters, followed by the letters Db, then followed by any characters |
{} |
placeholder for the filename found by find |
\; |
Terminate the command after -exec |
- file pattern searcher
ls -la | grep [term] #search for a folder name (term) in a directory list
cat test.txt | grep [term] #search for a term in a file
Character | What it's doing |
---|---|
--color |
color results |
-r |
recursive search |
-i |
ignore letter case |
-l |
prints only matching filenames |
-n |
prints line number |
-
sort filed.txt | uniq
-
sort file1 file1 file2 | uniq -u
If you combine this with the-u
parameter to uniq, which outputs lines that exist only once.
history | grep "command"
sudo !!
time command
python -m SimpleHTTPServer
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" # genertes a new key
- OpenSSH SSH client (remote login program)
ssh [server] -p [port] #logs in to a remote server
- upload file to server
scp filename.zip
- secure file transfer program
sftp [server] #logs in to the server (use help for more)
After sftp
you can upload file put filename.zip
or download file get filename.zip
wget --mirror --convert-links --adjust-extension --page-requisites --no-parent http://example.org
Alternatively, the command above may be shortened:
wget -mkEpnp http://example.org
Pattern | What it's doing |
---|---|
[pr]at |
A single charcter of p or r |
[a-z]at |
A character in the range: a-z |
[^a-z]at |
A character not in the range: a-z |
[A-Za-z]at |
A character in the range: a-z or A-Z |
a? |
Zero or one of a |
a* |
Zero or more of a |
a+ |
One or more of a |
a{3} |
Exactly 3 of a |
a{3,} |
3 or more of a |
a{3,6} |
Beetween 3 and 6 of a |
. |
Any single character |
^ |
Start of string |
$ |
End of string |
m
modifier: multi line. Causes ^
and $
to match the begin/end of each line (not only begin/end of string)
- Swift
.AnchorsMatchLines
"April 25h" or "Apr 25"
Apr(il)? \d\d(th)?
"My name is Pat Adams" or "My name is XYZ lastname"
My name in (XYZ|Pat) \w+
Find all quetes
"[^"]+"
My favorite color is blue
My favorite colour is green
My favorite (?:color|colour) is (.*)
- blue
- green
Find all "Testing bold text"
<([A-Z][A-Z0-9]?)>[\w ]+</\1>