School of Computing Linux Cheat Sheet
File and directory commands
Command
Action
ls
ls -la
ls -R
ls -F
ls --color=auto
cd dir
pwd
mkdir dir
rmdir dir
rm file
rm -r dir
rm -f file
rm -rf dir
cp file1 file2
cp -r dir1 dir2
mv file1 file2
displays files/directories in 3 column format
displays files/directories in long format, including hidden files
displays files/directories recursively
displays files/directories and appends indicator for file type or directory
control whether color is used to distinguish file types. (never, always or auto)
change directory to dir
show current directory
create a directory dir
delete directory dir
delete file
delete directory dir
force remove file
force remove dir (DANGEROUS)
copy file1 to file2
copy dir1 to dir2; create dir2 if it doesn't exist
rename or move file1 to file2
if file2 is an existing directory, moves file1 into
directory file2
create or update file
displays contents of file
displays contents of file, allows for forward/reverse navigation of file
output the first 10 lines of file
output the last 10 lines of file
output the last 10 lines of file and output continues as file is being updated, to
end CTRL+C
search file for word or "phrase"
NOTE: case sensitive. Phrase must be enclosed in quotes
search all files in current directory for word or "phrase"
NOTE: case sensitive. Phrase must be enclosed in quotes
search file for word or "phrase"
Case insensitive. Phrase must be enclosed in quotes
search all files in current directory for word or "phrase"
NOTE: case insensitive. Phrase must be enclosed in quotes
Starting at current directory look for the file named file
Starting at dir look for the file named file
touch file
cat file
less file
head file
tail file
tail -f file
grep word or "phrase" file
grep word or "phrase"*
grep -i word or "phrase" file
grep -i word or "phrase"*
find . name file
find dir name file
File Permissions
chmod octal file change the permissions of file to octal, which can be found separately for user, group, and
world by adding:
4 read (r)
2 write (w)
1 execute (x)
Examples:
chmod 777 read, write, execute for all
chmod 755 rwx for owner, rx for group and world
Help commands
Command
Action
progname --help or progname -h
man progname
man -k progname
displays help/usage for program if provided
displays documentation for progname
searches all documentation containing progname
System commands
Command
Action
date
cal
whoami
df
which progname
shows the current date and time
show this month's calendar
who you are logged in as
show quota information/disk usage
shows path information for progname
Short cuts
Command
Action
Ctrl+C
Ctrl+D
Ctrl+U
!!
history
!#
halts current command
logout, similar to exit
erases line of input at command line
repeats last command
displays history of commands with number of command
repeats # of command from history,
Example: !76 will repeat the 76th command in history
displays last command, continually pressing up arrow will allow to scroll
through previous commands
auto complete
up arrow
tab
Remote Access
Command
Action
ssh $USER@$HOST
ssh -Y $USER@$HOST
open a secure shell connection as $USER at $HOST
open a secure shell connection as $USER at $HOST allowing to run X11
tunneling
secure copy a file to $HOST as $USER
scp $USER@$HOST: file dir/
ssh
[email protected]1. ssh
[email protected].edu
2. ssh dragon2.cs.clemson.edu
Accessing a $HOST on campus
Accessing a $HOST from off campus. 1st ssh into access.cs.clemson.edu, with
username. Once logged into access.cs.clemson.edu, you can then ssh into any
lab machines (username not necessary)