Cheat sheet
From WakeDEAC
This Cheat sheet lists many of the common and useful Linux/Unix commands, in case you forget.
N.B: Most commands have more flags listed; typing man "cmd" will provide additional info on command ;cmd".
Contents |
Useful commands
cd d
- Change to directory d
mkdir d
- Create new directory d
rmdir d
- Remove empty directory d
mv f1 [f2...] d
- Move file(s) f1(,f2...) to directory d
mv d1 d2
- Rename directory d1 as d2 or, if d2 exists, move d1 into d2
passwd
- Change password
alias name1 name2
- Create command alias name1 so typing "name1" executes name2
rsh nd
- Login to remote computer/node nd
ssh nd
- Securely login to remote computer/node nd
ssh -n nd cmd
- perform command cmd on node nd
sentenv name v
- Set environment varable to value v {if this doesn't work you are in the bash shell}
man name
- Manual entry for name
CTRL-c
- Interrupt processes
sleep n
- Sleep for n seconds
jobs
- Print list of jobs
kill %
- Kill job n
hostname
- name of the computer you are on
ps
- Print process stats
ps -u us
- Print processes for user us
killall nm
- Kill all processes matching name nm
kill -9 n
- Remove process n
CTRL-z
- Suspend current process
cmmd&
- Run cmmd in background
bg [%n]
- Resume background job n
fg [%n]
- Resume foreground job n
df
- disk space free in bytes
- df -k
- disk free in KB
- df -h
- disk free in more readable format
- df -i
- inodes free
- df -ih
- inodes free in nmore readable format
- du
- disk usage
- du -k
- disk usage in KB
- du -s
- summarize disk usage for a directory tree
- du -hs
- summarize disk usage in more readable format
- exit
- Exit from shell
- ls [d] [f...]
- List files in directory
- ls -1 [f...]
- List files in detail
- ls -a
- include dot files
- ls -a
- ls -lh
- more size readable format
- ls -lh
- ls -t
- Time order files
- ls -t
- ls -rt
- reverse time order
- ls -rt
- ls -rtalh
- all of the above lists
- ls -rtalh
- alias [name]
- Display command aliases
- date
- Print date & time
- who
- List logged in users
- whoami
- Display current user
- finger [username]
- Output user information
- pwd
- Print working directory
- history
- Display recent commands
- ! n
- Submit recent command number "n" (obtain number from history)
- vi [file]
- Vi editor (often system alias for vim)
- wc file
- Line, word, & char count for file f
- wc -l file
- line count only
- cat file
- List contents of file
- cat f1 f2
- Concatenates f1 & f2
- cat f1 f2 > f3
- into file f3
- cat f1 f2 >> f3
- append f1 and f2 to f3
- more file
- List file contents by screen
- more +xxx file
- list file contents by screen starting at line xxx
- paste f1 f2
- pastes f1 and f2 together
- paste f1 f2 > f3
- into file f3
- paste f1 f2 >> f3
- append f1 and f2 to f3
- sort f
- Alphabetically sort file f
- sort -n f
- Numerically sort f
- sort -n f
- sort -rn f
- reserve numerically sort f
- sort -rn f
- mv f1 f2
- Rename file f1 as f2
- rm f
- Delete (remove) file f
- rm -r d
- Removes a directory d recusively
- rm -r d
- grep 'ptn' f
- Outputs lines that match ptn in file f
- head f
- Outputs beginning of file f
- tail f
- Outputs end of file f
- diff f1 f2
- Compare two files
- cp f1 f2
- Copy file f1 into f2
Chmod
chmod mode f Change permissions of f
mode: y+ab
a=all
g=group
u=user
+ adds permissions
(- substracts)
r=read
w=write
x=execute
s=sticky
chmod -R mode dir recursively changes mmode of directory
chgrp groupname file changes group of file or directory
chgrp -R groupname dir/ recursively changes group of directory
N.B. when changing group set sticky with chmod to make sure new files and directories keep the group
Scp
scp f1 username@computer:f2 copies securely from one computer to another scp temp salsbufr@dirac.phy.wfu.edu:ARCHIVES/tmp copies the file temp from the current computer to dirac.phy.wfu.edu to the file /home/salsbufr/ARCHIVES/tmp where /home/salsbufr is the home directory for salsbufr on dirac salsbufr is also as username for authentication ( a password will be required) scp temp salsbufr@dirac.phy.wfu.edu: copies file temp to /home/salsbufr/temp on dirac. Note: the : is always needed! Otherwise, the file temp would be copied to a file salsbufr@dirac.phy.wfu.edu on the first computer!
Wildcards with examples
- match any number of characters; use with caution!
- ? match one character
Examples
rm *.e???
- would delete any file having any number of characters followed by .e and then 3 characters
ssh -n deac024 ls "/scratch/azaria0/*"
- lists all files on deac024 in the /scratch/azaria0 directory. Note the "", it is to protect he wildcard so that it is expanded on deac024 .
General control
- cmd < file Take whatever is in file as input for cmd
- cmd > file Put the output from cmd into file cat f1 f2 > f3, would cat f1 and f2 into file ff3
- cmd >> file Append output from cmd to file
foreach n ( a b c d e ) will do a foreach loop using $n as a then b then d then d
foreach n ( 01 02 03 04 ) ssh -n deac0$n hostname ssh -n deac0$n ls "/scratch/salsbury/*/*" end
- will execute the command hostname and then the ls on deac001 then deac002 and so on

