Skip to content

Instantly share code, notes, and snippets.

@vitorbritto
Last active June 9, 2016 12:44
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vitorbritto/10518170 to your computer and use it in GitHub Desktop.
Save vitorbritto/10518170 to your computer and use it in GitHub Desktop.
Unix References

Unix Commands

Environment Control

cd d                         Change to directory d
mkdir d                      Create new directory d
rmdir d                      Remove directory d
mv f1 [f2...] d              Move file f to directory d
mv d1 d2                     Rename directory d1 as d2
passwd                       Change password
alias name1 name2            Create command alias (csh/tcsh)
alias name1="name2"          Create command alias (ksh/bash)
unalias name1[na2...]        Remove command alias na
ssh nd                       Login securely to remote node nd
exit                         End terminal session
setenv name v                Set env var to value v (csh/tcsh)
export name="v"              set environment variable to value v (sh/ksh/bash)

Output, Communication, & Help

lpr -P printer f             Output file f to line printer
script  [f]                  Save terminal session to f
exit                         Stop saving terminal session
mail username                Send mail to user
man name                     Unix manual entry for name

Process Control

CTRL/c                       Interrupt processes
CTRL/s                       Stop screen scrolling
CTRL/q                       Resume screen output
sleep n                      Sleep for n seconds
jobs                         Print list of jobs
kill %                       Kill job n
ps                           Print process status stats
kill -9 n                    Remove process n
CTRL/z                       Suspend current process
stop %n                      Suspend background job n
cmd &                        Run cmd in background
bg  [%n]                     Resume background job n
fg  [%n]                     Resume foreground job n
exit                         Exit from shell

Environment Status

ls  [d]  [f...]              List files in directory
ls -1  [f...]                List files in detail
alias  [name]                Display command aliases
printenv  [name]             Print environment values
quota                        Display disk quota
date                         Print date & time
who                          List logged in users
whoami                       Display current user
finger  [username]           Output user information
chfn                         Change finger information
pwd                          Print working directory
history                      Display recent commands
! n                          Submit recent command n

File Manipulation

vi  [f]                      Vi fullscreen editor
vim  [f]                     Vim, a much better fullscreen editor
emacs  [f]                   Emacs fullscreen editor
ed  [f]                      Text editor
wc  f                        Line, word, & char count
cat  f                       List contents of file
more  f                      List file contents by screen
cat f1 f2 >f3                Concatenates f1 & f2 into f3
chmod mode f                 Change protection mode of f
cmp f1 f2                    Compare two files
cp f1 f2                     Copy file f1 into f2
scp f1 nd:f2                 Secure copy file f1 to f2 on remote node nd
scp nd:f1 f2                 Secure copy file f1 on remote node nd to f2
sftp nd                      Secure file transfer to remote node nd
sort f                       Alphabetically sort f
split  [-n]  f               Split f into n-line pieces
mv f1  f2                    Rename file f1 as f2
rm f                         Delete (remove) file f
grep 'ptn'  f                Outputs lines that match ptn
diff f1 f2                   Lists file differences
head f                       Output beginning of f
tail f                       Output end of f

Compiler

cc  [-o f1]  f2              C compiler
c++ [-o f1]  f2              C++ compiler
lint f                       Check C code for errors
f77  [-o f1] f2              Fortran77 compiler
pc  [-o f1]  f2              Pascal compiler

Unix Structure

/
├── bin
├── boot
├── dev or devices (or both) etc
├── home
├── kernel
├── lib
├── mnt
├── opt
├── proc
├── sbin
├── tmp
├── usr
└── var
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment